This class is designed to be extended for use. You use it in
this way:
1. instantiate the object, passing an inputStream to the
constructor (a string can be passed as well).
2. call parse() to start it running. Parse will return
when the eof of file is reached.
3. during the parse, each of the following calls will
be made. The extensions should handle the calls as
necessary:
flush Called for each contiguous block
of text.
tag Called for each complete tag
pi Called for each PI (non-xml) recognized
doctype Called for a doctype
comment Called for each complete comment
errorString Called for each parse error
4. As an extension &xxx; macros can be implemented. For
each unrecognized &xxx; macro, a call to
documentAttribute is made that will return a string if
the macro name has a value.
callFlush
protected void callFlush(char[] buf,
int offset,
int length)
Invokes flush(). This method is provided so that flush() can
be protected
comment
protected abstract void comment(String s)
This method inserts a comment
It should be overridden by the subclass
commentEOFError
protected void commentEOFError(int resetTo)
doctype
protected abstract void doctype(String root,
String publicId,
String systemId)
This method emits a doctype. Internal subset information is discarded
It should be overridden by the subclass
documentAttribute
protected abstract String documentAttribute(String name)
This method looks up a &xxx; sequence in the document
properties (this is used for templates). A return of null
means the proerty is undefined.
It should be overridden by the subclass
eofError
protected void eofError()
errorString
protected abstract void errorString(String s)
This method inserts a parse error string into the document
It should be overridden by the subclass
findCloseAngleForComment
protected void findCloseAngleForComment(char c)
throws IOException
flush
protected abstract void flush(char[] buf,
int offset,
int length)
This method creates a block of text for a document.
It should be overridden by the subclass
generateError
protected void generateError(int offset)
getDocumentSource
public String getDocumentSource()
handleCommentOrDoctype
protected char handleCommentOrDoctype(char c)
throws IOException
initEntities
protected void initEntities()
parse
public void parse()
throws IOException
parseEscape
protected char parseEscape()
throws IOException
parseTag
protected char parseTag()
throws IOException
parseText
public void parseText()
throws IOException
pi
protected abstract void pi(String target,
String data)
This method emits a pi
It should be overridden by the subclass
readChar
protected char readChar()
throws IOException
scanIdentifier
protected char scanIdentifier(char c)
throws IOException
scanQuotedString
protected char scanQuotedString(char c)
throws IOException
setInput
public void setInput(InputStream i,
String encoding)
throws UnsupportedEncodingException
setInput
public void setInput(Reader src)
setShouldCacheSource
public void setShouldCacheSource(boolean state)
skipToCloseAngle
protected void skipToCloseAngle(char c)
throws IOException
This method is called when parsing a tag and an error is
encountered. It skips to the closing angle bracket,
treating the entire tag as error text. The generateError
call at the end stuffs the full tag into the document
as an error.
skipWhite
protected char skipWhite(char c)
throws IOException
tag
protected abstract void tag(String name,
TagProperties atts,
boolean endTag,
boolean emptyTag)
This method emits a tag
It should be overridden by the subclass