Package com.fasterxml.aalto.in
Class ReaderScanner
- java.lang.Object
-
- com.fasterxml.aalto.in.XmlScanner
-
- com.fasterxml.aalto.in.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 aReader. In general using this scanner is quite a bit less optimal than that ofInputStreambased scanner. Nonetheless, it is included for completeness, since Stax interface allows passing Readers as input sources.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.io.Reader_inUnderlying InputStream to use for reading content.protected char[]_inputBufferprotected int_inputEndprotected int_inputPtrprotected CharBasedPNameTable_symbolsFor now, symbol table contains prefixed names.protected intmTmpCharStorage location for a single character that can not be pushed back (for example, multi-byte char)-
Fields inherited from class com.fasterxml.aalto.in.XmlScanner
_attrCollector, _attrCount, _cfgCoalescing, _cfgLazyParsing, _config, _currElem, _currNsCount, _currRow, _currToken, _defaultNs, _depth, _entityPending, _isEmptyTag, _lastNsContext, _lastNsDecl, _nameBuffer, _nsBindingCache, _nsBindingCount, _nsBindings, _nsBindMisses, _pastBytesOrChars, _publicId, _rowStartOffset, _startColumn, _startRawOffset, _startRow, _systemId, _textBuilder, _tokenIncomplete, _tokenName, _xml11, CDATA_STR, INT_0, INT_9, INT_a, INT_A, INT_AMP, INT_APOS, INT_COLON, INT_CR, INT_EQ, INT_EXCL, INT_f, INT_F, INT_GT, INT_HYPHEN, INT_LBRACKET, INT_LF, INT_LT, INT_NULL, INT_QMARK, INT_QUOTE, INT_RBRACKET, INT_SLASH, INT_SPACE, INT_TAB, INT_z, MAX_UNICODE_CHAR, TOKEN_EOI
-
Fields inherited from interface com.fasterxml.aalto.util.XmlConsts
CHAR_CR, CHAR_LF, CHAR_NULL, CHAR_SPACE, STAX_DEFAULT_OUTPUT_ENCODING, STAX_DEFAULT_OUTPUT_VERSION, XML_DECL_KW_ENCODING, XML_DECL_KW_STANDALONE, XML_DECL_KW_VERSION, XML_SA_NO, XML_SA_YES, XML_V_10, XML_V_10_STR, XML_V_11, XML_V_11_STR, XML_V_UNKNOWN
-
-
Constructor Summary
Constructors Constructor Description ReaderScanner(ReaderConfig cfg, java.io.Reader r)ReaderScanner(ReaderConfig cfg, java.io.Reader r, char[] buffer, int ptr, int last)ReaderScanner(ReaderConfig cfg, java.io.Reader r, int pastChars)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void_closeSource()protected int_nextEntity()Helper method used to isolate things that need to be (re)set in cases whereprotected void_releaseBuffers()protected PNameaddPName(char[] nameBuffer, int nameLen, int hash)protected intcheckInTreeIndentation(char c)Note: consequtive white space is only considered indentation, if the following token seems like a tag (start/end).protected intcheckPrologIndentation(char c)protected voidfinishCData()protected voidfinishCharacters()protected voidfinishCoalescedCData()protected voidfinishCoalescedCharacters()protected voidfinishCoalescedText()Method that gets called after a primary text segment (of type CHARACTERS or CDATA, not applicable to SPACE) has been read in text buffer.protected voidfinishComment()protected voidfinishDTD(boolean copyContents)protected voidfinishPI()protected voidfinishSpace()protected voidfinishToken()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)intgetCurrentColumnNr()org.codehaus.stax2.XMLStreamLocation2getCurrentLocation()longgetEndingByteOffset()longgetEndingCharOffset()longgetStartingByteOffset()longgetStartingCharOffset()protected inthandleCharEntity()protected inthandleCommentOrCdataStart()protected inthandleEndElement()protected inthandleEntityInText(boolean inAttr)protected inthandlePIStart()protected inthandlePrologDeclStart(boolean isProlog)protected inthandleStartElement(char c)protected booleanloadAndRetain(int nrOfChars)protected booleanloadMore()protected charloadOne()protected charloadOne(int type)protected voidmarkLF()protected voidmarkLF(int offset)intnextFromProlog(boolean isProlog)intnextFromTree()protected PNameparsePName(char c)protected java.lang.StringparsePublicId(char quoteChar)protected java.lang.StringparseSystemId(char quoteChar)protected voidsetStartLocation()protected voidskipCData()protected booleanskipCharacters()protected booleanskipCoalescedText()Method that gets called after a primary text segment (of type CHARACTERS or CDATA, not applicable to SPACE) has been skipped.protected voidskipComment()protected charskipInternalWs(boolean reqd, java.lang.String msg)protected voidskipPI()protected voidskipSpace()-
Methods inherited from class com.fasterxml.aalto.in.XmlScanner
bindName, bindNs, checkImmutableBinding, close, decodeAttrBinaryValue, decodeAttrValue, decodeAttrValues, decodeElements, findAttrIndex, findOrCreateBinding, fireSaxCharacterEvents, fireSaxCommentEvent, fireSaxEndElement, fireSaxPIEvent, fireSaxSpaceEvents, fireSaxStartElement, getAttrCollector, getAttrCount, getAttrLocalName, getAttrNsURI, getAttrPrefix, getAttrPrefixedName, getAttrQName, getAttrType, getAttrValue, getAttrValue, getConfig, getCurrentLineNr, getDepth, getDTDPublicId, getDTDSystemId, getEndLocation, getInputPublicId, getInputSystemId, getName, getNamespacePrefix, getNamespaceURI, getNamespaceURI, getNamespaceURI, getNonTransientNamespaceContext, getNsCount, getPrefix, getPrefixes, getQName, getStartLocation, getText, getText, getTextCharacters, getTextCharacters, getTextLength, handleInvalidXmlChar, hasEmptyStack, isAttrSpecified, isEmptyTag, isTextWhitespace, loadMoreGuaranteed, loadMoreGuaranteed, reportDoubleHyphenInComments, reportDuplicateNsDecl, reportEntityOverflow, reportEofInName, reportIllegalCDataEnd, reportIllegalNsDecl, reportIllegalNsDecl, reportInputProblem, reportInvalidNameChar, reportInvalidNsIndex, reportInvalidXmlChar, reportMissingPISpace, reportMultipleColonsInName, reportPrologProblem, reportPrologUnexpChar, reportPrologUnexpElement, reportTreeUnexpChar, reportUnboundPrefix, reportUnexpandedEntityInAttr, reportUnexpectedEndTag, resetForDecoding, skipToken, throwInvalidSpace, throwNullChar, throwUnexpectedChar, verifyXmlChar
-
-
-
-
Field Detail
-
_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)
-
ReaderScanner
public ReaderScanner(ReaderConfig cfg, java.io.Reader r, int pastChars)
- Parameters:
pastChars- Number of characters already consumed from the logical input source before this scanner takes over (e.g., the length of an XML declaration parsed by a bootstrapper). Used as the initial value for the character-offset counter so reported locations include the skipped prolog. See [aalto-xml#73].
-
-
Method Detail
-
_releaseBuffers
protected void _releaseBuffers()
- Overrides:
_releaseBuffersin classXmlScanner
-
_closeSource
protected void _closeSource() throws java.io.IOException- Specified by:
_closeSourcein classXmlScanner- Throws:
java.io.IOException
-
finishToken
protected final void finishToken() throws javax.xml.stream.XMLStreamExceptionDescription copied from class:XmlScannerThis 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:
finishTokenin classXmlScanner- Throws:
javax.xml.stream.XMLStreamException
-
nextFromProlog
public final int nextFromProlog(boolean isProlog) throws javax.xml.stream.XMLStreamException- Specified by:
nextFromPrologin classXmlScanner- Throws:
javax.xml.stream.XMLStreamException
-
nextFromTree
public final int nextFromTree() throws javax.xml.stream.XMLStreamException- Specified by:
nextFromTreein classXmlScanner- 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
-
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
-
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:
finishCommentin classXmlScanner- Throws:
javax.xml.stream.XMLStreamException
-
finishPI
protected final void finishPI() throws javax.xml.stream.XMLStreamException- Specified by:
finishPIin classXmlScanner- Throws:
javax.xml.stream.XMLStreamException
-
finishDTD
protected final void finishDTD(boolean copyContents) throws javax.xml.stream.XMLStreamException- Specified by:
finishDTDin classXmlScanner- Throws:
javax.xml.stream.XMLStreamException
-
finishCData
protected final void finishCData() throws javax.xml.stream.XMLStreamException- Specified by:
finishCDatain classXmlScanner- Throws:
javax.xml.stream.XMLStreamException
-
finishCharacters
protected final void finishCharacters() throws javax.xml.stream.XMLStreamException- Specified by:
finishCharactersin classXmlScanner- Throws:
javax.xml.stream.XMLStreamException
-
finishSpace
protected final void finishSpace() throws javax.xml.stream.XMLStreamException- Specified by:
finishSpacein classXmlScanner- Throws:
javax.xml.stream.XMLStreamException
-
finishCoalescedText
protected final void finishCoalescedText() throws javax.xml.stream.XMLStreamExceptionMethod 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.XMLStreamExceptionMethod 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:
skipCoalescedTextin classXmlScanner- 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:
skipCommentin classXmlScanner- Throws:
javax.xml.stream.XMLStreamException
-
skipPI
protected final void skipPI() throws javax.xml.stream.XMLStreamException- Specified by:
skipPIin classXmlScanner- Throws:
javax.xml.stream.XMLStreamException
-
skipCharacters
protected final boolean skipCharacters() throws javax.xml.stream.XMLStreamException- Specified by:
skipCharactersin classXmlScanner- 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:
skipCDatain classXmlScanner- Throws:
javax.xml.stream.XMLStreamException
-
skipSpace
protected final void skipSpace() throws javax.xml.stream.XMLStreamException- Specified by:
skipSpacein classXmlScanner- 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
-
checkInTreeIndentation
protected final int checkInTreeIndentation(char c) throws javax.xml.stream.XMLStreamExceptionNote: 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
-
getCurrentLocation
public org.codehaus.stax2.XMLStreamLocation2 getCurrentLocation()
- Specified by:
getCurrentLocationin classXmlScanner- Returns:
- Current input location
-
getCurrentColumnNr
public int getCurrentColumnNr()
- Specified by:
getCurrentColumnNrin classXmlScanner
-
getStartingByteOffset
public long getStartingByteOffset()
- Specified by:
getStartingByteOffsetin classXmlScanner
-
getStartingCharOffset
public long getStartingCharOffset()
- Specified by:
getStartingCharOffsetin classXmlScanner
-
getEndingByteOffset
public long getEndingByteOffset() throws javax.xml.stream.XMLStreamException- Specified by:
getEndingByteOffsetin classXmlScanner- Throws:
javax.xml.stream.XMLStreamException
-
getEndingCharOffset
public long getEndingCharOffset() throws javax.xml.stream.XMLStreamException- Specified by:
getEndingCharOffsetin classXmlScanner- 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:
loadMorein classXmlScanner- 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
-
-