javax.swing.text.html.parser
Class DocumentParser

java.lang.Object sample code for java.lang.Object definition code for java.lang.Object 
  extended by javax.swing.text.html.parser.Parser sample code for javax.swing.text.html.parser.Parser definition code for javax.swing.text.html.parser.Parser 
      extended by javax.swing.text.html.parser.DocumentParser
All Implemented Interfaces:
DTDConstants sample code for javax.swing.text.html.parser.DTDConstants definition code for javax.swing.text.html.parser.DTDConstants

public class DocumentParser
extends Parser sample code for javax.swing.text.html.parser.Parser definition code for javax.swing.text.html.parser.Parser

A Parser for HTML Documents (actually, you can specify a DTD, but you should really only use this class with the html dtd in swing). Reads an InputStream of HTML and invokes the appropriate methods in the ParserCallback class. This is the default parser used by HTMLEditorKit to parse HTML url's.

This will message the callback for all valid tags, as well as tags that are implied but not explicitly specified. For example, the html string (<p>blah) only has a p tag defined. The callback will see the following methods:

  1. handleStartTag(html, ...)
  2. handleStartTag(head, ...)
  3. handleEndTag(head)
  4. handleStartTag(body, ...)
  5. handleStartTag(p, ...)
  6. handleText(...)
  7. handleEndTag(p)
  8. handleEndTag(body)
  9. handleEndTag(html)
