public abstract class BasicReader extends Logging implements java.io.Closeable
BasicReader implements the internal Logging interface for reporting the context of errors, and manages the underlying BasicScanner, and the Lexicon used by its descendants. The BasicScanner serves up the stream of tokens to all subclasses. The Lexicon defines the mapping from XML entity references to escaped characters or abbreviated boilerplate text. A DTDReader may add extra entity reference definitions to the Lexicon, before handing this back to an XMLReader or ASTReader. BasicReader implements the Closeable interface, so may be used in try-with-resources blocks (since JDK 1.7).
Modifier and Type | Field and Description |
---|---|
protected int |
lastToken
The lookahead token last read from the Scanner.
|
protected Lexicon |
lexicon
The lexicon used by this BasicReader to decode entity references.
|
protected BasicScanner |
scanner
The scanner used by this BasicReader to scan the input data.
|
protected Validation |
validation
An enumerated type describing the level of automatic validation to
perform.
|
Modifier | Constructor and Description |
---|---|
protected |
BasicReader(BasicScanner scanner)
Creates a BasicReader reading tokens from a BasicScanner created by
the subclass.
|
protected |
BasicReader(BasicScanner scanner,
Lexicon lexicon)
Creates a BasicReader reading tokens from a BasicScanner created by
the subclass, and using a given Lexicon to decode entity references.
|
Modifier and Type | Method and Description |
---|---|
protected void |
checkEncoding(java.lang.String declared,
java.lang.String actual)
Checks that the declared character encoding matches the actual
character encoding used to decode the XML file.
|
void |
close()
Closes this BasicReader reader.
|
protected boolean |
endOfStream()
Secretly reports whether the end of the input stream has been reached.
|
protected java.lang.String |
getContext()
Reports the XML document context in which an error was detected.
|
java.lang.String |
getEncoding()
Reports the character encoding used by this BasicReader.
|
Lexicon |
getLexicon()
Returns the Lexicon used by this BasicReader for decoding escaped
characters and boilerplate text.
|
protected int |
getLineNumber()
Reports the current line number reached by this BasicReader.
|
protected java.lang.String |
parseQuotedValue()
Parses the quoted value of an XML attribute.
|
void |
setLexicon(Lexicon lexicon)
Replaces the Lexicon used by this BasicReader for decoding escaped
characters and boilerplate text.
|
void |
setValidation(Validation validation)
Sets the level of automatic validation performed by XML/AST readers.
|
encodingError, semanticError, syntaxError
protected BasicScanner scanner
protected Lexicon lexicon
protected Validation validation
protected int lastToken
protected BasicReader(BasicScanner scanner, Lexicon lexicon)
scanner
- the BasicScanner.lexicon
- the Lexicon.protected BasicReader(BasicScanner scanner)
scanner
- the BasicScanner.public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
java.io.IOException
- if an I/O fault occurs during closing.public java.lang.String getEncoding()
protected void checkEncoding(java.lang.String declared, java.lang.String actual) throws java.io.UnsupportedEncodingException
declared
- the character encoding in the XML declaration.actual
- the character encoding used by the parser.java.io.UnsupportedEncodingException
- if the encodings don't match.protected int getLineNumber()
getLineNumber
in class Logging
protected java.lang.String getContext()
getContext
in class Logging
protected boolean endOfStream()
endOfStream
in class Logging
public void setValidation(Validation validation)
validation
- one of: IGNORE, EXPAND, DOCTYPE, SCHEMA.public Lexicon getLexicon()
public void setLexicon(Lexicon lexicon)
lexicon
- the Lexicon to use instead.protected java.lang.String parseQuotedValue() throws java.io.IOException, SyntaxError
java.io.IOException
- if the token stream fails.SyntaxError
- if the XML syntax is faulty.