Class XmlScanner

  • All Implemented Interfaces:
    XmlConsts, javax.xml.namespace.NamespaceContext, javax.xml.stream.XMLStreamConstants
    Direct Known Subclasses:
    ByteBasedScanner, ReaderScanner

    public abstract class XmlScanner
    extends java.lang.Object
    implements XmlConsts, javax.xml.stream.XMLStreamConstants, javax.xml.namespace.NamespaceContext
    This is the abstract base class for all scanner implementations, defining operations the actual parser requires from the low-level scanners. Scanners are encoding and input type (byte, char / stream, block) specific, so there are many implementations.
    • Field Detail

      • CDATA_STR

        protected final java.lang.String CDATA_STR
        String that identifies CDATA section (after "<![" prefix)
        See Also:
        Constant Field Values
      • TOKEN_EOI

        public static final int TOKEN_EOI
        This token type signifies end-of-input, in cases where it can be returned. In other cases, an exception may be thrown.
        See Also:
        Constant Field Values
      • MAX_UNICODE_CHAR

        protected static final int MAX_UNICODE_CHAR
        This constant defines the highest Unicode character allowed in XML content.
        See Also:
        Constant Field Values
      • BIND_MISSES_TO_ACTIVATE_CACHE

        private static final int BIND_MISSES_TO_ACTIVATE_CACHE
        Let's activate cache quite soon, no need to wait for hundreds of misses; just try to avoid cache construction if all we get is soap envelope element or such.
        See Also:
        Constant Field Values
      • BIND_CACHE_SIZE

        private static final int BIND_CACHE_SIZE
        Size of the bind cache can be reasonably small, and should still get high enough hit rate
        See Also:
        Constant Field Values
      • _xml11

        protected final boolean _xml11
        Whether validity checks (wrt. name and text characters) and normalization (linefeeds) is to be done using xml 1.1 rules, or basic xml 1.0 rules. Default is 1.0.
      • _cfgCoalescing

        protected final boolean _cfgCoalescing
      • _cfgLazyParsing

        protected boolean _cfgLazyParsing
      • _currToken

        protected int _currToken
      • _tokenIncomplete

        protected boolean _tokenIncomplete
      • _depth

        protected int _depth
        Number of START_ELEMENT events returned for which no END_ELEMENT has been returned; including current event.
      • _textBuilder

        protected final TextBuilder _textBuilder
        Textual content of the current event
      • _entityPending

        protected boolean _entityPending
        Flag set to indicate that an entity is pending
      • _nameBuffer

        protected char[] _nameBuffer
        Similarly, need a char buffer for actual String construction (in future, could perhaps use StringBuilder?). It is used for holding things like names (element, attribute), and attribute values.
      • _tokenName

        protected PName _tokenName
        Current name associated with the token, if any. Name of the current element, target of processing instruction, or name of an unexpanded entity.
      • _isEmptyTag

        protected boolean _isEmptyTag
        Flag that is used if the current state is START_ELEMENT or END_ELEMENT, to indicate if the underlying physical tag is a so-called empty tag (one ending with "/>")
      • _currElem

        protected ElementScope _currElem
        Information about the current element on the stack
      • _publicId

        protected java.lang.String _publicId
        Public id of the current event (DTD), if any.
      • _systemId

        protected java.lang.String _systemId
        System id of the current event (DTD), if any.
      • _lastNsDecl

        protected NsDeclaration _lastNsDecl
        Pointer to the last namespace declaration encountered. Because of backwards linking, it also serves as the head of the linked list of all active namespace declarations starting from the most recent one.
      • _currNsCount

        protected int _currNsCount
        This is a temporary state variable, valid during START_ELEMENT event. For those events, contains number of namespace declarations available. For END_ELEMENT, this count is computed on the fly.
      • _defaultNs

        protected NsBinding _defaultNs
        Default namespace binding is a per-document singleton, like explicit bindings, and used for elements (never for attributes).
      • _nsBindings

        protected NsBinding[] _nsBindings
        Array containing all prefix bindings needed within the current document, so far (if any). These bindings are not in a particular order, and they specifically do NOT represent actual namespace declarations parsed from xml content.
      • _nsBindingCount

        protected int _nsBindingCount
      • _nsBindingCache

        protected PName[] _nsBindingCache
        Although unbound pname instances can be easily and safely reused, bound ones are per-document. However, it makes sense to try to reuse them too; at least using a minimal static cache, activate only after certain number of cache misses (to avoid overhead for tiny documents, or documents with few or no namespace prefixes).
      • _nsBindMisses

        protected int _nsBindMisses
      • _attrCount

        protected int _attrCount
      • _pastBytesOrChars

        protected long _pastBytesOrChars
        Number of bytes that were read and processed before the contents of the current buffer; used for calculating absolute offsets.
      • _currRow

        protected int _currRow
        The row on which the character to read next is on. Note that it is 0-based, so API will generally add one to it before returning the value
      • _rowStartOffset

        protected int _rowStartOffset
        Offset used to calculate the column value given current input buffer pointer. May be negative, if the first character of the row was contained within an earlier buffer.
      • _startRawOffset

        protected long _startRawOffset
        Offset (in chars or bytes) at start of current token
      • _startRow

        protected long _startRow
        Current row at start of current (last returned) token
      • _startColumn

        protected long _startColumn
        Current column at start of current (last returned) token
    • Constructor Detail

    • Method Detail

      • close

        public final void close​(boolean forceCloseSource)
                         throws javax.xml.stream.XMLStreamException
        Method called at point when the parsing process has ended (either by encountering end of the input, or via explicit close), and buffers can and should be released.
        Parameters:
        forceCloseSource - True if the underlying input source is to be closed, independent of whether auto-close has been set to true via configuration (or if the scanner manages the input source)
        Throws:
        javax.xml.stream.XMLStreamException
      • _releaseBuffers

        protected void _releaseBuffers()
      • _closeSource

        protected abstract void _closeSource()
                                      throws java.io.IOException
        Throws:
        java.io.IOException
      • nextFromProlog

        public abstract int nextFromProlog​(boolean isProlog)
                                    throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • nextFromTree

        public abstract int nextFromTree()
                                  throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • finishToken

        protected abstract void finishToken()
                                     throws javax.xml.stream.XMLStreamException
        This method is called to ensure that the current token/event has been completely parsed, such that we have all the data needed to return it (textual content, PI data, comment text etc)
        Throws:
        javax.xml.stream.XMLStreamException
      • skipToken

        protected final boolean skipToken()
                                   throws javax.xml.stream.XMLStreamException
        This method is called to essentially skip remaining of the current token (data of PI etc)
        Returns:
        True If by skipping we also figured out following event type (and assigned its type to _currToken); false if that remains to be done
        Throws:
        javax.xml.stream.XMLStreamException
      • getCurrentLocation

        public abstract org.codehaus.stax2.XMLStreamLocation2 getCurrentLocation()
        Returns:
        Current input location
      • getStartLocation

        public final org.codehaus.stax2.XMLStreamLocation2 getStartLocation()
      • getStartingByteOffset

        public abstract long getStartingByteOffset()
      • getStartingCharOffset

        public abstract long getStartingCharOffset()
      • getEndingByteOffset

        public abstract long getEndingByteOffset()
                                          throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • getEndingCharOffset

        public abstract long getEndingCharOffset()
                                          throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • getEndLocation

        public org.codehaus.stax2.XMLStreamLocation2 getEndLocation()
                                                             throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • getCurrentLineNr

        public final int getCurrentLineNr()
      • getCurrentColumnNr

        public abstract int getCurrentColumnNr()
      • getInputSystemId

        public final java.lang.String getInputSystemId()
      • getInputPublicId

        public final java.lang.String getInputPublicId()
      • hasEmptyStack

        public final boolean hasEmptyStack()
      • getDepth

        public final int getDepth()
      • isEmptyTag

        public final boolean isEmptyTag()
      • getName

        public final PName getName()
      • getQName

        public final javax.xml.namespace.QName getQName()
      • getDTDPublicId

        public final java.lang.String getDTDPublicId()
      • getDTDSystemId

        public final java.lang.String getDTDSystemId()
      • getText

        public final java.lang.String getText()
                                       throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • getTextLength

        public final int getTextLength()
                                throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • getTextCharacters

        public final char[] getTextCharacters()
                                       throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • getTextCharacters

        public final int getTextCharacters​(int srcStart,
                                           char[] target,
                                           int targetStart,
                                           int len)
                                    throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • getText

        public final int getText​(java.io.Writer w,
                                 boolean preserveContents)
                          throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • isTextWhitespace

        public final boolean isTextWhitespace()
                                       throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • decodeElements

        public final int decodeElements​(org.codehaus.stax2.typed.TypedArrayDecoder tad,
                                        boolean reset)
                                 throws javax.xml.stream.XMLStreamException
        Method called by the stream reader to decode space-separated tokens that are part of the current text event, using given decoder.
        Parameters:
        reset - If true, need to tell text buffer to reset its decoding state; if false, shouldn't
        Throws:
        javax.xml.stream.XMLStreamException
      • resetForDecoding

        public final void resetForDecoding​(org.codehaus.stax2.typed.Base64Variant v,
                                           org.codehaus.stax2.ri.typed.CharArrayBase64Decoder dec,
                                           boolean firstChunk)
                                    throws javax.xml.stream.XMLStreamException
        Method called by the stream reader to reset given base64 decoder with data from the current text event.
        Throws:
        javax.xml.stream.XMLStreamException
      • fireSaxStartElement

        public void fireSaxStartElement​(org.xml.sax.ContentHandler h,
                                        org.xml.sax.Attributes attrs)
                                 throws org.xml.sax.SAXException
        Throws:
        org.xml.sax.SAXException
      • fireSaxEndElement

        public void fireSaxEndElement​(org.xml.sax.ContentHandler h)
                               throws org.xml.sax.SAXException
        Throws:
        org.xml.sax.SAXException
      • fireSaxCharacterEvents

        public void fireSaxCharacterEvents​(org.xml.sax.ContentHandler h)
                                    throws javax.xml.stream.XMLStreamException,
                                           org.xml.sax.SAXException
        Throws:
        javax.xml.stream.XMLStreamException
        org.xml.sax.SAXException
      • fireSaxSpaceEvents

        public void fireSaxSpaceEvents​(org.xml.sax.ContentHandler h)
                                throws javax.xml.stream.XMLStreamException,
                                       org.xml.sax.SAXException
        Throws:
        javax.xml.stream.XMLStreamException
        org.xml.sax.SAXException
      • fireSaxCommentEvent

        public void fireSaxCommentEvent​(org.xml.sax.ext.LexicalHandler h)
                                 throws javax.xml.stream.XMLStreamException,
                                        org.xml.sax.SAXException
        Throws:
        javax.xml.stream.XMLStreamException
        org.xml.sax.SAXException
      • fireSaxPIEvent

        public void fireSaxPIEvent​(org.xml.sax.ContentHandler h)
                            throws javax.xml.stream.XMLStreamException,
                                   org.xml.sax.SAXException
        Throws:
        javax.xml.stream.XMLStreamException
        org.xml.sax.SAXException
      • getAttrCount

        public final int getAttrCount()
      • getAttrLocalName

        public final java.lang.String getAttrLocalName​(int index)
      • getAttrQName

        public final javax.xml.namespace.QName getAttrQName​(int index)
      • getAttrPrefixedName

        public final java.lang.String getAttrPrefixedName​(int index)
      • getAttrNsURI

        public final java.lang.String getAttrNsURI​(int index)
      • getAttrPrefix

        public final java.lang.String getAttrPrefix​(int index)
      • getAttrValue

        public final java.lang.String getAttrValue​(int index)
      • getAttrValue

        public final java.lang.String getAttrValue​(java.lang.String nsURI,
                                                   java.lang.String localName)
      • decodeAttrValue

        public final void decodeAttrValue​(int index,
                                          org.codehaus.stax2.typed.TypedValueDecoder tvd)
                                   throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • decodeAttrValues

        public final int decodeAttrValues​(int index,
                                          org.codehaus.stax2.typed.TypedArrayDecoder tad)
                                   throws javax.xml.stream.XMLStreamException
        Method called to decode the attribute value that consists of zero or more space-separated tokens. Decoding is done using the decoder provided.
        Returns:
        Number of tokens decoded
        Throws:
        javax.xml.stream.XMLStreamException
      • decodeAttrBinaryValue

        public final byte[] decodeAttrBinaryValue​(int index,
                                                  org.codehaus.stax2.typed.Base64Variant v,
                                                  org.codehaus.stax2.ri.typed.CharArrayBase64Decoder dec)
                                           throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • findAttrIndex

        public final int findAttrIndex​(java.lang.String nsURI,
                                       java.lang.String localName)
      • getAttrType

        public final java.lang.String getAttrType​(int index)
      • isAttrSpecified

        public final boolean isAttrSpecified​(int index)
      • getNsCount

        public final int getNsCount()
      • getNamespacePrefix

        public final java.lang.String getNamespacePrefix​(int index)
      • getNamespaceURI

        public final java.lang.String getNamespaceURI​(int index)
      • findCurrNsDecl

        private NsDeclaration findCurrNsDecl​(int index)
      • getNamespaceURI

        public final java.lang.String getNamespaceURI()
      • getNonTransientNamespaceContext

        public final javax.xml.namespace.NamespaceContext getNonTransientNamespaceContext()
      • getNamespaceURI

        public java.lang.String getNamespaceURI​(java.lang.String prefix)
        Specified by:
        getNamespaceURI in interface javax.xml.namespace.NamespaceContext
      • getPrefix

        public java.lang.String getPrefix​(java.lang.String nsURI)
        Specified by:
        getPrefix in interface javax.xml.namespace.NamespaceContext
      • getPrefixes

        public java.util.Iterator<java.lang.String> getPrefixes​(java.lang.String nsURI)
        Specified by:
        getPrefixes in interface javax.xml.namespace.NamespaceContext
      • finishCharacters

        protected abstract void finishCharacters()
                                          throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • finishCData

        protected abstract void finishCData()
                                     throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • finishComment

        protected abstract void finishComment()
                                       throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • finishDTD

        protected abstract void finishDTD​(boolean copyContents)
                                   throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • finishPI

        protected abstract void finishPI()
                                  throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • finishSpace

        protected abstract void finishSpace()
                                     throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • skipCharacters

        protected abstract boolean skipCharacters()
                                           throws javax.xml.stream.XMLStreamException
        Returns:
        True, if an unexpanded entity was encountered (and is now pending)
        Throws:
        javax.xml.stream.XMLStreamException
      • skipCData

        protected abstract void skipCData()
                                   throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • skipComment

        protected abstract void skipComment()
                                     throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • skipPI

        protected abstract void skipPI()
                                throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • skipSpace

        protected abstract void skipSpace()
                                   throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • skipCoalescedText

        protected abstract boolean skipCoalescedText()
                                              throws javax.xml.stream.XMLStreamException
        Secondary skip method called after primary text segment has been skipped, and we are in coalescing mode.
        Returns:
        True, if an unexpanded entity was encountered (and is now pending)
        Throws:
        javax.xml.stream.XMLStreamException
      • loadMore

        protected abstract boolean loadMore()
                                     throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • bindName

        protected final PName bindName​(PName name,
                                       java.lang.String prefix)
        This method is called to find/create a fully qualified (bound) name (element / attribute), for a name with prefix. For non-prefixed names this method will not get called
      • findOrCreateBinding

        protected final NsBinding findOrCreateBinding​(java.lang.String prefix)
                                               throws javax.xml.stream.XMLStreamException
        Method called when a namespace declaration needs to find the binding object (essentially a per-prefix-per-document canonical container object)
        Throws:
        javax.xml.stream.XMLStreamException
      • bindNs

        protected final void bindNs​(PName name,
                                    java.lang.String uri)
                             throws javax.xml.stream.XMLStreamException
        Method called when we are ready to bind a declared namespace.
        Throws:
        javax.xml.stream.XMLStreamException
      • checkImmutableBinding

        protected final void checkImmutableBinding​(java.lang.String prefix,
                                                   java.lang.String uri)
                                            throws javax.xml.stream.XMLStreamException
        Method called when an immutable ns prefix (xml, xmlns) is encountered.
        Throws:
        javax.xml.stream.XMLStreamException
      • loadMoreGuaranteed

        protected final void loadMoreGuaranteed()
                                         throws javax.xml.stream.XMLStreamException
        Method that tries to load at least one more byte into buffer; and if that fails, throws an appropriate EOI exception.
        Throws:
        javax.xml.stream.XMLStreamException
      • loadMoreGuaranteed

        protected final void loadMoreGuaranteed​(int tt)
                                         throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • verifyXmlChar

        protected final void verifyXmlChar​(int value)
                                    throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • reportInputProblem

        protected void reportInputProblem​(java.lang.String msg)
                                   throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • reportUnexpandedEntityInAttr

        protected void reportUnexpandedEntityInAttr​(PName name,
                                                    boolean isNsDecl)
                                             throws javax.xml.stream.XMLStreamException
        Method called when a call to expand an entity within attribute value fails to expand it.
        Throws:
        javax.xml.stream.XMLStreamException
      • reportPrologUnexpElement

        protected void reportPrologUnexpElement​(boolean isProlog,
                                                int ch)
                                         throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • reportPrologUnexpChar

        protected void reportPrologUnexpChar​(boolean isProlog,
                                             int ch,
                                             java.lang.String msg)
                                      throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • reportPrologProblem

        protected void reportPrologProblem​(boolean isProlog,
                                           java.lang.String msg)
                                    throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • reportTreeUnexpChar

        protected void reportTreeUnexpChar​(int ch,
                                           java.lang.String msg)
                                    throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • reportInvalidNameChar

        protected void reportInvalidNameChar​(int ch,
                                             int index)
                                      throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • reportInvalidXmlChar

        protected void reportInvalidXmlChar​(int ch)
                                     throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • reportEofInName

        protected void reportEofInName​(char[] cbuf,
                                       int clen)
                                throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • reportMissingPISpace

        protected void reportMissingPISpace​(int ch)
                                     throws javax.xml.stream.XMLStreamException
        Called when there's an unexpected char after PI target (non-ws, not part of '?>' end marker
        Throws:
        javax.xml.stream.XMLStreamException
      • reportDoubleHyphenInComments

        protected void reportDoubleHyphenInComments()
                                             throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • reportMultipleColonsInName

        protected void reportMultipleColonsInName()
                                           throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • reportEntityOverflow

        protected void reportEntityOverflow()
                                     throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • reportInvalidNsIndex

        protected void reportInvalidNsIndex​(int index)
      • reportUnboundPrefix

        protected void reportUnboundPrefix​(PName name,
                                           boolean isAttr)
                                    throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • reportDuplicateNsDecl

        protected void reportDuplicateNsDecl​(java.lang.String prefix)
                                      throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • reportIllegalNsDecl

        protected void reportIllegalNsDecl​(java.lang.String prefix)
                                    throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • reportIllegalNsDecl

        protected void reportIllegalNsDecl​(java.lang.String prefix,
                                           java.lang.String uri)
                                    throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • reportUnexpectedEndTag

        protected void reportUnexpectedEndTag​(java.lang.String expName)
                                       throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • reportIllegalCDataEnd

        protected void reportIllegalCDataEnd()
                                      throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • throwUnexpectedChar

        protected void throwUnexpectedChar​(int i,
                                           java.lang.String msg)
                                    throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • throwNullChar

        protected void throwNullChar()
                              throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • handleInvalidXmlChar

        protected char handleInvalidXmlChar​(int i)
                                     throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • throwInvalidSpace

        protected void throwInvalidSpace​(int i)
                                  throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException