Top Description Fields Constructors Methods
com.ctc.wstx.sr

public abstract Class StreamScanner

extends WstxInputData
implements InputProblemReporter, InputConfigFlags, ParsingErrorMsgs
Class Inheritance
All Implemented Interfaces
com.ctc.wstx.cfg.ParsingErrorMsgs, com.ctc.wstx.cfg.InputConfigFlags, com.ctc.wstx.sr.InputProblemReporter
Known Direct Subclasses
com.ctc.wstx.dtd.MinimalDTDReader, com.ctc.wstx.sr.BasicStreamReader
Imports
java.io.FileNotFoundException, .IOException, java.net.URL, java.text.MessageFormat, java.util.Collections, .HashMap, .Map, javax.xml.stream.Location, .XMLInputFactory, .XMLReporter, .XMLResolver, .XMLStreamException, org.codehaus.stax2.XMLReporter2, .XMLStreamLocation2, org.codehaus.stax2.validation.XMLValidationProblem, com.ctc.wstx.api.ReaderConfig, com.ctc.wstx.cfg.ErrorConsts, .InputConfigFlags, .ParsingErrorMsgs, .XmlConsts, com.ctc.wstx.dtd.MinimalDTDReader, com.ctc.wstx.ent.EntityDecl, .IntEntity, com.ctc.wstx.exc.*, com.ctc.wstx.io.DefaultInputResolver, .WstxInputData, .WstxInputLocation, .WstxInputSource, com.ctc.wstx.util.ExceptionUtil, .SymbolTable, .TextBuffer

Abstract base class that defines some basic functionality that all Woodstox reader classes (main XML reader, DTD reader) extend from.

Field Summary

Modifier and TypeField and Description
public static final char
CHAR_CR_LF_OR_NULL

Last (highest) char code of the three, LF, CR and NULL

protected static final char
CHAR_FIRST_PURE_TEXT

Character that allows quick check of whether a char can potentially be some kind of markup, WRT input stream processing; has to contain linefeeds, &, < and > (note: > only matters when quoting text, as part of ]]>)

public static final int
protected boolean
mAllowXml11EscapedCharsInXml10

Flag that indicates whether all escaped chars are accepted in XML 1.0.

protected Map<String, IntEntity>
mCachedEntities

Cache of internal character entities;

protected final boolean
mCfgNsEnabled

If true, Reader is namespace aware, and should do basic checks (usually enforcing limitations on having colons in names)

protected boolean
mCfgReplaceEntities

Note

left non-final on purpose: sub-class may need to modify the default value after construction.

protected boolean
mCfgTreatCharRefsAsEntities

Flag for whether or not character references should be treated as entities

protected final ReaderConfig
mConfig

Copy of the configuration object passed by the factory.

protected int
mCurrDepth

This is the current depth of the input stack (same as what input element stack would return as its depth).

protected EntityDecl
mCurrEntity

Entity reference stream currently points to.

protected String
mCurrName

Local full name for the event, if it has one (note: element events do NOT use this variable; those names are stored in element stack): target for processing instructions.

protected String
mDocInputEncoding

Input stream encoding, if known (passed in, or determined by auto-detection); null if not.

protected String
mDocXmlEncoding

Character encoding from xml declaration, if any; null if no declaration, or it didn't specify encoding.

protected int
mDocXmlVersion

