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); } }
/** * <i>[SAX LexicalHandler interface support]</i> Reports the * start of a CDATA section. * * @throws SAXException The application may raise an exception. */ public void startCDATA() throws SAXException { this.ensureInitialization(); this.saxHandler.startCDATA(); }
/** * Checks whether a transformation result has been set and, if not, * retrieves the result tree being built by the document builder. */ private void retrieveResult() { if (result == null) { this.setResult(((DocumentBuilder)this.getHandler()).getResult()); } }
/** * 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; }
/** * <i>[SAX LexicalHandler interface support]</i> Reports the * beginning of some internal and external XML entities. * * @param name the name of the entity. If it is a parameter * entity, the name will begin with '%', and if it * is the external DTD subset, it will be "[dtd]". * * @throws SAXException The application may raise an exception. */ public void startEntity(String name) throws SAXException { this.ensureInitialization(); this.saxHandler.startEntity(name); }
/** * <i>[SAX LexicalHandler interface support]</i> Reports an XML * comment anywhere in the document. * * @param ch an array holding the characters in the comment. * @param start the starting position in the array. * @param length the number of characters to use from the array. * * @throws SAXException The application may raise an exception. */ public void comment(char ch[], int start, int length) throws SAXException { this.ensureInitialization(); this.saxHandler.comment(ch, start, length); } }
/** * Returns the result of an XSL Transformation. * * @return the transformation result as a (possibly empty) list of * JDOM nodes (Elements, Texts, Comments, PIs...). */ public List getResult() { // Flush remaining text content in case the last text segment is // outside an element. try { this.flushCharacters(); } catch (SAXException e) { /* Ignore... */ } return this.getDetachedContent(dummyRoot); }
/** * Build an XMLReader to be used for the source. This will * create a new instance of DocumentReader with an * EntityResolver instance if available. * * @return XMLReader reading the XML data from the source * JDOM document with an optional EntityResolver */ private XMLReader buildDocumentReader() { DocumentReader reader = new DocumentReader(); if (resolver != null) reader.setEntityResolver(resolver); return reader; }
/** * 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); }
/** * Public constructor. */ public FragmentHandler(JDOMFactory factory) { super(factory); // Add a dummy root element to the being-built document as XSL // transformation can output node lists instead of well-formed // documents. this.pushElement(dummyRoot); }
private void ensureInitialization() throws SAXException { // Trigger document initialization if XSLT processor failed to // fire the startDocument event. if (this.startDocumentReceived == false) { this.startDocument(); } }
/** * <i>[SAX LexicalHandler interface support]</i> Reports the end * of DTD declarations. * * @throws SAXException The application may raise an exception. */ public void endDTD() throws SAXException { this.saxHandler.endDTD(); }
/** * <i>[SAX LexicalHandler interface support]</i> Reports the end * of an entity. * * @param name the name of the entity that is ending. * * @throws SAXException The application may raise an exception. */ public void endEntity(String name) throws SAXException { this.saxHandler.endEntity(name); }
/** * <i>[SAX LexicalHandler interface support]</i> Reports the end * of a CDATA section. * * @throws SAXException The application may raise an exception. */ public void endCDATA() throws SAXException { this.saxHandler.endCDATA(); }
/** * 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); }
/** * Transforms the given document to an output document. * * @param inputDoc input document * @return transformed output document * @throws XSLTransformException if there's a problem in the transformation */ public Document transform(Document inputDoc) throws XSLTransformException { return transform(inputDoc, null); }
@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); } }
/** * 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; }
@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)); }