The items in italic are implied, that is, although they were not explicitly specified, to be correct html they should have been present (head isn't necessary, but it is still generated). For tags that are implied, the AttributeSet argument will have a value of Boolean.TRUE for the key HTMLEditorKit.ParserCallback.IMPLIED.

HTML.Attributes defines a type safe enumeration of html attributes. If an attribute key of a tag is defined in HTML.Attribute, the HTML.Attribute will be used as the key, otherwise a String will be used. For example <p foo=bar class=neat> has two attributes. foo is not defined in HTML.Attribute, where as class is, therefore the AttributeSet will have two values in it, HTML.Attribute.CLASS with a String value of 'neat' and the String key 'foo' with a String value of 'bar'.

The position argument will indicate the start of the tag, comment or text. Similiar to arrays, the first character in the stream has a position of 0. For tags that are implied the position will indicate the location of the next encountered tag. In the first example, the implied start body and html tags will have the same position as the p tag, and the implied end p, html and body tags will all have the same position.

As html skips whitespace the position for text will be the position of the first valid character, eg in the string '\n\n\nblah' the text 'blah' will have a position of 3, the newlines are skipped.

For attributes that do not have a value, eg in the html string <foo blah> the attribute blah does not have a value, there are two possible values that will be placed in the AttributeSet's value:

Once the stream has been parsed, the callback is notified of the most likely end of line string. The end of line string will be one of \n, \r or \r\n, which ever is encountered the most in parsing the stream.


Field Summary
 
Fields inherited from class javax.swing.text.html.parser.Parser sample code for javax.swing.text.html.parser.Parser definition code for javax.swing.text.html.parser.Parser
dtd sample code for javax.swing.text.html.parser.Parser.dtd definition code for javax.swing.text.html.parser.Parser.dtd , strict sample code for javax.swing.text.html.parser.Parser.strict definition code for javax.swing.text.html.parser.Parser.strict
 
Fields inherited from interface javax.swing.text.html.parser.DTDConstants sample code for javax.swing.text.html.parser.DTDConstants definition code for javax.swing.text.html.parser.DTDConstants
ANY sample code for javax.swing.text.html.parser.DTDConstants.ANY definition code for javax.swing.text.html.parser.DTDConstants.ANY , CDATA sample code for javax.swing.text.html.parser.DTDConstants.CDATA definition code for javax.swing.text.html.parser.DTDConstants.CDATA , CONREF sample code for javax.swing.text.html.parser.DTDConstants.CONREF definition code for javax.swing.text.html.parser.DTDConstants.CONREF , CURRENT sample code for javax.swing.text.html.parser.DTDConstants.CURRENT definition code for javax.swing.text.html.parser.DTDConstants.CURRENT , DEFAULT sample code for javax.swing.text.html.parser.DTDConstants.DEFAULT definition code for javax.swing.text.html.parser.DTDConstants.DEFAULT , EMPTY sample code for javax.swing.text.html.parser.DTDConstants.EMPTY definition code for javax.swing.text.html.parser.DTDConstants.EMPTY , ENDTAG sample code for javax.swing.text.html.parser.DTDConstants.ENDTAG definition code for javax.swing.text.html.parser.DTDConstants.ENDTAG , ENTITIES sample code for javax.swing.text.html.parser.DTDConstants.ENTITIES definition code for javax.swing.text.html.parser.DTDConstants.ENTITIES , ENTITY sample code for javax.swing.text.html.parser.DTDConstants.ENTITY definition code for javax.swing.text.html.parser.DTDConstants.ENTITY , FIXED sample code for javax.swing.text.html.parser.DTDConstants.FIXED definition code for javax.swing.text.html.parser.DTDConstants.FIXED , GENERAL sample code for javax.swing.text.html.parser.DTDConstants.GENERAL definition code for javax.swing.text.html.parser.DTDConstants.GENERAL , ID sample code for javax.swing.text.html.parser.DTDConstants.ID definition code for javax.swing.text.html.parser.DTDConstants.ID , IDREF sample code for javax.swing.text.html.parser.DTDConstants.IDREF definition code for javax.swing.text.html.parser.DTDConstants.IDREF , IDREFS sample code for javax.swing.text.html.parser.DTDConstants.IDREFS definition code for javax.swing.text.html.parser.DTDConstants.IDREFS , IMPLIED sample code for javax.swing.text.html.parser.DTDConstants.IMPLIED definition code for javax.swing.text.html.parser.DTDConstants.IMPLIED , MD sample code for javax.swing.text.html.parser.DTDConstants.MD definition code for javax.swing.text.html.parser.DTDConstants.MD , MODEL sample code for javax.swing.text.html.parser.DTDConstants.MODEL definition code for javax.swing.text.html.parser.DTDConstants.MODEL , MS sample code for javax.swing.text.html.parser.DTDConstants.MS definition code for javax.swing.text.html.parser.DTDConstants.MS , NAME sample code for javax.swing.text.html.parser.DTDConstants.NAME definition code for javax.swing.text.html.parser.DTDConstants.NAME , NAMES sample code for javax.swing.text.html.parser.DTDConstants.NAMES definition code for javax.swing.text.html.parser.DTDConstants.NAMES , NMTOKEN sample code for javax.swing.text.html.parser.DTDConstants.NMTOKEN definition code for javax.swing.text.html.parser.DTDConstants.NMTOKEN , NMTOKENS sample code for javax.swing.text.html.parser.DTDConstants.NMTOKENS definition code for javax.swing.text.html.parser.DTDConstants.NMTOKENS , NOTATION sample code for javax.swing.text.html.parser.DTDConstants.NOTATION definition code for javax.swing.text.html.parser.DTDConstants.NOTATION , NUMBER sample code for javax.swing.text.html.parser.DTDConstants.NUMBER definition code for javax.swing.text.html.parser.DTDConstants.NUMBER , NUMBERS sample code for javax.swing.text.html.parser.DTDConstants.NUMBERS definition code for javax.swing.text.html.parser.DTDConstants.NUMBERS , NUTOKEN sample code for javax.swing.text.html.parser.DTDConstants.NUTOKEN definition code for javax.swing.text.html.parser.DTDConstants.NUTOKEN , NUTOKENS sample code for javax.swing.text.html.parser.DTDConstants.NUTOKENS definition code for javax.swing.text.html.parser.DTDConstants.NUTOKENS , PARAMETER sample code for javax.swing.text.html.parser.DTDConstants.PARAMETER definition code for javax.swing.text.html.parser.DTDConstants.PARAMETER , PI sample code for javax.swing.text.html.parser.DTDConstants.PI definition code for javax.swing.text.html.parser.DTDConstants.PI , PUBLIC sample code for javax.swing.text.html.parser.DTDConstants.PUBLIC definition code for javax.swing.text.html.parser.DTDConstants.PUBLIC , RCDATA sample code for javax.swing.text.html.parser.DTDConstants.RCDATA definition code for javax.swing.text.html.parser.DTDConstants.RCDATA , REQUIRED sample code for javax.swing.text.html.parser.DTDConstants.REQUIRED definition code for javax.swing.text.html.parser.DTDConstants.REQUIRED , SDATA sample code for javax.swing.text.html.parser.DTDConstants.SDATA definition code for javax.swing.text.html.parser.DTDConstants.SDATA , STARTTAG sample code for javax.swing.text.html.parser.DTDConstants.STARTTAG definition code for javax.swing.text.html.parser.DTDConstants.STARTTAG , SYSTEM sample code for javax.swing.text.html.parser.DTDConstants.SYSTEM definition code for javax.swing.text.html.parser.DTDConstants.SYSTEM
 
Constructor Summary
DocumentParser sample code for javax.swing.text.html.parser.DocumentParser.DocumentParser(javax.swing.text.html.parser.DTD) definition code for javax.swing.text.html.parser.DocumentParser.DocumentParser(javax.swing.text.html.parser.DTD) (DTD sample code for javax.swing.text.html.parser.DTD definition code for javax.swing.text.html.parser.DTD  dtd)
           
 
Method Summary
protected  void handleComment sample code for javax.swing.text.html.parser.DocumentParser.handleComment(char[]) definition code for javax.swing.text.html.parser.DocumentParser.handleComment(char[]) (char[] text)
          Called when an HTML comment is encountered.
protected  void handleEmptyTag sample code for javax.swing.text.html.parser.DocumentParser.handleEmptyTag(javax.swing.text.html.parser.TagElement) definition code for javax.swing.text.html.parser.DocumentParser.handleEmptyTag(javax.swing.text.html.parser.TagElement) (TagElement sample code for javax.swing.text.html.parser.TagElement definition code for javax.swing.text.html.parser.TagElement  tag)
          Handle Empty Tag.
protected  void handleEndTag sample code for javax.swing.text.html.parser.DocumentParser.handleEndTag(javax.swing.text.html.parser.TagElement) definition code for javax.swing.text.html.parser.DocumentParser.handleEndTag(javax.swing.text.html.parser.TagElement) (TagElement sample code for javax.swing.text.html.parser.TagElement definition code for javax.swing.text.html.parser.TagElement  tag)
          Handle End Tag.
protected  void handleError sample code for javax.swing.text.html.parser.DocumentParser.handleError(int, java.lang.String) definition code for javax.swing.text.html.parser.DocumentParser.handleError(int, java.lang.String) (int ln, String sample code for java.lang.String definition code for java.lang.String  errorMsg)
          An error has occurred.
protected  void handleStartTag sample code for javax.swing.text.html.parser.DocumentParser.handleStartTag(javax.swing.text.html.parser.TagElement) definition code for javax.swing.text.html.parser.DocumentParser.handleStartTag(javax.swing.text.html.parser.TagElement) (TagElement sample code for javax.swing.text.html.parser.TagElement definition code for javax.swing.text.html.parser.TagElement  tag)
          Handle Start Tag.
protected  void handleText sample code for javax.swing.text.html.parser.DocumentParser.handleText(char[]) definition code for javax.swing.text.html.parser.DocumentParser.handleText(char[]) (char[] data)
          Handle Text.
 void parse sample code for javax.swing.text.html.parser.DocumentParser.parse(java.io.Reader, javax.swing.text.html.HTMLEditorKit.ParserCallback, boolean) definition code for javax.swing.text.html.parser.DocumentParser.parse(java.io.Reader, javax.swing.text.html.HTMLEditorKit.ParserCallback, boolean) (Reader sample code for java.io.Reader definition code for java.io.Reader  in, HTMLEditorKit.ParserCallback sample code for javax.swing.text.html.HTMLEditorKit.ParserCallback definition code for javax.swing.text.html.HTMLEditorKit.ParserCallback  callback, boolean ignoreCharSet)
           
 
Methods inherited from class javax.swing.text.html.parser.Parser sample code for javax.swing.text.html.parser.Parser definition code for javax.swing.text.html.parser.Parser
endTag sample code for javax.swing.text.html.parser.Parser.endTag(boolean) definition code for javax.swing.text.html.parser.Parser.endTag(boolean) , error sample code for javax.swing.text.html.parser.Parser.error(java.lang.String) definition code for javax.swing.text.html.parser.Parser.error(java.lang.String) , error sample code for javax.swing.text.html.parser.Parser.error(java.lang.String, java.lang.String) definition code for javax.swing.text.html.parser.Parser.error(java.lang.String, java.lang.String) , error sample code for javax.swing.text.html.parser.Parser.error(java.lang.String, java.lang.String, java.lang.String) definition code for javax.swing.text.html.parser.Parser.error(java.lang.String, java.lang.String, java.lang.String) , error sample code for javax.swing.text.html.parser.Parser.error(java.lang.String, java.lang.String, java.lang.String, java.lang.String) definition code for javax.swing.text.html.parser.Parser.error(java.lang.String, java.lang.String, java.lang.String, java.lang.String) , flushAttributes sample code for javax.swing.text.html.parser.Parser.flushAttributes() definition code for javax.swing.text.html.parser.Parser.flushAttributes() , getAttributes sample code for javax.swing.text.html.parser.Parser.getAttributes() definition code for javax.swing.text.html.parser.Parser.getAttributes() , getCurrentLine sample code for javax.swing.text.html.parser.Parser.getCurrentLine() definition code for javax.swing.text.html.parser.Parser.getCurrentLine() , getCurrentPos sample code for javax.swing.text.html.parser.Parser.getCurrentPos() definition code for javax.swing.text.html.parser.Parser.getCurrentPos() , handleEOFInComment sample code for javax.swing.text.html.parser.Parser.handleEOFInComment() definition code for javax.swing.text.html.parser.Parser.handleEOFInComment() , handleTitle sample code for javax.swing.text.html.parser.Parser.handleTitle(char[]) definition code for javax.swing.text.html.parser.Parser.handleTitle(char[]) , makeTag sample code for javax.swing.text.html.parser.Parser.makeTag(javax.swing.text.html.parser.Element) definition code for javax.swing.text.html.parser.Parser.makeTag(javax.swing.text.html.parser.Element) , makeTag sample code for javax.swing.text.html.parser.Parser.makeTag(javax.swing.text.html.parser.Element, boolean) definition code for javax.swing.text.html.parser.Parser.makeTag(javax.swing.text.html.parser.Element, boolean) , markFirstTime sample code for javax.swing.text.html.parser.Parser.markFirstTime(javax.swing.text.html.parser.Element) definition code for javax.swing.text.html.parser.Parser.markFirstTime(javax.swing.text.html.parser.Element) , parse sample code for javax.swing.text.html.parser.Parser.parse(java.io.Reader) definition code for javax.swing.text.html.parser.Parser.parse(java.io.Reader) , parseDTDMarkup sample code for javax.swing.text.html.parser.Parser.parseDTDMarkup() definition code for javax.swing.text.html.parser.Parser.parseDTDMarkup() , parseMarkupDeclarations sample code for javax.swing.text.html.parser.Parser.parseMarkupDeclarations(java.lang.StringBuffer) definition code for javax.swing.text.html.parser.Parser.parseMarkupDeclarations(java.lang.StringBuffer) , startTag sample code for javax.swing.text.html.parser.Parser.startTag(javax.swing.text.html.parser.TagElement) definition code for javax.swing.text.html.parser.Parser.startTag(javax.swing.text.html.parser.TagElement)
 
Methods inherited from class java.lang.Object sample code for java.lang.Object definition code for java.lang.Object
clone sample code for java.lang.Object.clone() definition code for java.lang.Object.clone() , equals sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) , finalize sample code for java.lang.Object.finalize() definition code for java.lang.Object.finalize() , getClass sample code for java.lang.Object.getClass() definition code for java.lang.Object.getClass() , hashCode sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode() , notify sample code for java.lang.Object.notify() definition code for java.lang.Object.notify() , notifyAll sample code for java.lang.Object.notifyAll() definition code for java.lang.Object.notifyAll() , toString sample code for java.lang.Object.toString() definition code for java.lang.Object.toString() , wait sample code for java.lang.Object.wait() definition code for java.lang.Object.wait() , wait sample code for java.lang.Object.wait(long) definition code for java.lang.Object.wait(long) , wait sample code for java.lang.Object.wait(long, int) definition code for java.lang.Object.wait(long, int)
 

