Class BasicStreamReader

  • All Implemented Interfaces:
    InputConfigFlags, ParsingErrorMsgs, InputProblemReporter, StreamReaderImpl, javax.xml.stream.XMLStreamConstants, javax.xml.stream.XMLStreamReader, org.codehaus.stax2.DTDInfo, org.codehaus.stax2.LocationInfo, org.codehaus.stax2.typed.TypedXMLStreamReader, org.codehaus.stax2.validation.Validatable, org.codehaus.stax2.XMLStreamReader2
    Direct Known Subclasses:
    TypedStreamReader

    public abstract class BasicStreamReader
    extends StreamScanner
    implements StreamReaderImpl, org.codehaus.stax2.DTDInfo, org.codehaus.stax2.LocationInfo
    Partial implementation of XMLStreamReader2 consisting of all functionality other than DTD-validation-specific parts, and Typed Access API (Stax2 v3.0), which are implemented at sub-classes.
    • Field Detail

      • MASK_GET_TEXT

        protected static final int MASK_GET_TEXT
        This mask covers all types for which basic getText() method can be called.
        See Also:
        Constant Field Values
      • MASK_GET_TEXT_XXX

        protected static final int MASK_GET_TEXT_XXX
        This mask covers all types for which extends getTextXxx methods can be called; which is less than those for which getText() can be called. Specifically, DTD and ENTITY_REFERENCE types do not support these extended
        See Also:
        Constant Field Values
      • MASK_GET_TEXT_WITH_WRITER

        protected static final int MASK_GET_TEXT_WITH_WRITER
        This mask is used with Stax2 getText() method (one that takes Writer as an argument): accepts even wider range of event types.
        See Also:
        Constant Field Values
      • MASK_GET_ELEMENT_TEXT

        protected static final int MASK_GET_ELEMENT_TEXT
        See Also:
        Constant Field Values
      • sPrefixXml

        protected static final java.lang.String sPrefixXml
      • sPrefixXmlns

        protected static final java.lang.String sPrefixXmlns
      • mConfigFlags

        protected final int mConfigFlags
        Set of locally stored configuration flags
      • mCfgCoalesceText

        protected final boolean mCfgCoalesceText
      • mCfgReportTextAsChars

        protected final boolean mCfgReportTextAsChars
      • mCfgLazyParsing

        protected final boolean mCfgLazyParsing
      • mShortestTextSegment

        protected final int mShortestTextSegment
        Minimum number of characters parser can return as partial text segment, IF it's not required to coalesce adjacent text segments.
      • mOwner

        protected final ReaderCreator mOwner
        Object to notify about shared stuff, such as symbol tables, as well as to query for additional config settings if necessary.
      • mDocStandalone

        protected int mDocStandalone
        Status about "stand-aloneness" of document; set to 'yes'/'no'/'unknown' based on whether there was xml declaration, and if so, whether it had standalone attribute.
      • mRootPrefix

        protected java.lang.String mRootPrefix
        Prefix of root element, as dictated by DOCTYPE declaration; null if no DOCTYPE declaration, or no root prefix
      • mRootLName

        protected java.lang.String mRootLName
        Local name of root element, as dictated by DOCTYPE declaration; null if no DOCTYPE declaration.
      • mDtdPublicId

        protected java.lang.String mDtdPublicId
        Public id of the DTD, if one exists and has been parsed.
      • mDtdSystemId

        protected java.lang.String mDtdSystemId
        System id of the DTD, if one exists and has been parsed.
      • mTextBuffer

        protected final TextBuffer mTextBuffer
        TextBuffer mostly used to collect non-element textual content (text, CDATA, comment content, pi data)
      • mElementStack

        protected final InputElementStack mElementStack
        Currently open element tree
      • mAttrCollector

        protected final AttributeCollector mAttrCollector
        Object that stores information about currently accessible attributes.
      • mStDoctypeFound

        protected boolean mStDoctypeFound
      • mTokenState

        protected int mTokenState
        State of the current token; one of M_ - constants from above.

        Initially set to fully tokenized, since it's the virtual START_DOCUMENT event that we fully know by now (parsed by bootstrapper)

      • mStTextThreshold

        protected final int mStTextThreshold
        Threshold value that defines tokenization state that needs to be achieved to "finish" current logical text segment (which may consist of adjacent CDATA and text segments; or be a complete physical segment; or just even a fragment of such a segment)
      • mCurrTextLength

        protected int mCurrTextLength
        Sized of currentTextLength for CDATA, CHARACTERS, WHITESPACE. When segmenting, this records to size of all the segments so we can track if the text length has exceeded limits.
      • mStEmptyElem

        protected boolean mStEmptyElem
      • mParseState

        protected int mParseState
        Main parsing/tokenization state (STATE_xxx)
      • mCurrToken

        protected int mCurrToken
        Current state of the stream, ie token value returned by getEventType(). Needs to be initialized to START_DOCUMENT, since that's the state it starts in.
      • mSecondaryToken

        protected int mSecondaryToken
        Additional information sometimes stored (when generating dummy events in multi-doc mode, for example) temporarily when mCurrToken is already populated.
      • mWsStatus

        protected int mWsStatus
        Status of current (text) token's "whitespaceness", that is, whether it is or is not all white space.
      • mValidateText

        protected boolean mValidateText
        Flag that indicates that textual content (CDATA, CHARACTERS) is to be validated within current element's scope. Enabled if one of validators returns XMLValidator.CONTENT_ALLOW_VALIDATABLE_TEXT, and will prevent lazy parsing of text.
      • mCheckIndentation

        protected int mCheckIndentation
        Counter used for determining whether we are to try to heuristically "intern" white space that seems to be used for indentation purposes
      • mPendingException

        protected javax.xml.stream.XMLStreamException mPendingException
        Due to the way Stax API does not allow throwing stream exceptions from many methods for which Woodstox would need to throw one (especially getText and its variations), we may need to delay throwing an exception until next() is called next time. If so, this variable holds the pending stream exception.
      • mGeneralEntities

        protected java.util.Map<java.lang.String,​EntityDecl> mGeneralEntities
        Entities parsed from internal/external DTD subsets. Although it will remain null for this class, extended classes make use of it, plus, to be able to share some of entity resolution code, instance is left here even though it semantically belongs to the sub-class.
      • mVldContent

        protected int mVldContent
        Mode information needed at this level; mostly to check what kind of textual content (if any) is allowed in current element context. Constants come from XMLValidator, (like XMLValidator.CONTENT_ALLOW_VALIDATABLE_TEXT). Only used inside tree; ignored for prolog/epilog (which have straight-forward static rules).
      • mReturnNullForDefaultNamespace

        protected boolean mReturnNullForDefaultNamespace
        Configuration from WstxInputProperties#RETURN_NULL_FOR_DEFAULT_NAMESPACE
        Since:
        4.1.2
    • Constructor Detail

      • BasicStreamReader

        protected BasicStreamReader​(InputBootstrapper bs,
                                    BranchingReaderSource input,
                                    ReaderCreator owner,
                                    ReaderConfig cfg,
                                    InputElementStack elemStack,
                                    boolean forER)
                             throws javax.xml.stream.XMLStreamException
        Parameters:
        elemStack - Input element stack to use; if null, will create instance locally.
        forER - Override indicator; if true, this stream reader will be used by an event reader, and should modify some of the base config settings appropriately. If false, configuration settings are to be used as is.
        Throws:
        javax.xml.stream.XMLStreamException
    • Method Detail

      • getCharacterEncodingScheme

        public java.lang.String getCharacterEncodingScheme()
        As per Stax (1.0) specs, needs to return whatever xml declaration claimed encoding is, if any; or null if no xml declaration found.

        Note: method name is rather confusing (compare to getEncoding()).

        Specified by:
        getCharacterEncodingScheme in interface javax.xml.stream.XMLStreamReader
      • getEncoding

        public java.lang.String getEncoding()
        As per Stax (1.0) specs, needs to return whatever parser determined the encoding was, if it was able to figure it out. If not (there are cases where this can not be found; specifically when being passed a Reader), it should return null.
        Specified by:
        getEncoding in interface javax.xml.stream.XMLStreamReader
      • getVersion

        public java.lang.String getVersion()
        Specified by:
        getVersion in interface javax.xml.stream.XMLStreamReader
      • isStandalone

        public boolean isStandalone()
        Specified by:
        isStandalone in interface javax.xml.stream.XMLStreamReader
      • standaloneSet

        public boolean standaloneSet()
        Specified by:
        standaloneSet in interface javax.xml.stream.XMLStreamReader
      • getProperty

        public java.lang.Object getProperty​(java.lang.String name)
        Specified by:
        getProperty in interface javax.xml.stream.XMLStreamReader
      • getAttributeCount

        public int getAttributeCount()
        Specified by:
        getAttributeCount in interface javax.xml.stream.XMLStreamReader
      • getAttributeLocalName

        public java.lang.String getAttributeLocalName​(int index)
        Specified by:
        getAttributeLocalName in interface javax.xml.stream.XMLStreamReader
      • getAttributeName

        public javax.xml.namespace.QName getAttributeName​(int index)
        Specified by:
        getAttributeName in interface javax.xml.stream.XMLStreamReader
      • getAttributeNamespace

        public java.lang.String getAttributeNamespace​(int index)
        Specified by:
        getAttributeNamespace in interface javax.xml.stream.XMLStreamReader
      • getAttributePrefix

        public java.lang.String getAttributePrefix​(int index)
        Specified by:
        getAttributePrefix in interface javax.xml.stream.XMLStreamReader
      • getAttributeType

        public java.lang.String getAttributeType​(int index)
        Specified by:
        getAttributeType in interface javax.xml.stream.XMLStreamReader
      • getAttributeValue

        public java.lang.String getAttributeValue​(int index)
        Specified by:
        getAttributeValue in interface javax.xml.stream.XMLStreamReader
      • getAttributeValue

        public java.lang.String getAttributeValue​(java.lang.String nsURI,
                                                  java.lang.String localName)
        Specified by:
        getAttributeValue in interface javax.xml.stream.XMLStreamReader
      • getElementText

        public java.lang.String getElementText()
                                        throws javax.xml.stream.XMLStreamException
        From StAX specs:
        Reads the content of a text-only element, an exception is thrown if this is not a text-only element. Regardless of value of javax.xml.stream.isCoalescing this method always returns coalesced content.
        Precondition: the current event is START_ELEMENT.
        Postcondition: the current event is the corresponding END_ELEMENT.
        Specified by:
        getElementText in interface javax.xml.stream.XMLStreamReader
        Throws:
        javax.xml.stream.XMLStreamException
      • getEventType

        public int getEventType()
        Returns type of the last event returned; or START_DOCUMENT before any events has been explicitly returned.
        Specified by:
        getEventType in interface javax.xml.stream.XMLStreamReader
      • getLocalName

        public java.lang.String getLocalName()
        Specified by:
        getLocalName in interface javax.xml.stream.XMLStreamReader
      • getName

        public javax.xml.namespace.QName getName()
        Specified by:
        getName in interface javax.xml.stream.XMLStreamReader
      • getNamespaceContext

        public javax.xml.namespace.NamespaceContext getNamespaceContext()
        Specified by:
        getNamespaceContext in interface javax.xml.stream.XMLStreamReader
      • getNamespaceCount

        public int getNamespaceCount()
        Specified by:
        getNamespaceCount in interface javax.xml.stream.XMLStreamReader
      • getNamespacePrefix

        public java.lang.String getNamespacePrefix​(int index)
        Specified by:
        getNamespacePrefix in interface javax.xml.stream.XMLStreamReader
      • getNamespaceURI

        public java.lang.String getNamespaceURI()
        Specified by:
        getNamespaceURI in interface javax.xml.stream.XMLStreamReader
      • getNamespaceURI

        public java.lang.String getNamespaceURI​(int index)
        Specified by:
        getNamespaceURI in interface javax.xml.stream.XMLStreamReader
      • getNamespaceURI

        public java.lang.String getNamespaceURI​(java.lang.String prefix)
        Specified by:
        getNamespaceURI in interface javax.xml.stream.XMLStreamReader
      • getPIData

        public java.lang.String getPIData()
        Specified by:
        getPIData in interface javax.xml.stream.XMLStreamReader
      • getPITarget

        public java.lang.String getPITarget()
        Specified by:
        getPITarget in interface javax.xml.stream.XMLStreamReader
      • getPrefix

        public java.lang.String getPrefix()
        Specified by:
        getPrefix in interface javax.xml.stream.XMLStreamReader
      • getText

        public java.lang.String getText()
        Specified by:
        getText in interface javax.xml.stream.XMLStreamReader
      • getTextCharacters

        public char[] getTextCharacters()
        Specified by:
        getTextCharacters in interface javax.xml.stream.XMLStreamReader
      • getTextCharacters

        public int getTextCharacters​(int sourceStart,
                                     char[] target,
                                     int targetStart,
                                     int len)
        Specified by:
        getTextCharacters in interface javax.xml.stream.XMLStreamReader
      • getTextLength

        public int getTextLength()
        Specified by:
        getTextLength in interface javax.xml.stream.XMLStreamReader
      • getTextStart

        public int getTextStart()
        Specified by:
        getTextStart in interface javax.xml.stream.XMLStreamReader
      • hasName

        public boolean hasName()
        Specified by:
        hasName in interface javax.xml.stream.XMLStreamReader
      • hasNext

        public boolean hasNext()
        Specified by:
        hasNext in interface javax.xml.stream.XMLStreamReader
      • hasText

        public boolean hasText()
        Specified by:
        hasText in interface javax.xml.stream.XMLStreamReader
      • isAttributeSpecified

        public boolean isAttributeSpecified​(int index)
        Specified by:
        isAttributeSpecified in interface javax.xml.stream.XMLStreamReader
      • isCharacters

        public boolean isCharacters()
        Specified by:
        isCharacters in interface javax.xml.stream.XMLStreamReader
      • isEndElement

        public boolean isEndElement()
        Specified by:
        isEndElement in interface javax.xml.stream.XMLStreamReader
      • isStartElement

        public boolean isStartElement()
        Specified by:
        isStartElement in interface javax.xml.stream.XMLStreamReader
      • isWhiteSpace

        public boolean isWhiteSpace()

        05-Apr-2004, TSa: Could try to determine status when text is actually read. That'd prevent double reads... but would it slow down that one reading so that net effect would be negative?

        Specified by:
        isWhiteSpace in interface javax.xml.stream.XMLStreamReader
      • require

        public void require​(int type,
                            java.lang.String nsUri,
                            java.lang.String localName)
                     throws javax.xml.stream.XMLStreamException
        Specified by:
        require in interface javax.xml.stream.XMLStreamReader
        Throws:
        javax.xml.stream.XMLStreamException
      • next

        public final int next()
                       throws javax.xml.stream.XMLStreamException
        Specified by:
        next in interface javax.xml.stream.XMLStreamReader
        Throws:
        javax.xml.stream.XMLStreamException
      • nextTag

        public int nextTag()
                    throws javax.xml.stream.XMLStreamException
        Specified by:
        nextTag in interface javax.xml.stream.XMLStreamReader
        Throws:
        javax.xml.stream.XMLStreamException
      • close

        public void close()
                   throws javax.xml.stream.XMLStreamException

        Note: as per StAX 1.0 specs, this method does NOT close the underlying input reader. That is, unless the new StAX2 property XMLInputFactory2.P_AUTO_CLOSE_INPUT is set to true.

        Specified by:
        close in interface javax.xml.stream.XMLStreamReader
        Throws:
        javax.xml.stream.XMLStreamException
      • getFeature

        @Deprecated
        public java.lang.Object getFeature​(java.lang.String name)
        Deprecated.
        Specified by:
        getFeature in interface org.codehaus.stax2.XMLStreamReader2
      • setFeature

        @Deprecated
        public void setFeature​(java.lang.String name,
                               java.lang.Object value)
        Deprecated.
        Specified by:
        setFeature in interface org.codehaus.stax2.XMLStreamReader2
      • isPropertySupported

        public boolean isPropertySupported​(java.lang.String name)
        Specified by:
        isPropertySupported in interface org.codehaus.stax2.XMLStreamReader2
      • setProperty

        public boolean setProperty​(java.lang.String name,
                                   java.lang.Object value)
        Specified by:
        setProperty in interface org.codehaus.stax2.XMLStreamReader2
        Parameters:
        name - Name of the property to set
        value - Value to set property to.
        Returns:
        True, if the specified property was succesfully set to specified value; false if its value was not changed
      • skipElement

        public void skipElement()
                         throws javax.xml.stream.XMLStreamException
        Specified by:
        skipElement in interface org.codehaus.stax2.XMLStreamReader2
        Throws:
        javax.xml.stream.XMLStreamException
      • getAttributeInfo

        public org.codehaus.stax2.AttributeInfo getAttributeInfo()
                                                          throws javax.xml.stream.XMLStreamException
        Specified by:
        getAttributeInfo in interface org.codehaus.stax2.XMLStreamReader2
        Throws:
        javax.xml.stream.XMLStreamException
      • getDTDInfo

        public org.codehaus.stax2.DTDInfo getDTDInfo()
                                              throws javax.xml.stream.XMLStreamException
        Since this class implements DTDInfo, method can just return this.
        Specified by:
        getDTDInfo in interface org.codehaus.stax2.XMLStreamReader2
        Throws:
        javax.xml.stream.XMLStreamException
      • getLocationInfo

        public final org.codehaus.stax2.LocationInfo getLocationInfo()
        Location information is always accessible, for this reader.
        Specified by:
        getLocationInfo in interface org.codehaus.stax2.XMLStreamReader2
      • getText

        public int getText​(java.io.Writer w,
                           boolean preserveContents)
                    throws java.io.IOException,
                           javax.xml.stream.XMLStreamException
        Method similar to getText(), except that it just uses provided Writer to write all textual content. For further optimization, it may also be allowed to do true pass-through, thus possibly avoiding one temporary copy of the data.

        TODO: try to optimize to allow completely streaming pass-through: currently will still read all data in memory buffers before outputting

        Specified by:
        getText in interface org.codehaus.stax2.XMLStreamReader2
        Parameters:
        w - Writer to use for writing textual contents
        preserveContents - If true, reader has to preserve contents so that further calls to getText will return proper conntets. If false, reader is allowed to skip creation of such copies: this can improve performance, but it also means that further calls to getText is not guaranteed to return meaningful data.
        Returns:
        Number of characters written to the reader
        Throws:
        java.io.IOException
        javax.xml.stream.XMLStreamException
      • getDepth

        public int getDepth()
        Specified by:
        getDepth in interface org.codehaus.stax2.XMLStreamReader2
        Returns:
        Number of open elements in the stack; 0 when parser is in prolog/epilog, 1 inside root element and so on.
      • isEmptyElement

        public boolean isEmptyElement()
                               throws javax.xml.stream.XMLStreamException
        Specified by:
        isEmptyElement in interface org.codehaus.stax2.XMLStreamReader2
        Returns:
        True, if cursor points to a start or end element that is constructed from 'empty' element (ends with '/>'); false otherwise.
        Throws:
        javax.xml.stream.XMLStreamException
      • getNonTransientNamespaceContext

        public javax.xml.namespace.NamespaceContext getNonTransientNamespaceContext()
        Specified by:
        getNonTransientNamespaceContext in interface org.codehaus.stax2.XMLStreamReader2
      • getPrefixedName

        public java.lang.String getPrefixedName()
        Specified by:
        getPrefixedName in interface org.codehaus.stax2.XMLStreamReader2
      • closeCompletely

        public void closeCompletely()
                             throws javax.xml.stream.XMLStreamException
        Specified by:
        closeCompletely in interface org.codehaus.stax2.XMLStreamReader2
        Throws:
        javax.xml.stream.XMLStreamException
      • getProcessedDTD

        public java.lang.Object getProcessedDTD()

        Note: DTD-handling sub-classes need to override this method.

        Specified by:
        getProcessedDTD in interface org.codehaus.stax2.DTDInfo
      • getDTDRootName

        public java.lang.String getDTDRootName()
        Specified by:
        getDTDRootName in interface org.codehaus.stax2.DTDInfo
      • getDTDPublicId

        public java.lang.String getDTDPublicId()
        Specified by:
        getDTDPublicId in interface org.codehaus.stax2.DTDInfo
      • getDTDSystemId

        public java.lang.String getDTDSystemId()
        Specified by:
        getDTDSystemId in interface org.codehaus.stax2.DTDInfo
      • getDTDInternalSubset

        public java.lang.String getDTDInternalSubset()
        Specified by:
        getDTDInternalSubset in interface org.codehaus.stax2.DTDInfo
        Returns:
        Internal subset portion of the DOCTYPE declaration, if any; empty String if none
      • getDTDInternalSubsetArray

        private char[] getDTDInternalSubsetArray()
        Internal method used by implementation
      • getProcessedDTDSchema

        public org.codehaus.stax2.validation.DTDValidationSchema getProcessedDTDSchema()
        Sub-class will override this method
        Specified by:
        getProcessedDTDSchema in interface org.codehaus.stax2.DTDInfo
      • getStartingByteOffset

        public long getStartingByteOffset()
        Specified by:
        getStartingByteOffset in interface org.codehaus.stax2.LocationInfo
      • getStartingCharOffset

        public long getStartingCharOffset()
        Specified by:
        getStartingCharOffset in interface org.codehaus.stax2.LocationInfo
      • getEndingByteOffset

        public long getEndingByteOffset()
                                 throws javax.xml.stream.XMLStreamException
        Specified by:
        getEndingByteOffset in interface org.codehaus.stax2.LocationInfo
        Throws:
        javax.xml.stream.XMLStreamException
      • getEndingCharOffset

        public long getEndingCharOffset()
                                 throws javax.xml.stream.XMLStreamException
        Specified by:
        getEndingCharOffset in interface org.codehaus.stax2.LocationInfo
        Throws:
        javax.xml.stream.XMLStreamException
      • getLocation

        public final javax.xml.stream.Location getLocation()
        Description copied from class: StreamScanner
        Returns location of last properly parsed token; as per StAX specs, apparently needs to be the end of current event, which is the same as the start of the following event (or EOF if that's next).
        Specified by:
        getLocation in interface InputProblemReporter
        Specified by:
        getLocation in interface org.codehaus.stax2.LocationInfo
        Specified by:
        getLocation in interface javax.xml.stream.XMLStreamReader
        Specified by:
        getLocation in class StreamScanner
      • getEndLocation

        public final org.codehaus.stax2.XMLStreamLocation2 getEndLocation()
                                                                   throws javax.xml.stream.XMLStreamException
        Specified by:
        getEndLocation in interface org.codehaus.stax2.LocationInfo
        Throws:
        javax.xml.stream.XMLStreamException
      • validateAgainst

        public org.codehaus.stax2.validation.XMLValidator validateAgainst​(org.codehaus.stax2.validation.XMLValidationSchema schema)
                                                                   throws javax.xml.stream.XMLStreamException
        Specified by:
        validateAgainst in interface org.codehaus.stax2.validation.Validatable
        Throws:
        javax.xml.stream.XMLStreamException
      • stopValidatingAgainst

        public org.codehaus.stax2.validation.XMLValidator stopValidatingAgainst​(org.codehaus.stax2.validation.XMLValidationSchema schema)
                                                                         throws javax.xml.stream.XMLStreamException
        Specified by:
        stopValidatingAgainst in interface org.codehaus.stax2.validation.Validatable
        Throws:
        javax.xml.stream.XMLStreamException
      • stopValidatingAgainst

        public org.codehaus.stax2.validation.XMLValidator stopValidatingAgainst​(org.codehaus.stax2.validation.XMLValidator validator)
                                                                         throws javax.xml.stream.XMLStreamException
        Specified by:
        stopValidatingAgainst in interface org.codehaus.stax2.validation.Validatable
        Throws:
        javax.xml.stream.XMLStreamException
      • setValidationProblemHandler

        public org.codehaus.stax2.validation.ValidationProblemHandler setValidationProblemHandler​(org.codehaus.stax2.validation.ValidationProblemHandler h)
        Specified by:
        setValidationProblemHandler in interface org.codehaus.stax2.validation.Validatable
      • withStartElement

        public java.lang.Object withStartElement​(ElemCallback cb,
                                                 javax.xml.stream.Location loc)
        Method called by DefaultEventAllocator to get double-indirection necessary for constructing start element events.
        Specified by:
        withStartElement in interface StreamReaderImpl
        Returns:
        Null, if stream does not point to start element; whatever callback returns otherwise.
      • getInputElementStack

        public InputElementStack getInputElementStack()
        Method needed by classes (like stream writer implementations) that want to have efficient direct access to element stack implementation
        Specified by:
        getInputElementStack in interface StreamReaderImpl
      • getAttributeCollector

        public AttributeCollector getAttributeCollector()
        Method needed by classes (like stream writer implementations) that want to have efficient direct access to attribute collector Object, for optimal attribute name and value access.
        Specified by:
        getAttributeCollector in interface StreamReaderImpl
      • 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
      • hasConfigFlags

        protected final boolean hasConfigFlags​(int flags)
      • checkKeyword

        protected java.lang.String checkKeyword​(char c,
                                                java.lang.String expected)
                                         throws javax.xml.stream.XMLStreamException
        Returns:
        Null, if keyword matches ok; String that contains erroneous keyword if not.
        Throws:
        javax.xml.stream.XMLStreamException
      • checkCData

        protected void checkCData()
                           throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • parseAttrValue

        private final void parseAttrValue​(char openingQuote,
                                          TextBuilder tb)
                                   throws javax.xml.stream.XMLStreamException
        Method that will parse an attribute value enclosed in quotes, using an TextBuilder instance. Will normalize white space inside attribute value using default XML rules (change linefeeds to spaces etc.; but won't use DTD information for further coalescing).
        Parameters:
        openingQuote - Quote character (single or double quote) for this attribute value
        tb - TextBuilder into which attribute value will be added
        Throws:
        javax.xml.stream.XMLStreamException
      • _checkAttributeLimit

        private final char[] _checkAttributeLimit​(TextBuilder tb,
                                                  char[] outBuf,
                                                  int outPtr,
                                                  int currAttrSize,
                                                  int maxAttrSize)
                                           throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • nextFromProlog

        private boolean nextFromProlog​(boolean isProlog)
                                throws javax.xml.stream.XMLStreamException
        Method called to find type of next token in prolog; either reading just enough information to know the type (lazy parsing), or the full contents (non-lazy)
        Returns:
        True if we hit EOI, false otherwise
        Throws:
        javax.xml.stream.XMLStreamException
      • handleRootElem

        protected void handleRootElem​(char c)
                               throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • initValidation

        protected void initValidation()
                               throws javax.xml.stream.XMLStreamException
        Method called right before the document root element is handled. The default implementation is empty; validating stream readers should override the method and do whatever initialization is necessary
        Throws:
        javax.xml.stream.XMLStreamException
      • handleEOF

        protected int handleEOF​(boolean isProlog)
                         throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • handleExtraRoot

        private int handleExtraRoot​(char c)
                             throws javax.xml.stream.XMLStreamException
        Method called if a root-level element is found after the main root element was closed. This is legal in multi-doc parsing mode (and in fragment mode), but not in the default single-doc mode.
        Parameters:
        c - Character passed in (not currently used)
        Returns:
        Token to return
        Throws:
        javax.xml.stream.XMLStreamException
      • handleMultiDocStart

        protected int handleMultiDocStart​(int nextEvent)
        Method called when an event was encountered that indicates document boundary in multi-doc mode. Needs to trigger dummy END_DOCUMENT/START_DOCUMENT event combination, followed by the handling of the original event.
        Returns:
        Event type to return
      • nextFromMultiDocState

        private int nextFromMultiDocState()
                                   throws javax.xml.stream.XMLStreamException
        Method called to get the next event when we are "multi-doc hack" mode, during which extra END_DOCUMENT/START_DOCUMENT events need to be returned.
        Throws:
        javax.xml.stream.XMLStreamException
      • handleMultiDocXmlDecl

        protected void handleMultiDocXmlDecl()
                                      throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • skipEquals

        protected final char skipEquals​(java.lang.String name,
                                        java.lang.String eofMsg)
                                 throws javax.xml.stream.XMLStreamException
        Method that checks that input following is of form '[S]* '=' [S]*' (as per XML specs, production #25). Will push back non-white space characters as necessary, in case no equals char is encountered.
        Throws:
        javax.xml.stream.XMLStreamException
      • parseQuoted

        protected final void parseQuoted​(java.lang.String name,
                                         char quoteChar,
                                         TextBuffer tbuf)
                                  throws javax.xml.stream.XMLStreamException
        Method called to parse quoted xml declaration pseudo-attribute values. Works similar to attribute value parsing, except no entities can be included, and in general need not be as picky (since caller is to verify contents). One exception is that we do check for linefeeds and lt chars, since they generally would indicate problems and are useful to catch early on (can happen if a quote is missed etc)

        Note: since it'll be called at most 3 times per document, this method is not optimized too much.

        Throws:
        javax.xml.stream.XMLStreamException
      • nextFromPrologBang

        private void nextFromPrologBang​(boolean isProlog)
                                 throws javax.xml.stream.XMLStreamException
        Called after character sequence '<!' has been found; expectation is that it'll either be DOCTYPE declaration (if we are in prolog and haven't yet seen one), or a comment. CDATA is not legal here; it would start same way otherwise.
        Throws:
        javax.xml.stream.XMLStreamException
      • startDTD

        private void startDTD()
                       throws javax.xml.stream.XMLStreamException
        Method called to parse through most of DOCTYPE declaration; excluding optional internal subset.
        Throws:
        javax.xml.stream.XMLStreamException
      • finishDTD

        protected void finishDTD​(boolean copyContents)
                          throws javax.xml.stream.XMLStreamException
        This method gets called to handle remainder of DOCTYPE declaration, essentially the optional internal subset. This class implements the basic "ignore it" functionality, but can optionally still store copy of the contents to the read buffer.

        NOTE: Since this default implementation will be overridden by some sub-classes, make sure you do NOT change the method signature.

        Parameters:
        copyContents - If true, will copy contents of the internal subset of DOCTYPE declaration in the text buffer; if false, will just completely ignore the subset (if one found).
        Throws:
        javax.xml.stream.XMLStreamException
      • nextFromTree

        private final int nextFromTree()
                                throws javax.xml.stream.XMLStreamException
        Method called to parse beginning of the next event within document tree, and return its type.
        Throws:
        javax.xml.stream.XMLStreamException
      • closeContentTree

        private int closeContentTree()
                              throws javax.xml.stream.XMLStreamException
        Method called when advancing stream past the end tag that closes the root element of the open document. Document can be either the singular one, in regular mode, or one of possibly multiple, in multi-doc mode: this method is never called in fragment mode. Method needs to update state properly and parse following epilog event (if any).
        Returns:
        Event following end tag of the root elemennt, if any; END_DOCUMENT otherwis.e
        Throws:
        javax.xml.stream.XMLStreamException
      • handleStartElem

        private final void handleStartElem​(char c)
                                    throws javax.xml.stream.XMLStreamException
        Method that takes care of parsing of start elements; including full parsing of namespace declarations and attributes, as well as namespace resolution.
        Throws:
        javax.xml.stream.XMLStreamException
      • handleNsAttrs

        private final boolean handleNsAttrs​(char c)
                                     throws javax.xml.stream.XMLStreamException
        Returns:
        True if this is an empty element; false if not
        Throws:
        javax.xml.stream.XMLStreamException
      • handleNonNsAttrs

        private final boolean handleNonNsAttrs​(char c)
                                        throws javax.xml.stream.XMLStreamException
        Returns:
        True if this is an empty element; false if not
        Throws:
        javax.xml.stream.XMLStreamException
      • readEndElem

        protected final void readEndElem()
                                  throws javax.xml.stream.XMLStreamException
        Method called to completely read a close tag, and update element stack appropriately (including checking that tag matches etc).
        Throws:
        javax.xml.stream.XMLStreamException
      • reportExtraEndElem

        private void reportExtraEndElem()
                                 throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • reportWrongEndPrefix

        private void reportWrongEndPrefix​(java.lang.String prefix,
                                          java.lang.String localName,
                                          int done)
                                   throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • reportWrongEndElem

        private void reportWrongEndElem​(java.lang.String prefix,
                                        java.lang.String localName,
                                        int done)
                                 throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • nextFromTreeCommentOrCData

        private int nextFromTreeCommentOrCData()
                                        throws javax.xml.stream.XMLStreamException

        Note: According to StAX 1.0, coalesced text events are always to be returned as CHARACTERS, never as CDATA. And since at this point we don't really know if there's anything to coalesce (but there may be), let's convert CDATA if necessary.

        Throws:
        javax.xml.stream.XMLStreamException
      • skipToken

        private int skipToken()
                       throws javax.xml.stream.XMLStreamException
        Method called to skip last part of current token, when full token has not been parsed. Generally happens when caller is not interested in current token and just calls next() to iterate to next token.

        Note: this method is to accurately update the location information to reflect where the next event will start (or, in case of EOF, where EOF was encountered, ie. where event would start, if there was one).

        Returns:
        Next character after node has been skipped, or -1 if EOF follows
        Throws:
        javax.xml.stream.XMLStreamException
      • skipCommentOrCData

        private void skipCommentOrCData​(java.lang.String errorMsg,
                                        char endChar,
                                        boolean preventDoubles)
                                 throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • skipCoalescedText

        private int skipCoalescedText​(int i)
                               throws javax.xml.stream.XMLStreamException
        Method called to skip past all following text and CDATA segments, until encountering something else (including a general entity, which may in turn expand to text).
        Returns:
        Character following all the skipped text and CDATA segments, if any; or -1 to denote EOF
        Throws:
        javax.xml.stream.XMLStreamException
      • skipTokenText

        private int skipTokenText​(int i)
                           throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • ensureFinishToken

        protected void ensureFinishToken()
                                  throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • safeEnsureFinishToken

        protected void safeEnsureFinishToken()
      • safeFinishToken

        protected void safeFinishToken()
      • finishToken

        protected void finishToken​(boolean deferErrors)
                            throws javax.xml.stream.XMLStreamException
        Method called to read in contents of the token completely, if not yet read. Generally called when caller needs to access anything other than basic token type (except for elements), text contents or such.
        Parameters:
        deferErrors - Flag to enable storing an exception to a variable, instead of immediately throwing it. If true, will just store the exception; if false, will not store, just throw.
        Throws:
        javax.xml.stream.XMLStreamException
      • readComment

        private void readComment()
                          throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • readComment2

        private void readComment2​(TextBuffer tb)
                           throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • readPIPrimary

        private final int readPIPrimary()
                                 throws javax.xml.stream.XMLStreamException
        Method that reads the primary part of a PI, ie. target, and also skips white space between target and data (if any data)
        Returns:
        Usually PROCESSING_INSTRUCTION; but may be different in multi-doc mode, if we actually hit a secondary xml declaration.
        Throws:
        javax.xml.stream.XMLStreamException
      • readPI

        private void readPI()
                     throws javax.xml.stream.XMLStreamException
        Method that parses a processing instruction's data portion; at this point target has been parsed.
        Throws:
        javax.xml.stream.XMLStreamException
      • readPI2

        private void readPI2​(TextBuffer tb)
                      throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • readCoalescedText

        protected void readCoalescedText​(int currType,
                                         boolean deferErrors)
                                  throws javax.xml.stream.XMLStreamException
        Method called to read the content of both current CDATA/CHARACTERS events, and all following consequtive events into the text buffer. At this point the current type is known, prefix (for CDATA) skipped, and initial consequtive contents (if any) read in.
        Parameters:
        deferErrors - Flag to enable storing an exception to a variable, instead of immediately throwing it. If true, will just store the exception; if false, will not store, just throw.
        Throws:
        javax.xml.stream.XMLStreamException
      • readCDataPrimary

        private final boolean readCDataPrimary​(char c)
                                        throws javax.xml.stream.XMLStreamException
        Method called to read in consecutive beginning parts of a CDATA segment, up to either end of the segment (]] and >) or until first 'hole' in text (buffer end, 2-char lf to convert, entity).

        When the method is called, it's expected that the first character has been read as is in the current input buffer just before current pointer

        Parameters:
        c - First character in the CDATA segment (possibly part of end marker for empty segments
        Returns:
        True if the whole CDATA segment was completely read; this happens only if lt-char is hit; false if it's possible that it wasn't read (ie. end-of-buffer or entity encountered).
        Throws:
        javax.xml.stream.XMLStreamException
      • readCDataSecondary

        protected boolean readCDataSecondary​(int shortestSegment)
                                      throws javax.xml.stream.XMLStreamException
        Returns:
        True if the whole CData section was completely read (we hit the end marker); false if a shorter segment was returned.
        Throws:
        javax.xml.stream.XMLStreamException
      • checkCDataEnd

        private boolean checkCDataEnd​(char[] outBuf,
                                      int outPtr)
                               throws javax.xml.stream.XMLStreamException
        Method that will check, given the starting ']', whether there is ending ']]>' (including optional extra ']'s); if so, will updated output buffer with extra ]s, if not, will make sure input and output are positioned for further checking.
        Returns:
        True, if we hit the end marker; false if not.
        Throws:
        javax.xml.stream.XMLStreamException
      • readTextPrimary

        private final boolean readTextPrimary​(char c)
                                       throws javax.xml.stream.XMLStreamException
        Method called to read in consecutive beginning parts of a text segment, up to either end of the segment (lt char) or until first 'hole' in text (buffer end, 2-char lf to convert, entity).

        When the method is called, it's expected that the first character has been read as is in the current input buffer just before current pointer

        Parameters:
        c - First character of the text segment
        Returns:
        True if the whole text segment was completely read; this happens only if lt-char is hit; false if it's possible that it wasn't read (ie. end-of-buffer or entity encountered).
        Throws:
        javax.xml.stream.XMLStreamException
      • readTextSecondary

        protected final boolean readTextSecondary​(int shortestSegment,
                                                  boolean deferErrors)
                                           throws javax.xml.stream.XMLStreamException
        Parameters:
        deferErrors - Flag to enable storing an exception to a variable, instead of immediately throwing it. If true, will just store the exception; if false, will not store, just throw.
        Returns:
        True if the text segment was completely read ('<' was hit, or in non-entity-expanding mode, a non-char entity); false if it may still continue
        Throws:
        javax.xml.stream.XMLStreamException
      • _expandOutputForText

        private final char[] _expandOutputForText​(int inputPtr,
                                                  char[] outBuf,
                                                  int shortestSegment)
      • readIndentation

        private final int readIndentation​(char c,
                                          int ptr)
                                   throws javax.xml.stream.XMLStreamException
        Method called to try to parse and canonicalize white space that has a good chance of being white space with somewhat regular structure; specifically, something that looks like typical indentation.

        Note: Caller guarantees that there will be at least 2 characters available in the input buffer. And method has to ensure that if it does not find a match, it will return pointer value such that there is at least one valid character remaining.

        Returns:
        -1, if the content was determined to be canonicalizable (indentation) white space; and thus fully parsed. Otherwise pointer (value to set to mInputPtr) to the next character to process (not processed by this method)
        Throws:
        javax.xml.stream.XMLStreamException
      • readSpacePrimary

        private final boolean readSpacePrimary​(char c,
                                               boolean prologWS)
                                        throws javax.xml.stream.XMLStreamException
        Reading whitespace should be very similar to reading normal text; although couple of simplifications can be made. Further, since this method is very unlikely to be of much performance concern, some optimizations are left out, where it simplifies code.
        Parameters:
        c - First white space characters; known to contain white space at this point
        prologWS - If true, is reading white space outside XML tree, and as such can get EOF. If false, should not get EOF, nor be followed by any other char than <
        Returns:
        True if the whole white space segment was read; false if something prevented that (end of buffer, replaceable 2-char lf)
        Throws:
        javax.xml.stream.XMLStreamException
      • readSpaceSecondary

        private void readSpaceSecondary​(boolean prologWS)
                                 throws javax.xml.stream.XMLStreamException
        This is very similar to readSecondaryText(); called when we need to read in rest of (ignorable) white space segment.
        Parameters:
        prologWS - True if the ignorable white space is within prolog (or epilog); false if it's within xml tree.
        Throws:
        javax.xml.stream.XMLStreamException
      • readAndWriteText

        private int readAndWriteText​(java.io.Writer w)
                              throws java.io.IOException,
                                     javax.xml.stream.XMLStreamException
        Method called to read the contents of the current CHARACTERS event, and write all contents using the specified Writer.
        Parameters:
        w - Writer to use for writing out textual content parsed
        Returns:
        Total number of characters written using the writer
        Throws:
        java.io.IOException
        javax.xml.stream.XMLStreamException
      • readAndWriteCData

        private int readAndWriteCData​(java.io.Writer w)
                               throws java.io.IOException,
                                      javax.xml.stream.XMLStreamException
        Method called to read the contents of the current (possibly partially read) CDATA event, and write all contents using the specified Writer.
        Parameters:
        w - Writer to use for writing out textual content parsed
        Returns:
        Total number of characters written using the writer for the current CDATA event
        Throws:
        java.io.IOException
        javax.xml.stream.XMLStreamException
      • readAndWriteCoalesced

        private int readAndWriteCoalesced​(java.io.Writer w,
                                          boolean wasCData)
                                   throws java.io.IOException,
                                          javax.xml.stream.XMLStreamException
        Returns:
        Number of characters written to Writer during the call
        Throws:
        java.io.IOException
        javax.xml.stream.XMLStreamException
      • skipWS

        protected final boolean skipWS​(char c)
                                throws javax.xml.stream.XMLStreamException
        Method that will skip any white space from input source(s)
        Returns:
        true If at least one white space was skipped; false if not (character passed was not white space)
        Throws:
        javax.xml.stream.XMLStreamException
      • findEntity

        protected EntityDecl findEntity​(java.lang.String id,
                                        java.lang.Object arg)
                                 throws javax.xml.stream.XMLStreamException
        Description copied from class: StreamScanner
        Abstract method for sub-classes to implement, for finding a declared general or parsed entity.
        Specified by:
        findEntity in class StreamScanner
        Parameters:
        id - Identifier of the entity to find
        arg - Optional argument passed from caller; needed by DTD reader.
        Throws:
        javax.xml.stream.XMLStreamException
      • handleUndeclaredEntity

        protected void handleUndeclaredEntity​(java.lang.String id)
                                       throws javax.xml.stream.XMLStreamException
        Description copied from class: StreamScanner
        This method gets called if a declaration for an entity was not found in entity expanding mode (enabled by default for xml reader, always enabled for dtd reader).
        Specified by:
        handleUndeclaredEntity in class StreamScanner
        Throws:
        javax.xml.stream.XMLStreamException
      • handleGreedyEntityProblem

        protected void handleGreedyEntityProblem​(WstxInputSource input)
                                          throws javax.xml.stream.XMLStreamException
        This problem gets reported if an entity tries to expand to a close tag matching start tag that did not came from the same entity (but from parent).
        Throws:
        javax.xml.stream.XMLStreamException
      • throwNotTextual

        private void throwNotTextual​(int type)
      • throwNotTextXxx

        private void throwNotTextXxx​(int type)
      • throwNotTextualOrElem

        protected void throwNotTextualOrElem​(int type)
      • throwUnexpectedEOF

        protected void throwUnexpectedEOF()
                                   throws WstxException
        Method called when we get an EOF within content tree
        Throws:
        WstxException
      • _constructUnexpectedInTyped

        protected javax.xml.stream.XMLStreamException _constructUnexpectedInTyped​(int nextToken)
        Method called to report a problem with
      • _constructTypeException

        protected org.codehaus.stax2.typed.TypedXMLStreamException _constructTypeException​(java.lang.String msg,
                                                                                           java.lang.String lexicalValue)
      • reportInvalidContent

        protected void reportInvalidContent​(int evtType)
                                     throws javax.xml.stream.XMLStreamException
        Stub method implemented by validating parsers, to report content that's not valid for current element context. Defined at this level since some such problems need to be caught at low-level; however, details of error reports are not needed here.
        Parameters:
        evtType - Type of event that contained unexpected content
        Throws:
        javax.xml.stream.XMLStreamException