This documentation differs from the official API. Jadeite adds extra features to the API including: variable font sizes, constructions examples, placeholders for classes and methods, and auto-generated “See Also” links. Additionally it is missing some items found in standard Javadoc documentation, including: generics type information, “Deprecated” tags and comments, “See Also” links, along with other minor differences. Please send any questions or feedback to bam@cs.cmu.edu.


javax.swing.text.html.parser
class Parser

java.lang.Object extended by javax.swing.text.html.parser.Parser
All Implemented Interfaces:
DTDConstants
Direct Known Subclasses:
DocumentParser

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 &nbsp 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
Parser(DTD dtd)

          
 
Method Summary
protected void
endTag(boolean omitted)

          Handle an end tag.
protected void

          
protected void
error(String err, String arg1)

          
protected void
error(String err, String arg1, String arg2)

          
protected void
error(String err, String arg1, String arg2, String arg3)

          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

          Called when an empty tag is encountered.
protected void

          Called when an end tag is encountered.
protected void

          
protected void
handleError(int ln, String msg)

          An error has occurred.
protected void

          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
makeTag(Element elem, boolean fictional)

          Makes a TagElement.
protected void

          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

          Parse markup declarations.
protected void

          Handle a start tag.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dtd

protected DTD dtd

strict

protected boolean strict
This flag determines whether or not the Parser will be strict in enforcing SGML compatibility. If false, it will be lenient with certain common classes of erroneous HTML constructs. Strict or not, in either case an error will be recorded.
Constructor Detail

Parser

public Parser(DTD dtd)
Parameters:
dtd
Method Detail

endTag

protected void endTag(boolean omitted)
Handle an end tag. The end tag is popped from the tag stack.

Parameters:
omitted

error

protected void error(String err)
Parameters:
err

error

protected void error(String err,
                     String arg1)
Parameters:
err
arg1

error

protected void error(String err,
                     String arg1,
                     String arg2)
Parameters:
err
arg1
arg2

error

protected void error(String err,
                     String arg1,
                     String arg2,
                     String arg3)
Invoke the error handler.

Parameters:
err
arg1
arg2
arg3

flushAttributes

protected void flushAttributes()

getAttributes

protected SimpleAttributeSet getAttributes()

getCurrentLine

protected int getCurrentLine()
Returns:
the line number of the line currently being parsed

getCurrentPos

protected int getCurrentPos()

handleComment

protected void handleComment(char[] text)
Called when an HTML comment is encountered.

Parameters:
text

handleEmptyTag

protected void handleEmptyTag(TagElement tag)
                       throws ChangedCharSetException
Called when an empty tag is encountered.

Parameters:
tag
Throws:
ChangedCharSetException

handleEndTag

protected void handleEndTag(TagElement tag)
Called when an end tag is encountered.

Parameters:
tag

handleEOFInComment

protected void handleEOFInComment()

handleError

protected void handleError(int ln,
                           String msg)
An error has occurred.

Parameters:
ln
msg

handleStartTag

protected void handleStartTag(TagElement tag)
Called when a start tag is encountered.

Parameters:
tag

handleText

protected void handleText(char[] text)
Called when PCDATA is encountered.

Parameters:
text

handleTitle

protected void handleTitle(char[] text)
Called when an HTML title tag is encountered.

Parameters:
text

makeTag

protected TagElement makeTag(Element elem)
Parameters:
elem

makeTag

protected TagElement makeTag(Element elem,
                             boolean fictional)
Makes a TagElement.

Parameters:
elem
fictional

markFirstTime

protected void markFirstTime(Element elem)
Marks the first time a tag has been seen in a document

Parameters:
elem

parse

public synchronized void parse(Reader in)
                        throws IOException
Parse an HTML stream, given a DTD.

Parameters:
in
Throws:
IOException

parseDTDMarkup

public String parseDTDMarkup()
                      throws IOException
Parses th Document Declaration Type markup declaration. Currently ignores it.

Throws:
IOException

parseMarkupDeclarations

protected boolean parseMarkupDeclarations(StringBuffer strBuff)
                                   throws IOException
Parse markup declarations. Currently only handles the Document Type Declaration markup. Returns true if it is a markup declaration false otherwise.

Parameters:
strBuff
Throws:
IOException

startTag

protected void startTag(TagElement tag)
                 throws ChangedCharSetException
Handle a start tag. The new tag is pushed onto the tag stack. The attribute list is checked for required attributes.

Parameters:
tag
Throws:
ChangedCharSetException


This documentation differs from the official API. Jadeite adds extra features to the API including: variable font sizes, constructions examples, placeholders for classes and methods, and auto-generated “See Also” links. Additionally it is missing some items found in standard Javadoc documentation, including: generics type information, “Deprecated” tags and comments, “See Also” links, along with other minor differences. Please send any questions or feedback to bam@cs.cmu.edu.
This page displays the Jadeite version of the documention, which is derived from the offical documentation that contains this copyright notice:
Copyright 2008 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.
The official Sun™ documentation can be found here at http://java.sun.com/javase/6/docs/api/.