Constructor Detail

DocumentParser sample code for javax.swing.text.html.parser.DocumentParser(javax.swing.text.html.parser.DTD) definition code for javax.swing.text.html.parser.DocumentParser(javax.swing.text.html.parser.DTD)

public DocumentParser(DTD sample code for javax.swing.text.html.parser.DTD definition code for javax.swing.text.html.parser.DTD  dtd)
Method Detail

parse sample code for javax.swing.text.html.parser.DocumentParser.parse(java.io.Reader, javax.swing.text.html.HTMLEditorKit.ParserCallback, boolean) definition code for javax.swing.text.html.parser.DocumentParser.parse(java.io.Reader, javax.swing.text.html.HTMLEditorKit.ParserCallback, boolean)

public void parse(Reader sample code for java.io.Reader definition code for java.io.Reader  in,
                  HTMLEditorKit.ParserCallback sample code for javax.swing.text.html.HTMLEditorKit.ParserCallback definition code for javax.swing.text.html.HTMLEditorKit.ParserCallback  callback,
                  boolean ignoreCharSet)
           throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Throws:
IOException sample code for java.io.IOException definition code for java.io.IOException

handleStartTag sample code for javax.swing.text.html.parser.DocumentParser.handleStartTag(javax.swing.text.html.parser.TagElement) definition code for javax.swing.text.html.parser.DocumentParser.handleStartTag(javax.swing.text.html.parser.TagElement)

