Class ReaderScanner

  • All Implemented Interfaces:
    XmlConsts, javax.xml.namespace.NamespaceContext, javax.xml.stream.XMLStreamConstants

    public final class ReaderScanner
    extends XmlScanner
    This is the concrete scanner implementation used when input comes as a Reader. In general using this scanner is quite a bit less optimal than that of InputStream based scanner. Nonetheless, it is included for completeness, since Stax interface allows passing Readers as input sources.
    • Field Detail

      • sCharTypes

        private static final XmlCharTypes sCharTypes
        Although java chars are basically UTF-16 in memory, the closest match for char types is Latin1.
      • _in

        protected java.io.Reader _in
        Underlying InputStream to use for reading content.
      • _inputBuffer

        protected char[] _inputBuffer
      • _inputPtr

        protected int _inputPtr
      • _inputEnd

        protected int _inputEnd
      • mTmpChar

        protected int mTmpChar
        Storage location for a single character that can not be pushed back (for example, multi-byte char)
      • _symbols

        protected final CharBasedPNameTable _symbols
        For now, symbol table contains prefixed names. In future it is possible that they may be split into prefixes and local names?
    • Constructor Detail

      • ReaderScanner

        public ReaderScanner​(ReaderConfig cfg,
                             java.io.Reader r,
                             char[] buffer,
                             int ptr,
                             int last)
      • ReaderScanner

        public ReaderScanner​(ReaderConfig cfg,
                             java.io.Reader r)
    • Method Detail

      • _closeSource

        protected void _closeSource()
                             throws java.io.IOException
        Specified by:
        _closeSource in class XmlScanner
        Throws:
        java.io.IOException
      • finishToken

        protected final void finishToken()
                                  throws javax.xml.stream.XMLStreamException
        Description copied from class: XmlScanner
        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)
        Specified by:
        finishToken in class XmlScanner
        Throws:
        javax.xml.stream.XMLStreamException
      • nextFromProlog

        public final int nextFromProlog​(boolean isProlog)
                                 throws javax.xml.stream.XMLStreamException
        Specified by:
        nextFromProlog in class XmlScanner
        Throws:
        javax.xml.stream.XMLStreamException
      • nextFromTree

        public final int nextFromTree()
                               throws javax.xml.stream.XMLStreamException
        Specified by:
        nextFromTree in class XmlScanner
        Throws:
        javax.xml.stream.XMLStreamException
      • _nextEntity

        protected int _nextEntity()
        Helper method used to isolate things that need to be (re)set in cases where
      • handlePrologDeclStart

        protected final int handlePrologDeclStart​(boolean isProlog)
                                           throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • handleDtdStart

        private final int handleDtdStart()
                                  throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • handleCommentOrCdataStart

        protected final int handleCommentOrCdataStart()
                                               throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • handlePIStart

        protected final int handlePIStart()
                                   throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • handleCharEntity

        protected final int handleCharEntity()
                                      throws javax.xml.stream.XMLStreamException
        Returns:
        Code point for the entity that expands to a valid XML content character.
        Throws:
        javax.xml.stream.XMLStreamException
      • handleStartElement

        protected final int handleStartElement​(char c)
                                        throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • collectValue

        private int collectValue​(int attrPtr,
                                 char quoteChar,
                                 PName attrName)
                          throws javax.xml.stream.XMLStreamException
        This method implements the tight loop for parsing attribute values. It's off-lined from the main start element method to simplify main method, which makes code more maintainable and possibly easier for JIT/HotSpot to optimize.
        Throws:
        javax.xml.stream.XMLStreamException
      • handleNsDeclaration

        private void handleNsDeclaration​(PName name,
                                         char quoteChar)
                                  throws javax.xml.stream.XMLStreamException
        Method called from the main START_ELEMENT handling loop, to parse namespace URI values.
        Throws:
        javax.xml.stream.XMLStreamException
      • handleEndElement

        protected final int handleEndElement()
                                      throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • handleEntityInText

        protected final int handleEntityInText​(boolean inAttr)
                                        throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • finishComment

        protected final void finishComment()
                                    throws javax.xml.stream.XMLStreamException
        Specified by:
        finishComment in class XmlScanner
        Throws:
        javax.xml.stream.XMLStreamException
      • finishPI

        protected final void finishPI()
                               throws javax.xml.stream.XMLStreamException
        Specified by:
        finishPI in class XmlScanner
        Throws:
        javax.xml.stream.XMLStreamException
      • finishDTD

        protected final void finishDTD​(boolean copyContents)
                                throws javax.xml.stream.XMLStreamException
        Specified by:
        finishDTD in class XmlScanner
        Throws:
        javax.xml.stream.XMLStreamException
      • finishCData

        protected final void finishCData()
                                  throws javax.xml.stream.XMLStreamException
        Specified by:
        finishCData in class XmlScanner
        Throws:
        javax.xml.stream.XMLStreamException
      • finishCharacters

        protected final void finishCharacters()
                                       throws javax.xml.stream.XMLStreamException
        Specified by:
        finishCharacters in class XmlScanner
        Throws:
        javax.xml.stream.XMLStreamException
      • finishSpace

        protected final void finishSpace()
                                  throws javax.xml.stream.XMLStreamException
        Specified by:
        finishSpace in class XmlScanner
        Throws:
        javax.xml.stream.XMLStreamException
      • finishCoalescedText

        protected final void finishCoalescedText()
                                          throws javax.xml.stream.XMLStreamException
        Method that gets called after a primary text segment (of type CHARACTERS or CDATA, not applicable to SPACE) has been read in text buffer. Method has to see if the following event would be textual as well, and if so, read it (and any other following textual segments).
        Throws:
        javax.xml.stream.XMLStreamException
      • finishCoalescedCData

        protected final void finishCoalescedCData()
                                           throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • finishCoalescedCharacters

        protected final void finishCoalescedCharacters()
                                                throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • skipCoalescedText

        protected final boolean skipCoalescedText()
                                           throws javax.xml.stream.XMLStreamException
        Method that gets called after a primary text segment (of type CHARACTERS or CDATA, not applicable to SPACE) has been skipped. Method has to see if the following event would be textual as well, and if so, skip it (and any other following textual segments).
        Specified by:
        skipCoalescedText in class XmlScanner
        Returns:
        True if we encountered an unexpandable entity
        Throws:
        javax.xml.stream.XMLStreamException
      • skipComment

        protected final void skipComment()
                                  throws javax.xml.stream.XMLStreamException
        Specified by:
        skipComment in class XmlScanner
        Throws:
        javax.xml.stream.XMLStreamException
      • skipPI

        protected final void skipPI()
                             throws javax.xml.stream.XMLStreamException
        Specified by:
        skipPI in class XmlScanner
        Throws:
        javax.xml.stream.XMLStreamException
      • skipCharacters

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

        protected final void skipCData()
                                throws javax.xml.stream.XMLStreamException
        Specified by:
        skipCData in class XmlScanner
        Throws:
        javax.xml.stream.XMLStreamException
      • skipSpace

        protected final void skipSpace()
                                throws javax.xml.stream.XMLStreamException
        Specified by:
        skipSpace in class XmlScanner
        Throws:
        javax.xml.stream.XMLStreamException
      • skipInternalWs

        protected char skipInternalWs​(boolean reqd,
                                      java.lang.String msg)
                               throws javax.xml.stream.XMLStreamException
        Returns:
        First byte following skipped white space
        Throws:
        javax.xml.stream.XMLStreamException
      • matchAsciiKeyword

        private final void matchAsciiKeyword​(java.lang.String keyw)
                                      throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • checkInTreeIndentation

        protected final int checkInTreeIndentation​(char c)
                                            throws javax.xml.stream.XMLStreamException

        Note: consequtive white space is only considered indentation, if the following token seems like a tag (start/end). This so that if a CDATA section follows, it can be coalesced in coalescing mode. Although we could check if coalescing mode is enabled, this should seldom have significant effect either way, so it removes one possible source of problems in coalescing mode.

        Returns:
        -1, if indentation was handled; offset in the output buffer, if not
        Throws:
        javax.xml.stream.XMLStreamException
      • checkPrologIndentation

        protected final int checkPrologIndentation​(char c)
                                            throws javax.xml.stream.XMLStreamException
        Returns:
        -1, if indentation was handled; offset in the output buffer, if not
        Throws:
        javax.xml.stream.XMLStreamException
      • parsePName

        protected PName parsePName​(char c)
                            throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • addPName

        protected final PName addPName​(char[] nameBuffer,
                                       int nameLen,
                                       int hash)
                                throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • parsePublicId

        protected java.lang.String parsePublicId​(char quoteChar)
                                          throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • parseSystemId

        protected java.lang.String parseSystemId​(char quoteChar)
                                          throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • checkSurrogate

        private char checkSurrogate​(char firstChar)
                             throws javax.xml.stream.XMLStreamException
        This method is called to verify that a surrogate pair found describes a legal surrogate pair (ie. expands to a legal XML char)
        Throws:
        javax.xml.stream.XMLStreamException
      • checkSurrogateNameChar

        private int checkSurrogateNameChar​(char firstChar,
                                           char sec,
                                           int index)
                                    throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • decodeSurrogate

        private int decodeSurrogate​(char firstChar)
                             throws javax.xml.stream.XMLStreamException
        This method is similar to checkSurrogate, but returns the actual character code encoded by the surrogate pair. This is needed if further validation rules (such as name charactert checks) are to be done.
        Throws:
        javax.xml.stream.XMLStreamException
      • reportInvalidFirstSurrogate

        private void reportInvalidFirstSurrogate​(char ch)
                                          throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • reportInvalidSecondSurrogate

        private void reportInvalidSecondSurrogate​(char ch)
                                           throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • getCurrentLocation

        public org.codehaus.stax2.XMLStreamLocation2 getCurrentLocation()
        Specified by:
        getCurrentLocation in class XmlScanner
        Returns:
        Current input location
      • getEndingByteOffset

        public long getEndingByteOffset()
                                 throws javax.xml.stream.XMLStreamException
        Specified by:
        getEndingByteOffset in class XmlScanner
        Throws:
        javax.xml.stream.XMLStreamException
      • getEndingCharOffset

        public long getEndingCharOffset()
                                 throws javax.xml.stream.XMLStreamException
        Specified by:
        getEndingCharOffset in class XmlScanner
        Throws:
        javax.xml.stream.XMLStreamException
      • markLF

        protected final void markLF​(int offset)
      • markLF

        protected final void markLF()
      • setStartLocation

        protected final void setStartLocation()
      • loadMore

        protected final boolean loadMore()
                                  throws javax.xml.stream.XMLStreamException
        Specified by:
        loadMore in class XmlScanner
        Throws:
        javax.xml.stream.XMLStreamException
      • loadOne

        protected final char loadOne()
                              throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • loadOne

        protected final char loadOne​(int type)
                              throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • loadAndRetain

        protected final boolean loadAndRetain​(int nrOfChars)
                                       throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException