Class DomTripXMLReader

  • All Implemented Interfaces:
    org.xml.sax.XMLReader

    public class DomTripXMLReader
    extends java.lang.Object
    implements org.xml.sax.XMLReader
    An XMLReader implementation that reads from a domtrip Document.

    This class allows a domtrip document to be used as a SAXSource for JAXP interoperability. When parse(InputSource) is called, it walks the domtrip document tree and emits SAX events to the registered ContentHandler.

    Supported Features:

    • http://xml.org/sax/features/namespaces - always true
    • http://xml.org/sax/features/namespace-prefixes - controls whether namespace declarations are reported as attributes (default false)

    Supported Properties:

    • http://xml.org/sax/properties/lexical-handler - LexicalHandler for comment and CDATA events
    Since:
    1.3.0
    See Also:
    DomTripSAXSource, SAXOutputter
    • Constructor Summary

      Constructors 
      Constructor Description
      DomTripXMLReader​(Document document)
      Creates a new XMLReader that reads from the given document.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      org.xml.sax.ContentHandler getContentHandler()  
      Document getDocument()
      Returns the document backing this reader.
      org.xml.sax.DTDHandler getDTDHandler()  
      org.xml.sax.EntityResolver getEntityResolver()  
      org.xml.sax.ErrorHandler getErrorHandler()  
      boolean getFeature​(java.lang.String name)  
      java.lang.Object getProperty​(java.lang.String name)  
      void parse​(java.lang.String systemId)
      Parses the domtrip document, emitting SAX events to the registered handlers.
      void parse​(org.xml.sax.InputSource input)
      Parses the domtrip document, emitting SAX events to the registered handlers.
      void setContentHandler​(org.xml.sax.ContentHandler handler)  
      void setDTDHandler​(org.xml.sax.DTDHandler handler)  
      void setEntityResolver​(org.xml.sax.EntityResolver resolver)  
      void setErrorHandler​(org.xml.sax.ErrorHandler handler)  
      void setFeature​(java.lang.String name, boolean value)  
      void setProperty​(java.lang.String name, java.lang.Object value)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DomTripXMLReader

        public DomTripXMLReader​(Document document)
        Creates a new XMLReader that reads from the given document.
        Parameters:
        document - the document to read
        Throws:
        java.lang.IllegalArgumentException - if document is null
    • Method Detail

      • getDocument

        public Document getDocument()
        Returns the document backing this reader.
        Returns:
        the domtrip document
      • getFeature

        public boolean getFeature​(java.lang.String name)
                           throws org.xml.sax.SAXNotRecognizedException
        Specified by:
        getFeature in interface org.xml.sax.XMLReader
        Throws:
        org.xml.sax.SAXNotRecognizedException
      • setFeature

        public void setFeature​(java.lang.String name,
                               boolean value)
                        throws org.xml.sax.SAXNotRecognizedException,
                               org.xml.sax.SAXNotSupportedException
        Specified by:
        setFeature in interface org.xml.sax.XMLReader
        Throws:
        org.xml.sax.SAXNotRecognizedException
        org.xml.sax.SAXNotSupportedException
      • getProperty

        public java.lang.Object getProperty​(java.lang.String name)
                                     throws org.xml.sax.SAXNotRecognizedException
        Specified by:
        getProperty in interface org.xml.sax.XMLReader
        Throws:
        org.xml.sax.SAXNotRecognizedException
      • setProperty

        public void setProperty​(java.lang.String name,
                                java.lang.Object value)
                         throws org.xml.sax.SAXNotRecognizedException,
                                org.xml.sax.SAXNotSupportedException
        Specified by:
        setProperty in interface org.xml.sax.XMLReader
        Throws:
        org.xml.sax.SAXNotRecognizedException
        org.xml.sax.SAXNotSupportedException
      • setEntityResolver

        public void setEntityResolver​(org.xml.sax.EntityResolver resolver)
        Specified by:
        setEntityResolver in interface org.xml.sax.XMLReader
      • getEntityResolver

        public org.xml.sax.EntityResolver getEntityResolver()
        Specified by:
        getEntityResolver in interface org.xml.sax.XMLReader
      • setDTDHandler

        public void setDTDHandler​(org.xml.sax.DTDHandler handler)
        Specified by:
        setDTDHandler in interface org.xml.sax.XMLReader
      • getDTDHandler

        public org.xml.sax.DTDHandler getDTDHandler()
        Specified by:
        getDTDHandler in interface org.xml.sax.XMLReader
      • setContentHandler

        public void setContentHandler​(org.xml.sax.ContentHandler handler)
        Specified by:
        setContentHandler in interface org.xml.sax.XMLReader
      • getContentHandler

        public org.xml.sax.ContentHandler getContentHandler()
        Specified by:
        getContentHandler in interface org.xml.sax.XMLReader
      • setErrorHandler

        public void setErrorHandler​(org.xml.sax.ErrorHandler handler)
        Specified by:
        setErrorHandler in interface org.xml.sax.XMLReader
      • getErrorHandler

        public org.xml.sax.ErrorHandler getErrorHandler()
        Specified by:
        getErrorHandler in interface org.xml.sax.XMLReader
      • parse

        public void parse​(org.xml.sax.InputSource input)
                   throws java.io.IOException,
                          org.xml.sax.SAXException
        Parses the domtrip document, emitting SAX events to the registered handlers.

        The input parameter is ignored since the document is provided at construction time. A ContentHandler must be set before calling this method.

        Specified by:
        parse in interface org.xml.sax.XMLReader
        Parameters:
        input - ignored (document was provided at construction)
        Throws:
        org.xml.sax.SAXException - if the content handler reports an error
        java.lang.IllegalStateException - if no content handler has been set
        java.io.IOException
      • parse

        public void parse​(java.lang.String systemId)
                   throws java.io.IOException,
                          org.xml.sax.SAXException
        Parses the domtrip document, emitting SAX events to the registered handlers.

        The systemId parameter is ignored since the document is provided at construction time.

        Specified by:
        parse in interface org.xml.sax.XMLReader
        Parameters:
        systemId - ignored
        Throws:
        org.xml.sax.SAXException - if the content handler reports an error
        java.io.IOException