protected void handleStartTag(TagElement sample code for javax.swing.text.html.parser.TagElement definition code for javax.swing.text.html.parser.TagElement  tag)
Handle Start Tag.

Overrides:
handleStartTag sample code for javax.swing.text.html.parser.Parser.handleStartTag(javax.swing.text.html.parser.TagElement) definition code for javax.swing.text.html.parser.Parser.handleStartTag(javax.swing.text.html.parser.TagElement) in class Parser sample code for javax.swing.text.html.parser.Parser definition code for javax.swing.text.html.parser.Parser

handleComment sample code for javax.swing.text.html.parser.DocumentParser.handleComment(char[]) definition code for javax.swing.text.html.parser.DocumentParser.handleComment(char[])

protected void handleComment(char[] text)
Description copied from class: Parser sample code for javax.swing.text.html.parser.Parser.handleComment(char[]) definition code for javax.swing.text.html.parser.Parser.handleComment(char[])
Called when an HTML comment is encountered.

Overrides:
handleComment sample code for javax.swing.text.html.parser.Parser.handleComment(char[]) definition code for javax.swing.text.html.parser.Parser.handleComment(char[]) in class Parser sample code for javax.swing.text.html.parser.Parser definition code for javax.swing.text.html.parser.Parser

handleEmptyTag sample code for javax.swing.text.html.parser.DocumentParser.handleEmptyTag(javax.swing.text.html.parser.TagElement) definition code for javax.swing.text.html.parser.DocumentParser.handleEmptyTag(javax.swing.text.html.parser.TagElement)

