com.sun.lwuit.html
Class HTMLParser

java.lang.Object
  extended by com.sun.lwuit.xml.XMLParser
      extended by com.sun.lwuit.html.HTMLParser

public class HTMLParser
extends XMLParser

The HTMLParser class is used to parse an XHTML-MP 1.0 document into a DOM object (Element). Unsupported tags and attributes as well as comments are dropped in the parsing process. The parser is also makes use of CSSParser for external CSS files, embedded CSS segments and CSS within the 'style' attribute.


Constructor Summary
HTMLParser()
          Constructs a new instance of HTMLParser
 
Method Summary
protected  java.lang.String convertCharEntity(java.lang.String charEntity)
          Overrides XMLParser.convertCharEntity to add in HTML char entities
protected  Element createNewElement(java.lang.String name)
          Overrides XMLParser.createNewElement to return an HTMLElement instance
protected  Element createNewTextElement(java.lang.String text)
          Overrides XMLParser.createNewTextElement to return an HTMLElement instance
protected  java.lang.String getSupportedStandardName()
          Returns a string identifying the document type this parser supports.
protected  boolean isEmptyTag(java.lang.String tagName)
          Checks whether the specified tag is an empty tag as defined in EMPTY_TAGS
protected  boolean isSupported(Element element)
          Overrides the Element.isSupported to let the parser know which tags are supported in XHTML-MP 1.0
 HTMLElement parseHTML(java.io.InputStreamReader isr)
          A convenience method that casts the returned type of the parse method to HTMLElement.
protected  void parseTagContent(Element element, java.io.Reader is)
          Overrides XMLParser.parseTagContent to enable embedded CSS segments (Style tags)
protected  boolean shouldEvaluate(Element element)
          Overrides the Element.shouldEvaluate method to return false on the script tag.
 
Methods inherited from class com.sun.lwuit.xml.XMLParser
addCharEntitiesRange, addCharEntity, attribute, endTag, eventParser, isWhiteSpace, notifyError, parse, parseCommentOrXMLDeclaration, parseTag, setIncludeWhitespacesBetweenTags, setParserCallback, startTag, textElement
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HTMLParser

public HTMLParser()
Constructs a new instance of HTMLParser

Method Detail

parseTagContent

protected void parseTagContent(Element element,
                               java.io.Reader is)
                        throws java.io.IOException
Overrides XMLParser.parseTagContent to enable embedded CSS segments (Style tags)

Overrides:
parseTagContent in class XMLParser
Parameters:
element - The current parent element
is - The reader containing the XML
Throws:
java.io.IOException - if an I/O error in the stream is encountered

createNewElement

protected Element createNewElement(java.lang.String name)
Overrides XMLParser.createNewElement to return an HTMLElement instance

Overrides:
createNewElement in class XMLParser
Parameters:
name - The HTMLElement's name
Returns:
a new instance of the names HTMLElement

createNewTextElement

protected Element createNewTextElement(java.lang.String text)
Overrides XMLParser.createNewTextElement to return an HTMLElement instance

Overrides:
createNewTextElement in class XMLParser
Parameters:
text - The HTMLElement's text
Returns:
a new instance of the HTMLElement

convertCharEntity

protected java.lang.String convertCharEntity(java.lang.String charEntity)
Overrides XMLParser.convertCharEntity to add in HTML char entities

Overrides:
convertCharEntity in class XMLParser
Parameters:
charEntity - The char entity to convert
Returns:
A string containing a single char, or the original char entity string (with & and ;) if the char entity couldn't be resolved

isEmptyTag

protected boolean isEmptyTag(java.lang.String tagName)
Checks whether the specified tag is an empty tag as defined in EMPTY_TAGS

Overrides:
isEmptyTag in class XMLParser
Parameters:
tagName - The tag name to check
Returns:
true if that tag is defined as an empty tag, false otherwise

parseHTML

public HTMLElement parseHTML(java.io.InputStreamReader isr)
A convenience method that casts the returned type of the parse method to HTMLElement. Basically calling this method is simlar to calling parse and casting to HTMLElement.

Parameters:
isr - The input stream containing the HTML
Returns:
The HTML document

getSupportedStandardName

protected java.lang.String getSupportedStandardName()
Returns a string identifying the document type this parser supports. This should be overriden by subclassing parsers.

Overrides:
getSupportedStandardName in class XMLParser
Returns:
a string identifying the document type this parser supports.

isSupported

protected boolean isSupported(Element element)
Overrides the Element.isSupported to let the parser know which tags are supported in XHTML-MP 1.0

Overrides:
isSupported in class XMLParser
Parameters:
element - The element to check
Returns:
true if the tag is a supported XHTML Mobile Profile 1.0 tag, false otherwise

shouldEvaluate

protected boolean shouldEvaluate(Element element)
Overrides the Element.shouldEvaluate method to return false on the script tag. The script tag should be skipped entirely, since it may contain characters like greater-than and lesser-than which may break the HTML All other tags are evaluated (i.e. added including all their children to the tree), even if not supported (But of course their functionality is ignored by HTMLComponent)

Overrides:
shouldEvaluate in class XMLParser
Parameters:
element - The element to check
Returns:
false if this is the SCRIPT tag, true otherwise