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); } }
/** * Creates a JDOM TrAX source wrapping a JDOM document. * * @param source the JDOM document to use as source for the * transformations * * @throws IllegalArgumentException if <code>source</code> is * <code>null</code>. */ public JDOMSource(Document source) { setDocument(source); }
/** * Creates a JDOM TrAX source wrapping a list of JDOM nodes. * * @param source the JDOM nodes to use as source for the * transformations * * @throws IllegalArgumentException if <code>source</code> is * <code>null</code>. */ public JDOMSource(List source) { setNodes(source); }
/** * Returns the source node list used by this TrAX source. * * @return the source node list used by this TrAX source or * <code>null</code> if the source is a JDOM document. * * @see #setDocument */ public List getNodes() { Object src = ((JDOMInputSource)getInputSource()).getSource(); List nodes = null; if (src instanceof List) { nodes = (List)src; } return nodes; }
/** * Returns the XMLReader to be used for the Source. * <p> * This implementation returns a specific XMLReader reading * the XML data from the source JDOM document. * </p> * * @return an XMLReader reading the XML data from the source * JDOM document. */ public XMLReader getXMLReader() { if (this.xmlReader == null) { this.xmlReader = buildDocumentReader(); } return this.xmlReader; }
/** * Creates a JDOM TrAX source wrapping a JDOM element with an * associated EntityResolver to resolve external entities. * * @param source The JDOM Element to use as source for the * transformations * * @param resolver Entity resolver to use for the source * transformation * * @throws IllegalArgumentException if<code>source</code> is * <code>null</code> */ public JDOMSource(Document source, EntityResolver resolver) { setDocument(source); this.resolver = resolver; }
/** * Creates a JDOM TrAX source wrapping a JDOM element. * * @param source the JDOM element to use as source for the * transformations * * @throws IllegalArgumentException if <code>source</code> is * <code>null</code>. */ public JDOMSource(Element source) { List nodes = new ArrayList(); nodes.add(source); setNodes(nodes); }
/** * Returns the source document used by this TrAX source. * * @return the source document used by this TrAX source or * <code>null</code> if the source is a node list. * * @see #setDocument */ public Document getDocument() { Object src = ((JDOMInputSource)getInputSource()).getSource(); Document doc = null; if (src instanceof Document) { doc = (Document)src; } return doc; }
filter = (XMLFilter)(filter.getParent()); filter.setParent(buildDocumentReader());
@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); }