gnu.xml.dom.html2

Class DomHTMLParser

Implemented Interfaces:
DTDConstants

public class DomHTMLParser
extends Parser

This parser reads HTML from the given stream and stores into HTMLDocument. The HTML tag becomes the Node. The tag attributes become the node attributes. The text inside HTML tag is inserted as one or several text nodes. The nested HTML tags are inserted as child nodes. If the strict tree structure, closing the tag means closing all nested tags. To work around this, this parser closes the nested tags and immediately reopens them after the closed tag. In this way, <b><i>c</b>d is parsed as <b><i>c</i></b><i>d .

Field Summary

protected Node
cursor
The subsequently created new nodes will be inserted as the childs of this cursor.
protected DomHTMLDocument
document
The target where HTML document will be inserted.

Fields inherited from class gnu.javax.swing.text.html.parser.support.Parser

dtd, hTag, preformatted, strict

Fields inherited from class gnu.javax.swing.text.html.parser.support.low.ReaderTokenizer

advanced, backupMode

Fields inherited from class gnu.javax.swing.text.html.parser.support.low.Constants

AP, BEGIN, COMMENT_END, COMMENT_OPEN, COMMENT_TRIPLEDASH_END, DOUBLE_DASH, END, ENTITY, ENTITY_NAMED, ENTITY_NUMERIC, EOF, EQ, EXCLAMATION, NUMTOKEN, OTHER, QUOT, SCRIPT, SCRIPT_CLOSE, SCRIPT_OPEN, SGML, SLASH, STYLE, STYLE_CLOSE, STYLE_OPEN, TAG, TAG_CLOSE, WS, bDIGIT, bLETTER, bLINEBREAK, bNAME, bQUOTING, bSINGLE_CHAR_TOKEN, bSPECIAL, bWHITESPACE

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

DomHTMLParser(DTD dtd)
Create parser using the given DTD.

Method Summary

protected Node
createNode(String name)
Create a new node.
protected void
handleComment(char[] text)
Handle comment by inserting the comment node.
protected void
handleEmptyTag(TagElement tag)
Handle the tag with no content.
protected void
handleEndTag(TagElement tag)
Close the given tag.
protected void
handleStartTag(TagElement tag)
Handle the start tag by inserting the HTML element.
protected void
handleText(char[] text)
Handle text by inserting the text node.
HTMLDocument
parseDocument(Reader input)
Read the document, present in the given stream, and return the corresponding HTMLDocument.
boolean
parseMarkupDeclarations(StringBuffer strBuff)
Parse SGML insertion ( <! .

Methods inherited from class gnu.javax.swing.text.html.parser.support.Parser

CDATA, Comment, Script, Sgml, Style, Tag, _handleText, append, consume, endTag, error, error, error, error, error, flushAttributes, getAttributes, getCurrentLine, handleComment, handleEOFInComment, handleEmptyTag, handleEndTag, handleError, handleStartTag, handleText, handleTitle, makeTag, makeTag, markFirstTime, mustBe, noValueAttribute, optional, parse, parseDTDMarkup, parseDocument, parseMarkupDeclarations, readAttributes, resolveNamedEntity, resolveNumericEntity, restart, startTag

Methods inherited from class gnu.javax.swing.text.html.parser.support.low.ReaderTokenizer

error, getEndOfLineSequence, getNextToken, getTokenAhead, getTokenAhead, mark, reset, reset

Methods inherited from class gnu.javax.swing.text.html.parser.support.low.Constants

endMatches

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Details

cursor

protected Node cursor
The subsequently created new nodes will be inserted as the childs of this cursor.

document

protected DomHTMLDocument document
The target where HTML document will be inserted.

Constructor Details

DomHTMLParser

public DomHTMLParser(DTD dtd)
Create parser using the given DTD.
Parameters:
dtd - the DTD (for example, HTML_401F).

Method Details

createNode

protected Node createNode(String name)
Create a new node.
Parameters:
name - the name of node, case insensitive.
Returns:
the created node.

handleComment

protected void handleComment(char[] text)
Handle comment by inserting the comment node.
Overrides:
handleComment in interface Parser
Parameters:
text - the comment text.

handleEmptyTag

protected void handleEmptyTag(TagElement tag)
Handle the tag with no content.
Overrides:
handleEmptyTag in interface Parser
Parameters:
tag - the tag to handle.

handleEndTag

protected void handleEndTag(TagElement tag)
Close the given tag. Close and reopen all nested tags.
Overrides:
handleEndTag in interface Parser
Parameters:
tag - the tag to close.

handleStartTag

protected void handleStartTag(TagElement tag)
Handle the start tag by inserting the HTML element.
Overrides:
handleStartTag in interface Parser
Parameters:
tag - the tag to handle.

handleText

protected void handleText(char[] text)
Handle text by inserting the text node.
Overrides:
handleText in interface Parser
Parameters:
text - the text to insert.

parseDocument

public HTMLDocument parseDocument(Reader input)
            throws IOException
Read the document, present in the given stream, and return the corresponding HTMLDocument.
Parameters:
input - a stream to read from.
Returns:
a document, reflecting the structure of the provided HTML text.
Throws:
IOException - if the reader throws one.

parseMarkupDeclarations

public boolean parseMarkupDeclarations(StringBuffer strBuff)
            throws IOException
Parse SGML insertion ( <! ... > ). Currently just treats it as comment.
Overrides:
parseMarkupDeclarations in interface Parser

DomHTMLParser.java -- Copyright (C) 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.