public List<StoreDefinition> readStoreList(Reader input, boolean verifySchema) { try { SAXBuilder builder = new SAXBuilder(); Document doc = builder.build(input); if(verifySchema) { Validator validator = schema.newValidator(); validator.validate(new JDOMSource(doc)); } Element root = doc.getRootElement(); if(!root.getName().equals(STORES_ELMT)) throw new MappingException("Invalid root element: " + doc.getRootElement().getName()); List<StoreDefinition> stores = new ArrayList<StoreDefinition>(); for(Object store: root.getChildren(STORE_ELMT)) stores.add(readStore((Element) store)); for(Object view: root.getChildren(VIEW_ELMT)) stores.add(readView((Element) view, stores)); return stores; } catch(JDOMException e) { throw new MappingException(e); } catch(SAXException e) { throw new MappingException(e); } catch(IOException e) { throw new MappingException(e); } }
@SuppressWarnings("unchecked") public Cluster readCluster(Reader input, boolean verifySchema) { try { SAXBuilder builder = new SAXBuilder(false); Document doc = builder.build(input); if(verifySchema) { Validator validator = this.schema.newValidator(); validator.validate(new JDOMSource(doc)); } Element root = doc.getRootElement(); if(!root.getName().equals(CLUSTER_ELMT)) throw new MappingException("Invalid root element: " + doc.getRootElement().getName()); String name = root.getChildText(CLUSTER_NAME_ELMT); List<Zone> zones = new ArrayList<Zone>(); for(Element node: (List<Element>) root.getChildren(ZONE_ELMT)) zones.add(readZone(node)); List<Node> servers = new ArrayList<Node>(); for(Element node: (List<Element>) root.getChildren(SERVER_ELMT)) servers.add(readServer(node)); return new Cluster(name, servers, zones); } catch(JDOMException e) { throw new MappingException(e); } catch(SAXException e) { throw new MappingException(e); } catch(IOException e) { throw new MappingException(e); } }
@Override protected Source createResponsePayload(MethodParameter returnType, Object returnValue) { Element returnedElement = (Element) returnValue; return new JDOMSource(returnedElement); }
/** * <p> * This will create a new <code>XSLTransformer</code> by * reading the stylesheet from the specified * <code>Document</code>. * </p> * * @param stylesheet <code>Document</code> containing the stylesheet. * @throws XSLTransformException when the supplied <code>Document</code> * is not syntactically correct XSLT */ public XSLTransformer(Document stylesheet) throws XSLTransformException { this(new JDOMSource(stylesheet)); }
protected Source createXsltSource(Map model, String root, HttpServletRequest request, HttpServletResponse response) throws Exception { Document doc = (Document) model.get(VIEW_DOCUMENT); return new JDOMSource(doc); }
protected void dumpDocument(Element node) { try { Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty( OutputKeys.INDENT, "yes" ); transformer.transform( new JDOMSource(node), new StreamResult(System.out) ); } catch ( Exception e ) { e.printStackTrace(); } }
@Override public String fetchLicenseRDF(Document license) { StringWriter result = new StringWriter(); try { templates.newTransformer().transform( new JDOMSource(license), new StreamResult(result) ); } catch (TransformerException e) { throw new IllegalStateException(e.getMessage(), e); } return result.getBuffer().toString(); }
/** * @throws IOException if an I/O error occurs * @throws XmlMappingException if the given source cannot be mapped to an object */ public Object unmarshal(InputStream xmlInputStream) throws IOException{ Document schemaValidatedJdom; try { schemaValidatedJdom = parseAndValidateAgainstSchema(new InputStreamReader(xmlInputStream, "UTF-8")); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } return unmarshaller.unmarshal( new JDOMSource(schemaValidatedJdom) ); }
/** * @throws IOException if an I/O error occurs * @throws XmlMappingException if the given source cannot be mapped to an object */ public Object unmarshal(String xmlFileContent) throws IOException{ Document schemaValidatedJdom = parseAndValidateAgainstSchema(new StringReader(xmlFileContent)); return unmarshaller.unmarshal( new JDOMSource(schemaValidatedJdom) ); }
public final Source invoke(Source request) throws Exception { Element requestElement = getDocumentElement(request); Element responseElement = invokeInternal(requestElement); return responseElement != null ? new JDOMSource(responseElement) : null; }
/** * Transforms the given input nodes to a list of output nodes. * * @param inputNodes input nodes * @return transformed output nodes * @throws XSLTransformException if there's a problem in the transformation */ public List transform(List inputNodes) throws XSLTransformException { JDOMSource source = new JDOMSource(inputNodes); JDOMResult result = new JDOMResult(); result.setFactory(factory); // null ok try { templates.newTransformer().transform(source, result); return result.getResult(); } catch (TransformerException e) { throw new XSLTransformException("Could not perform transformation", e); } }
/** * */ public void writeTo(boolean isShort) throws Exception { Element root = dBase.toXML(); Vector cnt = new Vector(); cnt.add(root); Document doc = new Document(cnt); if (isShort) { TransformerFactory tFactory = TransformerFactory.newInstance(); StreamSource style = getStyle(); JDOMResult result = new JDOMResult(); JDOMSource source = new JDOMSource(doc); Transformer trans = tFactory.newTransformer(style); trans.setOutputProperty(OutputKeys.METHOD, "xml"); trans.setOutputProperty(OutputKeys.INDENT, "yes"); trans.transform(source, result); doc = result.getDocument(); doc.setDocType( new DocType( "database", "-//AIS.PL//DTD Mapping Description 0.4//EN", "http://www.ais.pl/dtds/mapping_0_4.dtd")); } XMLOutputter xo = new XMLOutputter(); String xoDoc = xo.outputString(doc); System.out.println(xoDoc); }
/** * Transforms the given document to an output document. * * @param inputDoc input document * @param resolver entity resolver for the input document * @return transformed output document * @throws XSLTransformException if there's a problem in the transformation */ public Document transform(Document inputDoc, EntityResolver resolver) throws XSLTransformException { JDOMSource source = new JDOMSource(inputDoc, resolver); JDOMResult result = new JDOMResult(); result.setFactory(factory); // null ok try { templates.newTransformer().transform(source, result); return result.getDocument(); } catch (TransformerException e) { throw new XSLTransformException("Could not perform transformation", e); } }
JDOMSource source = new JDOMSource(doc);
Document ddim = new Document(createDIM(dso)); JDOMResult result = new JDOMResult(); xform.transform(new JDOMSource(ddim), result); Element root = result.getDocument().getRootElement(); root.detach();
List dimList; if (list) { JDOMSource source = new JDOMSource(inDoc.getRootElement().getChildren()); JDOMResult result = new JDOMResult(); xform.transform(source, result); outputter.output(dimList, System.out); } else { JDOMSource source = new JDOMSource(inDoc); JDOMResult result = new JDOMResult(); xform.transform(source, result);
return new JDOMSource(doc);
/** * Ingest a whole document. Build Document object around root element, * and feed that to the transformation, since it may get handled * differently than a List of metadata elements. * * @param createMissingMetadataFields whether to create missing fields * @throws CrosswalkException crosswalk error * @throws IOException if IO error * @throws SQLException if database error * @throws AuthorizeException if authorization error */ @Override public void ingest(Context context, DSpaceObject dso, Element root, boolean createMissingMetadataFields) throws CrosswalkException, IOException, SQLException, AuthorizeException { Transformer xform = getTransformer(DIRECTION); if (xform == null) { throw new CrosswalkInternalException( "Failed to initialize transformer, probably error loading stylesheet."); } try { JDOMSource source = new JDOMSource(new Document((Element) root.clone())); JDOMResult result = new JDOMResult(); xform.transform(source, result); Document dimDoc = result.getDocument(); ingestDIM(context, dso, dimDoc.getRootElement().getChildren(), createMissingMetadataFields); } catch (TransformerException e) { log.error("Got error: " + e.toString()); throw new CrosswalkInternalException("XSL Transformation failed: " + e.toString(), e); } }
xform.transform(new JDOMSource(metadata), result); ingestDIM(context, dso, result.getResult(), createMissingMetadataFields); } catch (TransformerException e) {
xform.transform(new JDOMSource(createDIM(dso).getChildren()), result); return result.getResult(); } catch (TransformerException e) {