| |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public class Parser extends Object implements DTDConstants
A simple DTD-driven HTML parser. The parser reads an HTML file from an InputStream and calls various methods (which should be overridden in a subclass) when tags and data are encountered.
Unfortunately there are many badly implemented HTML parsers out there, and as a result there are many badly formatted HTML files. This parser attempts to parse most HTML files. This means that the implementation sometimes deviates from the SGML specification in favor of HTML.
The parser treats \r and \r\n as \n. Newlines after starttags and before end tags are ignored just as specified in the SGML/HTML specification.
The html spec does not specify how spaces are to be coalesced very well. Specifically, the following scenarios are not discussed (note that a space should be used here, but I am using   to force the space to be displayed):
'<b>blah <i> <strike> foo' which can be treated as: '<b>blah <i><strike>foo'
as well as: '<p><a href="xx"> <em>Using</em></a></p>' which appears to be treated as: '<p><a href="xx"><em>Using</em></a></p>'
If strict
is false, when a tag that breaks flow,
(TagElement.breaksFlows
) or trailing whitespace is
encountered, all whitespace will be ignored until a non whitespace
character is encountered. This appears to give behavior closer to
the popular browsers.
Field Summary | |
---|---|
protected DTD |
dtd
|
protected boolean |
strict
This flag determines whether or not the Parser will be strict in enforcing SGML compatibility. |
Constructor Summary | |
---|---|
|
Method Summary | |
---|---|
protected void |
endTag(boolean omitted) Handle an end tag. |
protected void |
|
protected void |
|
protected void |
|
protected void |
Invoke the error handler. |
protected void |
|
protected SimpleAttributeSet |
|
protected int |
|
protected int |
|
protected void |
handleComment(char[] text) Called when an HTML comment is encountered. |
protected void |
handleEmptyTag(TagElement tag) Called when an empty tag is encountered. |
protected void |
handleEndTag(TagElement tag) Called when an end tag is encountered. |
protected void |
|
protected void |
handleError(int ln, String msg) An error has occurred. |
protected void |
handleStartTag(TagElement tag) Called when a start tag is encountered. |
protected void |
handleText(char[] text) Called when PCDATA is encountered. |
protected void |
handleTitle(char[] text) Called when an HTML title tag is encountered. |
protected TagElement |
|
protected TagElement |
Makes a TagElement. |
protected void |
markFirstTime(Element elem) Marks the first time a tag has been seen in a document |
void |
Parse an HTML stream, given a DTD. |
String |
Parses th Document Declaration Type markup declaration. |
protected boolean |
parseMarkupDeclarations(StringBuffer strBuff) Parse markup declarations. |
protected void |
startTag(TagElement tag) Handle a start tag. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected DTD dtd
protected boolean strict
Constructor Detail |
---|
public Parser(DTD dtd)
dtd
Method Detail |
---|
protected void endTag(boolean omitted)
omitted
protected void error(String err)
err
protected void error(String err, String arg1)
err
arg1
protected void error(String err, String arg1, String arg2)
err
arg1
arg2
protected void error(String err, String arg1, String arg2, String arg3)
err
arg1
arg2
arg3
protected void flushAttributes()
protected SimpleAttributeSet getAttributes()
protected int getCurrentLine()
protected int getCurrentPos()
protected void handleComment(char[] text)
text
protected void handleEmptyTag(TagElement tag) throws ChangedCharSetException
tag
ChangedCharSetException
protected void handleEndTag(TagElement tag)
tag
protected void handleEOFInComment()
protected void handleError(int ln, String msg)
ln
msg
protected void handleStartTag(TagElement tag)
tag
protected void handleText(char[] text)
text
protected void handleTitle(char[] text)
text
protected TagElement makeTag(Element elem)
elem
protected TagElement makeTag(Element elem, boolean fictional)
elem
fictional
protected void markFirstTime(Element elem)
elem
public synchronized void parse(Reader in) throws IOException
in
IOException
public String parseDTDMarkup() throws IOException
IOException
protected boolean parseMarkupDeclarations(StringBuffer strBuff) throws IOException
strBuff
IOException
protected void startTag(TagElement tag) throws ChangedCharSetException
tag
ChangedCharSetException
| |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |