Spec-Zone .ru
спецификации, руководства, описания, API
JavaTM 2 Platform
Std. Ed. v1.3.1

javax.swing.text.html.parser
Class Parser

java.lang.Object
  |
  +--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.

See Also:
DTD, TagElement, SimpleAttributeSet

Field Summary
protected  DTD dtd
           
protected  boolean strict
          This flag determines whether or not the Parser will be strict in enforcing SGML compatibility.
 
Fields inherited from interface javax.swing.text.html.parser.DTDConstants
ANY, CDATA, CONREF, CURRENT, DEFAULT, EMPTY, ENDTAG, ENTITIES, ENTITY, FIXED, GENERAL, ID, IDREF, IDREFS, IMPLIED, MD, MODEL, MS, NAME, NAMES, NMTOKEN, NMTOKENS, NOTATION, NUMBER, NUMBERS, NUTOKEN, NUTOKENS, PARAMETER, PI, PUBLIC, RCDATA, REQUIRED, SDATA, STARTTAG, SYSTEM
 
Constructor Summary
Parser(DTD dtd)
           
 
Method Summary
protected  void endTag(boolean omitted)
          Handle an end tag.
protected  void error(String err)
           
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 flushAttributes()
           
protected  SimpleAttributeSet getAttributes()
           
protected  int getCurrentLine()
           
protected  int getCurrentPos()
           
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 handleEOFInComment()
           
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 makeTag(Element elem)
           
protected  TagElement makeTag(Element elem, boolean fictional)
          Makes a TagElement.
protected  void markFirstTime(Element elem)
          Marks the first time a tag has been seen in a document
 void parse(Reader in)
          Parse an HTML stream, given a DTD.
 String parseDTDMarkup()
          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

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)
Method Detail

getCurrentLine

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

makeTag

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

makeTag

protected TagElement makeTag(Element elem)

getAttributes

protected SimpleAttributeSet getAttributes()

flushAttributes

protected void flushAttributes()

handleText

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

handleTitle

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

handleComment

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

handleEOFInComment

protected void handleEOFInComment()

handleEmptyTag

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

handleStartTag

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

handleEndTag

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

handleError

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

error

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

error

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

error

protected void error(String err,
                     String arg1)

error

protected void error(String err)

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.

endTag

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

markFirstTime

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

parseDTDMarkup

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

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.

parse

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

getCurrentPos

protected int getCurrentPos()

JavaTM 2 Platform
Std. Ed. v1.3.1

Submit a bug or feature
For further API reference and developer documentation, see Java 2 SDK SE Developer Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.

Java, Java 2D, and JDBC are trademarks or registered trademarks of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-2001 Sun Microsystems, Inc. 901 San Antonio Road
Palo Alto, California, 94303, U.S.A. All Rights Reserved.

free hit counter