XML version as declared by the document; one of constants from XmlConsts (like XmlConsts#XML_V_10).

protected int
mEntityExpansionCount

Number of times a parsed general entity has been expanded; used for (optionally) limiting number of expansion to guard against denial-of-service attacks like "Billion Laughs".

protected XMLResolver
mEntityResolver

Custom resolver used to handle external entities that are to be expanded by this reader (external param/general entity expander)

protected WstxInputSource
mInput

Currently active input source; contains link to parent (nesting) input sources, if any.

protected int
protected char[]
mNameBuffer

Temporary buffer used if local name can not be just directly constructed from input buffer (name is on a boundary or such).

protected boolean
mNormalizeLFs

Flag that indicates whether linefeeds in the input data are to be normalized or not.

protected final WstxInputSource
mRootInput

Top-most input source this reader can use; due to input source chaining, this is not necessarily the root of all input; for example, external DTD subset reader's root input still has original document input as its parent.

pack-priv final SymbolTable
protected int
mTokenInputCol

Column on input row that current token starts; 0-based (although in the end it'll be converted to 1-based)

protected int
mTokenInputRow

Input row on which current token starts, 1-based

protected long
mTokenInputTotal

Total number of characters read before start of current token.

private static final byte
private static final byte
private static final byte
private static final byte
private static final byte[]
private static final byte[]
private static final int
VALID_CHAR_COUNT

Hides com.ctc.wstx.io.WstxInputData.VALID_CHAR_COUNT.

We will only use validity array for first 256 characters, mostly because after those characters it's easier to do fairly simple block checks.
private static final int
VALID_PUBID_CHAR_COUNT

Hides com.ctc.wstx.io.WstxInputData.VALID_PUBID_CHAR_COUNT.

Public identifiers only use 7-bit ascii range.
Inherited from com.ctc.wstx.io.WstxInputData:
CHAR_NULLCHAR_SPACEINT_NULLINT_SPACEMAX_UNICODE_CHARmCurrInputProcessedmCurrInputRowmCurrInputRowStartmInputBuffermInputEndmInputPtrmXml11

Constructor Summary

AccessConstructor and Description
protected
StreamScanner(WstxInputSource input, ReaderConfig cfg, XMLResolver res)

Constructor used when creating a complete new (main-level) reader that does not share its input buffers or state with another reader.

Method Summary

Modifier and TypeMethod and Description
protected void
_reportProblem(XMLReporter rep, String probType, String msg, Location loc)

protected void
protected void
closeAllInput(boolean force)

protected WstxException
constructFromIOE(IOException ioe)

Construct and return a XMLStreamException to throw as a result of a failed Typed Access operation (but one not caused by a Well-Formedness Constraint or Validation Constraint problem)

protected XMLStreamException
constructLimitViolation(String type, long limit)

protected WstxException
protected WstxException
protected boolean

Returns:

true if there's now enough data; false if not (EOF)
ensureInput
(int minAmount)

Method called to make sure current main-level input buffer has at least specified number of characters available consequtively, without having to call loadMore.

protected final char[]
expandBy50Pct(char[] buf)

protected EntityDecl
expandEntity(String
Name of the entity being expanded
id
,
boolean
Whether external entities can be expanded or not; if not, and the entity to expand would be external one, an exception will be thrown
allowExt
,
Object extraArg)

Helper method that will try to expand a parsed entity (parameter or generic entity).

private void
expandEntity(EntityDecl
Entity to be expanded
ed
,
boolean
Whether external entities are allowed or not.
allowExt
)

Note

defined as private for documentation, ie.

private EntityDecl
expandUnresolvedEntity(String id)

Note

only called from the local expandEntity() method

protected abstract EntityDecl
findEntity(String
Identifier of the entity to find
id
,
Object
Optional argument passed from caller; needed by DTD reader.
arg
)

Abstract method for sub-classes to implement, for finding a declared general or parsed entity.

protected int

Returns:

Either single-character replacement (which is NOT to be reparsed), or null char (0) to indicate expansion is done via input source.
fullyResolveEntity
(boolean
If true, is allowed to expand external entities (expanding text); if false, is not (expanding attribute value).
allowExt
)

Method that does full resolution of an entity reference, be it character entity, internal entity or external entity, including updating of input buffers, and depending on whether result is a character entity (or one of 5 pre-defined entities), returns char in question, or null character (code 0) to indicate it had to change input source.

public ReaderConfig
public final WstxInputSource
getCurrentInput()

Returns current input source this source uses.

public XMLStreamLocation2
protected EntityDecl
getIntEntity(int ch, final char[] originalChars)

Returns an entity (possibly from cache) for the argument character using the encoded representation in mInputBuffer[entityStartPos ...

protected WstxInputLocation
getLastCharLocation()

Method that returns location of the last character returned by this reader; that is, location "one less" than the currently pointed to location.

public abstract Location
getLocation()

Redeclares com.ctc.wstx.sr.InputProblemReporter.getLocation.

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).

protected final char[]
getNameBuffer(int minSize)

protected final int
protected final int
getNextAfterWS()

Method that will skip through zero or more white space characters, and return either the character following white space, or -1 to indicate EOF (end of the outermost input source)/

protected final char
getNextChar(String errorMsg)

protected final char
protected final char
getNextCharFromCurrent(String errorMsg)

Similar to getNextChar, but will not read more characters from parent input source(s) if the current input source doesn't have more content.

protected final char
protected final char
getNextInCurrAfterWS(String errorMsg, char c)

protected URL
public XMLStreamLocation2
protected String
protected abstract void
protected abstract void
handleUndeclaredEntity(String id)

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).

protected void
initInputSource(WstxInputSource newInput, boolean isExt, String
Name of the entity being expanded
entityId
)

Method called when an entity has been expanded (new input source has been created).

protected final int
protected boolean

Returns:

true if reading succeeded (or may succeed), false if we reached EOF.
loadMore
()

Method that will try to read one or more characters from currently open input sources; closing input sources if necessary.

protected final boolean
loadMore(String errorMsg)

protected boolean
protected final boolean
protected final void
protected final void
markLF(int inputPtr)

protected final String
protected String
parseFNameForError()

Method called to read in full name, including unlimited number of namespace separators (':'), for the purpose of displaying name in an error message.

protected String

Returns:

Canonicalized name String (which may have length 0, if EOF or non-name-start char encountered)
parseFullName
()

Method that will parse 'full' name token; what full means depends on whether reader is namespace aware or not.

protected String
parseFullName(char c)

protected String
parseFullName2(int start, int hash)

protected String

Returns:

Canonicalized name String (which may have length 0, if EOF or non-name-start char encountered)
parseLocalName
(char
First character of the name; not yet checked for validity
c
)

Method that will parse name token (roughly equivalent to XML specs; although bit lenier for more efficient handling); either uri prefix, or local name.

protected String
parseLocalName2(int start, int hash)

Second part of name token parsing; called when name can continue past input buffer end (so only part was read before calling this method to read the rest).

protected final String
parsePublicId(char quoteChar, String errorMsg)

Simple parsing method that parses system ids, which are generally used in entities (from DOCTYPE declaration to internal/external subsets).

protected final String
parseSystemId(char quoteChar, boolean convertLFs, String errorMsg)

Simple parsing method that parses system ids, which are generally used in entities (from DOCTYPE declaration to internal/external subsets).

protected final void
parseUntil(TextBuffer tb, char endChar, boolean convertLFs, String errorMsg)

protected final int
peekNext()

Similar to getNext, but does not advance pointer in input buffer.

protected final void
pushback()

Method to push back last character read; can only be called once, that is, no more than one char can be guaranteed to be succesfully returned.

private void
reportIllegalChar(int value)

public void
reportProblem(String probType, String format, Object arg, Object arg2)

public void
private void
public void
reportValidationProblem(XMLValidationProblem prob)

Implements com.ctc.wstx.sr.InputProblemReporter.reportValidationProblem.

Note

this is the base implementation used for implementing ValidationContext

public void
reportValidationProblem(String msg, int severity)

public void
public void
public void
private int
resolveCharEnt(StringBuffer originalCharacters)

protected int

Returns:

(Valid) character value, if entity is a character reference, and could be resolved from current input buffer (does not span buffer boundary); null char (code 0) if not (either non-char entity, or spans input buffer boundary).
resolveCharOnlyEntity
(boolean
If true, will check pre-defined internal entities (gt, lt, amp, apos, quot) as character entities; if false, will only check actual 'real' character entities.
checkStd
)

Method called to resolve character entities, and only character entities (except that pre-defined char entities -- amp, apos, lt, gt, quote -- MAY be "char entities" in this sense, depending on arguments).

protected EntityDecl
resolveNonCharEntity()

Reverse of resolveCharOnlyEntity; will only resolve entity if it is NOT a character entity (or pre-defined 'generic' entity; amp, apos, lt, gt or quot).

protected int

Returns:

(Valid) character value, if entity is a character reference, and could be resolved from current input buffer (does not span buffer boundary); null char (code 0) if not (either non-char entity, or spans input buffer boundary).
resolveSimpleEntity
(boolean
If true, will check pre-defined internal entities (gt, lt, amp, apos, quot); if false, will only check actual character entities.
checkStd
)

Method that tries to resolve a character entity, or (if caller so specifies), a pre-defined internal entity (lt, gt, amp, apos, quot).

protected final boolean

Returns:

True, if passed in char is '\r' and next one is '\n'.
skipCRLF
(char c)

Method called when a CR has been spotted in input; checks if next char is LF, and if so, skips it.

protected int

Returns:

Length of skipped name.
skipFullName
(char c)

Note

does not check for number of colons, amongst other things.

protected void
protected void
protected void
protected WstxException
throwInvalidSpace(int i, boolean deferErrors)

protected void
throwLazyError(Exception e)

Method called to report an error, when caller's signature only allows runtime exceptions to be thrown.

private void
throwNsColonException(String name)

Method called to throw an exception indicating that a name that should not be namespace-qualified (PI target, entity/notation name) is one, and reader is namespace aware.

protected void
protected void
throwNullParent(WstxInputSource
Input source currently in use
curr
)

public void
public void
throwParseError(String format, Object arg, Object arg2)

Implements com.ctc.wstx.sr.InputProblemReporter.throwParseError.

Throws generic parse error with specified message and current parsing location.

private void
protected void
protected void
throwUnexpectedEOB(String msg)

Similar to throwUnexpectedEOF, but only indicates ending of an input block.

protected void
public WstxException
throwWfcException(String msg, boolean deferErrors)

protected String
tokenTypeDesc(int type)

private final void
validateChar(int value)

Method that will verify that expanded Unicode codepoint is a valid XML content character.

protected void
verifyLimit(String type, long maxValue, long currentValue)

Inherited from com.ctc.wstx.io.WstxInputData:
copyBufferStateFromfindIllegalNameCharfindIllegalNmtokenChargetCharDescisNameCharisNameCharisNameStartCharisNameStartCharisSpaceChar