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 DocumentParser

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

public class DocumentParser
extends 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
dtd, strict
 
Constructor Summary

          
 
Method Summary
protected void
handleComment(char[] text)

          Called when an HTML comment is encountered.
protected void

          Handle Empty Tag.
protected void

          Handle End Tag.
protected void
handleError(int ln, String errorMsg)

          An error has occurred.
protected void

          Handle Start Tag.
protected void
handleText(char[] data)

          Handle Text.
 void
parse(Reader in, HTMLEditorKit.ParserCallback callback, boolean ignoreCharSet)

          
 
Methods inherited from class javax.swing.text.html.parser.Parser
endTag, error, error, error, error, flushAttributes, getAttributes, getCurrentLine, getCurrentPos, handleComment, handleEmptyTag, handleEndTag, handleEOFInComment, handleError, handleStartTag, handleText, handleTitle, makeTag, makeTag, markFirstTime, parse, parseDTDMarkup, parseMarkupDeclarations, startTag
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DocumentParser

public DocumentParser(DTD dtd)
Parameters:
dtd
Method Detail

handleComment

protected void handleComment(char[] text)
Overrides:
handleComment in class Parser
Parameters:
text

handleEmptyTag

protected void handleEmptyTag(TagElement tag)
                       throws ChangedCharSetException
Handle Empty Tag.

Overrides:
handleEmptyTag in class Parser
Parameters:
tag
Throws:
ChangedCharSetException

handleEndTag

protected void handleEndTag(TagElement tag)
Handle End Tag.

Overrides:
handleEndTag in class Parser
Parameters:
tag

handleError

protected void handleError(int ln,
                           String errorMsg)
Overrides:
handleError in class Parser
Parameters:
ln
errorMsg

handleStartTag

protected void handleStartTag(TagElement tag)
Handle Start Tag.

Overrides:
handleStartTag in class Parser
Parameters:
tag

handleText

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

Overrides:
handleText in class Parser
Parameters:
data

parse

public void parse(Reader in,
                  HTMLEditorKit.ParserCallback callback,
                  boolean ignoreCharSet)
           throws IOException
Parameters:
in
callback
ignoreCharSet
Throws:
IOException


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/.