protected void handleEmptyTag(TagElement sample code for javax.swing.text.html.parser.TagElement definition code for javax.swing.text.html.parser.TagElement  tag)
                       throws ChangedCharSetException sample code for javax.swing.text.ChangedCharSetException definition code for javax.swing.text.ChangedCharSetException 
Handle Empty Tag.

Overrides:
handleEmptyTag sample code for javax.swing.text.html.parser.Parser.handleEmptyTag(javax.swing.text.html.parser.TagElement) definition code for javax.swing.text.html.parser.Parser.handleEmptyTag(javax.swing.text.html.parser.TagElement) in class Parser sample code for javax.swing.text.html.parser.Parser definition code for javax.swing.text.html.parser.Parser
Throws:
ChangedCharSetException sample code for javax.swing.text.ChangedCharSetException definition code for javax.swing.text.ChangedCharSetException

handleEndTag sample code for javax.swing.text.html.parser.DocumentParser.handleEndTag(javax.swing.text.html.parser.TagElement) definition code for javax.swing.text.html.parser.DocumentParser.handleEndTag(javax.swing.text.html.parser.TagElement)

protected void handleEndTag(TagElement sample code for javax.swing.text.html.parser.TagElement definition code for javax.swing.text.html.parser.TagElement  tag)
Handle End Tag.

Overrides:
handleEndTag sample code for javax.swing.text.html.parser.Parser.handleEndTag(javax.swing.text.html.parser.TagElement) definition code for javax.swing.text.html.parser.Parser.handleEndTag(javax.swing.text.html.parser.TagElement) in class Parser sample code for javax.swing.text.html.parser.Parser definition code for javax.swing.text.html.parser.Parser

handleText sample code for javax.swing.text.html.parser.DocumentParser.handleText(char[]) definition code for javax.swing.text.html.parser.DocumentParser.handleText(char[])

protected void handleText(char[] data)
Handle Text.

Overrides:
handleText sample code for javax.swing.text.html.parser.Parser.handleText(char[]) definition code for javax.swing.text.html.parser.Parser.handleText(char[]) in class Parser sample code for javax.swing.text.html.parser.Parser definition code for javax.swing.text.html.parser.Parser

handleError sample code for javax.swing.text.html.parser.DocumentParser.handleError(int, java.lang.String) definition code for javax.swing.text.html.parser.DocumentParser.handleError(int, java.lang.String)

protected void handleError(int ln,
                           String sample code for java.lang.String definition code for java.lang.String  errorMsg)
Description copied from class: Parser sample code for javax.swing.text.html.parser.Parser.handleError(int, java.lang.String) definition code for javax.swing.text.html.parser.Parser.handleError(int, java.lang.String)
An error has occurred.

Overrides:
handleError sample code for javax.swing.text.html.parser.Parser.handleError(int, java.lang.String) definition code for javax.swing.text.html.parser.Parser.handleError(int, java.lang.String) in class Parser sample code for javax.swing.text.html.parser.Parser definition code for javax.swing.text.html.parser.Parser