Class WstxSAXParser

  • All Implemented Interfaces:
    DTDEventListener, org.xml.sax.Attributes, org.xml.sax.ext.Attributes2, org.xml.sax.ext.Locator2, org.xml.sax.Locator, org.xml.sax.Parser, org.xml.sax.XMLReader

    public class WstxSAXParser
    extends javax.xml.parsers.SAXParser
    implements org.xml.sax.Parser, org.xml.sax.XMLReader, org.xml.sax.ext.Attributes2, org.xml.sax.ext.Locator2, DTDEventListener
    This class implements parser part of JAXP and SAX interfaces; and effectively offers an alternative to using Stax input factory / stream reader combination.
    • Field Detail

      • FEAT_DEFAULT_NS_PREFIXES

        static final boolean FEAT_DEFAULT_NS_PREFIXES
        See Also:
        Constant Field Values
      • mStaxFactory

        protected final WstxInputFactory mStaxFactory
        We will need the factory reference mostly for constructing underlying stream reader we use.
      • mFeatNsPrefixes

        protected boolean mFeatNsPrefixes
      • mScanner

        protected BasicStreamReader mScanner
        Since the stream reader would mostly be just a wrapper around the underlying scanner (its main job is to implement Stax interface), we can and should just use the scanner. In effect, this class is then a replacement of BasicStreamReader, when using SAX interfaces.
      • mEncoding

        protected java.lang.String mEncoding
      • mXmlVersion

        protected java.lang.String mXmlVersion
      • mStandalone

        protected boolean mStandalone
      • mContentHandler

        protected org.xml.sax.ContentHandler mContentHandler
      • mDTDHandler

        protected org.xml.sax.DTDHandler mDTDHandler
      • mEntityResolver

        protected org.xml.sax.EntityResolver mEntityResolver
      • mErrorHandler

        protected org.xml.sax.ErrorHandler mErrorHandler
      • mLexicalHandler

        protected org.xml.sax.ext.LexicalHandler mLexicalHandler
      • mDeclHandler

        protected org.xml.sax.ext.DeclHandler mDeclHandler
      • mAttrCount

        protected int mAttrCount
        Number of attributes accessible via Attributes and Attributes2 interfaces, for the current start element.

        Note: does not include namespace declarations, even they are to be reported as attributes.

      • mNsCount

        protected int mNsCount
        Need to keep track of number of namespaces, if namespace declarations are to be reported along with attributes (see mFeatNsPrefixes).
    • Constructor Detail

      • WstxSAXParser

        public WstxSAXParser​(WstxInputFactory sf,
                             boolean nsPrefixes)

        NOTE: this was a protected constructor for versions 4.0 and 3.2; changed to public in 4.1

      • WstxSAXParser

        public WstxSAXParser()
    • Method Detail

      • getParser

        public final org.xml.sax.Parser getParser()
        Specified by:
        getParser in class javax.xml.parsers.SAXParser
      • getXMLReader

        public final org.xml.sax.XMLReader getXMLReader()
        Specified by:
        getXMLReader in class javax.xml.parsers.SAXParser
      • getStaxConfig

        public final ReaderConfig getStaxConfig()
        Accessor used to allow configuring all standard Stax configuration settings that the underlying reader uses.
        Since:
        4.0.8
      • isNamespaceAware

        public boolean isNamespaceAware()
        Specified by:
        isNamespaceAware in class javax.xml.parsers.SAXParser
      • isValidating

        public boolean isValidating()
        Specified by:
        isValidating in class javax.xml.parsers.SAXParser
      • getProperty

        public java.lang.Object getProperty​(java.lang.String name)
                                     throws org.xml.sax.SAXNotRecognizedException,
                                            org.xml.sax.SAXNotSupportedException
        Specified by:
        getProperty in interface org.xml.sax.XMLReader
        Specified by:
        getProperty in class javax.xml.parsers.SAXParser
        Throws:
        org.xml.sax.SAXNotRecognizedException
        org.xml.sax.SAXNotSupportedException
      • 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
        Specified by:
        setProperty in class javax.xml.parsers.SAXParser
        Throws:
        org.xml.sax.SAXNotRecognizedException
        org.xml.sax.SAXNotSupportedException
      • parse

        public void parse​(org.xml.sax.InputSource is,
                          org.xml.sax.HandlerBase hb)
                   throws org.xml.sax.SAXException,
                          java.io.IOException
        Overrides:
        parse in class javax.xml.parsers.SAXParser
        Throws:
        org.xml.sax.SAXException
        java.io.IOException
      • parse

        public void parse​(org.xml.sax.InputSource is,
                          org.xml.sax.helpers.DefaultHandler dh)
                   throws org.xml.sax.SAXException,
                          java.io.IOException
        Overrides:
        parse in class javax.xml.parsers.SAXParser
        Throws:
        org.xml.sax.SAXException
        java.io.IOException
      • getContentHandler

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

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

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

        public org.xml.sax.ErrorHandler getErrorHandler()
        Specified by:
        getErrorHandler in interface org.xml.sax.XMLReader
      • 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
      • setContentHandler

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

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

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

        public void setErrorHandler​(org.xml.sax.ErrorHandler handler)
        Specified by:
        setErrorHandler in interface org.xml.sax.Parser
        Specified by:
        setErrorHandler in interface org.xml.sax.XMLReader
      • 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
      • parse

        public void parse​(org.xml.sax.InputSource input)
                   throws org.xml.sax.SAXException
        Specified by:
        parse in interface org.xml.sax.Parser
        Specified by:
        parse in interface org.xml.sax.XMLReader
        Throws:
        org.xml.sax.SAXException
      • parse

        public void parse​(java.lang.String systemId)
                   throws org.xml.sax.SAXException
        Specified by:
        parse in interface org.xml.sax.Parser
        Specified by:
        parse in interface org.xml.sax.XMLReader
        Throws:
        org.xml.sax.SAXException
      • fireEvents

        private final void fireEvents()
                               throws java.io.IOException,
                                      org.xml.sax.SAXException,
                                      javax.xml.stream.XMLStreamException
        This is the actual "tight event loop" that will send all events between start and end document events. Although we could use the stream reader here, there's not much as it mostly just forwards requests to the scanner: and so we can as well just copy the little code stream reader's next() method has.
        Throws:
        java.io.IOException
        org.xml.sax.SAXException
        javax.xml.stream.XMLStreamException
      • fireAuxEvent

        private final void fireAuxEvent​(int type,
                                        boolean inTree)
                                 throws java.io.IOException,
                                        org.xml.sax.SAXException,
                                        javax.xml.stream.XMLStreamException
        Throws:
        java.io.IOException
        org.xml.sax.SAXException
        javax.xml.stream.XMLStreamException
      • fireStartTag

        private final void fireStartTag()
                                 throws org.xml.sax.SAXException
        Throws:
        org.xml.sax.SAXException
      • setDocumentHandler

        public void setDocumentHandler​(org.xml.sax.DocumentHandler handler)
        Specified by:
        setDocumentHandler in interface org.xml.sax.Parser
      • setLocale

        public void setLocale​(java.util.Locale locale)
        Specified by:
        setLocale in interface org.xml.sax.Parser
      • getIndex

        public int getIndex​(java.lang.String qName)
        Specified by:
        getIndex in interface org.xml.sax.Attributes
      • getIndex

        public int getIndex​(java.lang.String uri,
                            java.lang.String localName)
        Specified by:
        getIndex in interface org.xml.sax.Attributes
      • getLength

        public int getLength()
        Specified by:
        getLength in interface org.xml.sax.Attributes
      • getLocalName

        public java.lang.String getLocalName​(int index)
        Specified by:
        getLocalName in interface org.xml.sax.Attributes
      • getQName

        public java.lang.String getQName​(int index)
        Specified by:
        getQName in interface org.xml.sax.Attributes
      • getType

        public java.lang.String getType​(int index)
        Specified by:
        getType in interface org.xml.sax.Attributes
      • getType

        public java.lang.String getType​(java.lang.String qName)
        Specified by:
        getType in interface org.xml.sax.Attributes
      • getType

        public java.lang.String getType​(java.lang.String uri,
                                        java.lang.String localName)
        Specified by:
        getType in interface org.xml.sax.Attributes
      • getURI

        public java.lang.String getURI​(int index)
        Specified by:
        getURI in interface org.xml.sax.Attributes
      • getValue

        public java.lang.String getValue​(int index)
        Specified by:
        getValue in interface org.xml.sax.Attributes
      • getValue

        public java.lang.String getValue​(java.lang.String qName)
        Specified by:
        getValue in interface org.xml.sax.Attributes
      • getValue

        public java.lang.String getValue​(java.lang.String uri,
                                         java.lang.String localName)
        Specified by:
        getValue in interface org.xml.sax.Attributes
      • isDeclared

        public boolean isDeclared​(int index)
        Specified by:
        isDeclared in interface org.xml.sax.ext.Attributes2
      • isDeclared

        public boolean isDeclared​(java.lang.String qName)
        Specified by:
        isDeclared in interface org.xml.sax.ext.Attributes2
      • isDeclared

        public boolean isDeclared​(java.lang.String uri,
                                  java.lang.String localName)
        Specified by:
        isDeclared in interface org.xml.sax.ext.Attributes2
      • isSpecified

        public boolean isSpecified​(int index)
        Specified by:
        isSpecified in interface org.xml.sax.ext.Attributes2
      • isSpecified

        public boolean isSpecified​(java.lang.String qName)
        Specified by:
        isSpecified in interface org.xml.sax.ext.Attributes2
      • isSpecified

        public boolean isSpecified​(java.lang.String uri,
                                   java.lang.String localName)
        Specified by:
        isSpecified in interface org.xml.sax.ext.Attributes2
      • getColumnNumber

        public int getColumnNumber()
        Specified by:
        getColumnNumber in interface org.xml.sax.Locator
      • getLineNumber

        public int getLineNumber()
        Specified by:
        getLineNumber in interface org.xml.sax.Locator
      • getPublicId

        public java.lang.String getPublicId()
        Specified by:
        getPublicId in interface org.xml.sax.Locator
      • getSystemId

        public java.lang.String getSystemId()
        Specified by:
        getSystemId in interface org.xml.sax.Locator
      • getEncoding

        public java.lang.String getEncoding()
        Specified by:
        getEncoding in interface org.xml.sax.ext.Locator2
      • getXMLVersion

        public java.lang.String getXMLVersion()
        Specified by:
        getXMLVersion in interface org.xml.sax.ext.Locator2
      • dtdReportComments

        public boolean dtdReportComments()
        Specified by:
        dtdReportComments in interface DTDEventListener
        Returns:
        True, if there is a listener interested in getting comment events within DTD subset (since that's optional)
      • dtdComment

        public void dtdComment​(char[] data,
                               int offset,
                               int len)
        Specified by:
        dtdComment in interface DTDEventListener
      • dtdNotationDecl

        public void dtdNotationDecl​(java.lang.String name,
                                    java.lang.String publicId,
                                    java.lang.String systemId,
                                    java.net.URL baseURL)
                             throws javax.xml.stream.XMLStreamException
        Specified by:
        dtdNotationDecl in interface DTDEventListener
        Throws:
        javax.xml.stream.XMLStreamException
      • dtdUnparsedEntityDecl

        public void dtdUnparsedEntityDecl​(java.lang.String name,
                                          java.lang.String publicId,
                                          java.lang.String systemId,
                                          java.lang.String notationName,
                                          java.net.URL baseURL)
                                   throws javax.xml.stream.XMLStreamException
        Specified by:
        dtdUnparsedEntityDecl in interface DTDEventListener
        Throws:
        javax.xml.stream.XMLStreamException
      • attributeDecl

        public void attributeDecl​(java.lang.String eName,
                                  java.lang.String aName,
                                  java.lang.String type,
                                  java.lang.String mode,
                                  java.lang.String value)
        Specified by:
        attributeDecl in interface DTDEventListener
      • dtdElementDecl

        public void dtdElementDecl​(java.lang.String name,
                                   java.lang.String model)
        Specified by:
        dtdElementDecl in interface DTDEventListener
      • dtdExternalEntityDecl

        public void dtdExternalEntityDecl​(java.lang.String name,
                                          java.lang.String publicId,
                                          java.lang.String systemId)
        Specified by:
        dtdExternalEntityDecl in interface DTDEventListener
      • throwSaxException

        private void throwSaxException​(java.lang.Exception src)
                                throws org.xml.sax.SAXException
        Throws:
        org.xml.sax.SAXException
      • throwSaxException

        private void throwSaxException​(java.lang.String msg)
                                throws org.xml.sax.SAXException
        Throws:
        org.xml.sax.SAXException
      • throwNoSuchAttribute

        private void throwNoSuchAttribute​(int index)