Package org.dom4j.io

Examples of org.dom4j.io.SAXContentHandler


  public Object getVariable(String name) {
      if (map.containsKey (name)) {
    Object v = map.get (name);
    if (v instanceof SAXEventBuffer) {
        if (!xmlVals.containsKey (name)) {
      SAXContentHandler hdlr = new SAXContentHandler ();
      try {
          ((SAXEventBuffer)v).emit (hdlr);
      } catch (SAXException e) {
          throw (IllegalArgumentException)
        (new IllegalArgumentException
         ("Error converting SAX events: "
          + e.getMessage ())).initCause(e);
      }
      xmlVals.put (name, hdlr.getDocument());
        }
        return xmlVals.get (name);
    }
    return v;
      } else {
View Full Code Here


        public Object getVariable(String name) {
      if (getPaProcessData().containsKey (name)) {
          Object v = getPaProcessData().get (name);
          if (v instanceof SAXEventBuffer) {
        if (!xmlVals.containsKey (name)) {
            SAXContentHandler hdlr
          = new SAXContentHandler ();
            try {
          ((SAXEventBuffer)v).emit (hdlr);
            } catch (SAXException e) {
          throw (IllegalArgumentException)
              (new IllegalArgumentException
               ("Error converting SAX events: "
                + e.getMessage ())).initCause(e);
            }
            xmlVals.put (name, hdlr.getDocument());
        }
        return xmlVals.get (name);
          }
          return v;
      } else {
View Full Code Here

        XMLParser parser = new XMLParser();
        Script script = parser.parse(in);
        script = script.compile();
        JellyContext context = parser.getContext();
       
        SAXContentHandler contentHandler = new SAXContentHandler();
        XMLOutput output = new XMLOutput( contentHandler );
       
        contentHandler.startDocument();
        script.run(context, output);
        contentHandler.endDocument();
       
        return contentHandler.getDocument();
    }
View Full Code Here

   
    /**
     * Parses the body of this tag and returns the parsed document
     */
    protected Document parseBody(XMLOutput output) throws Exception {
        SAXContentHandler handler = new SAXContentHandler();
        XMLOutput newOutput = new XMLOutput(handler);
        handler.startDocument();
        invokeBody( newOutput);
        handler.endDocument();
        return handler.getDocument();

/*
        // the following is inefficient as it requires a parse of the text
        // but is left here in the code to see how it could be done.

View Full Code Here

    }

    protected Document roundTripSAX(Document document) throws Exception {
        // now lets write it back as SAX events to
        // a SAX ContentHandler which should build up a new document
        SAXContentHandler contentHandler = new SAXContentHandler();
        SAXWriter saxWriter = new SAXWriter(contentHandler, contentHandler,
                contentHandler);

        saxWriter.write(document);

        Document newDocument = contentHandler.getDocument();

        // lets ensure names are same
        newDocument.setName(document.getName());

        assertDocumentsEqual(document, newDocument);
View Full Code Here

*/
public class Dom4jUnmarshallingEventHandler extends UnmarshallingEventHandlerAdaptor {
    private Element owner;
   
    public Dom4jUnmarshallingEventHandler(UnmarshallingContext _ctxt) throws SAXException {
        super(_ctxt, new SAXContentHandler(new DocumentFactory()));
    }
View Full Code Here

        SAXParser parser = spf.newSAXParser();
        xmlReader = parser.getXMLReader();
    }

    public void testSAXContentHandler() throws Exception {
        SAXContentHandler contentHandler = new SAXContentHandler();
        xmlReader.setContentHandler(contentHandler);
        xmlReader.setDTDHandler(contentHandler);
        xmlReader.setProperty("http://xml.org/sax/properties/lexical-handler",
                contentHandler);

        for (int i = 0, size = testDocuments.length; i < size; i++) {
            Document docFromSAXReader = getDocument(testDocuments[i]);

            xmlReader.parse(getFile(testDocuments[i]).toString());

            Document docFromSAXContentHandler = contentHandler.getDocument();

            docFromSAXContentHandler.setName(docFromSAXReader.getName());

            assertDocumentsEqual(docFromSAXReader, docFromSAXContentHandler);
            assertEquals(docFromSAXReader.asXML(), docFromSAXContentHandler
View Full Code Here

        println("Converted to DOM4J tree using DOM: " + document);

        // now lets write it back as SAX events to
        // a SAX ContentHandler which should build up a new document
        SAXContentHandler contentHandler = new SAXContentHandler();
        SAXWriter saxWriter = new SAXWriter(contentHandler, null,
                contentHandler);

        saxWriter.write(document);
        document = contentHandler.getDocument();

        println("Converted DOM4J to SAX events then back to DOM4J: " + document);

        return document;
    }
View Full Code Here

*/
public class Dom4jUnmarshallingEventHandler extends UnmarshallingEventHandlerAdaptor {
    private Element owner;
   
    public Dom4jUnmarshallingEventHandler(UnmarshallingContext _ctxt) throws SAXException {
        super(_ctxt, new SAXContentHandler(new DocumentFactory()));
    }
View Full Code Here

TOP

Related Classes of org.dom4j.io.SAXContentHandler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.