Book Home Java Enterprise in a Nutshell Search this book

Chapter 32. The javax.swing.text.html.parser Package

This package includes classes and interfaces for parsing HTML text. The parser is configured by a DTD (document type definition) and is therefore customizable. The parser conforms to the HTMLEditorKit.Parser and HTMLEditorKit.ParserCallback interfaces defined in the javax.swing.text.html package. Most applications can ignore this package and simply use javax.swing.JEditorPane and javax.swing.text.html.HTMLEditorKit to handle their HTML parsing and display needs. Figure 32-1 shows the class hierarchy of this package.

figure

Figure 32-1. The javax.swing.text.html.parser package

AttributeListJava 1.2
javax.swing.text.html.parserserializable

This class is an element in a linked list of attribute specifications. The complete list of attribute specifications represents an ATTLIST element of a DTD. Each AttributeList object represents the name, type, and values of a single attribute. Use the getNext() method to obtain the next AttributeList object in the linked list.

public final class AttributeList implements DTDConstants, Serializable {
// Public Constructors
public AttributeList (String name);
public AttributeList (String name, int type, int modifier, String value, java.util.Vector values, AttributeList next);
// Public Class Methods
public static int name2type (String nm);
public static String type2name (int tp);
// Property Accessor Methods (by property name)
public int getModifier ();
public String getName ();
public AttributeList getNext ();
public int getType ();
public String getValue ();
public java.util.Enumeration getValues ();
// Public Methods Overriding Object
public String toString ();
// Public Instance Fields
public int modifier ;
public String name ;
public AttributeList next ;
public int type ;
public String value ;
public java.util.Vector values ;
}

Hierarchy: Object-->AttributeList(DTDConstants,Serializable)

Passed To: AttributeList.AttributeList(), DTD.{defAttributeList(), defElement(), defineAttributes(), defineElement()}

Returned By: AttributeList.getNext(), DTD.defAttributeList(), javax.swing.text.html.parser.Element.{getAttribute(), getAttributeByValue(), getAttributes()}

Type Of: AttributeList.next, javax.swing.text.html.parser.Element.atts

ContentModelJava 1.2
javax.swing.text.html.parserserializable model

This class represents a content model of an element in a DTD.

public final class ContentModel implements Serializable {
// Public Constructors
public ContentModel ();
public ContentModel (javax.swing.text.html.parser.Element content);
public ContentModel (int type, ContentModel content);
public ContentModel (int type, Object content, ContentModel next);
// Public Instance Methods
public boolean empty ();
public javax.swing.text.html.parser.Element first ();
public boolean first (Object token);
public void getElements (java.util.Vector elemVec);
// Public Methods Overriding Object
public String toString ();
// Public Instance Fields
public Object content ;
public ContentModel next ;
public int type ;
}

Hierarchy: Object-->ContentModel(Serializable)

Passed To: ContentModel.ContentModel(), DTD.{defContentModel(), defElement(), defineElement()}

Returned By: DTD.defContentModel(), javax.swing.text.html.parser.Element.getContent()

Type Of: ContentModel.next, javax.swing.text.html.parser.Element.content

DocumentParserJava 1.2
javax.swing.text.html.parser

This Parser subclass is the delegate of the ParserDelegator class. The parse() method reads a document from the specified Reader stream, parses it using the DTD specified when the DocumentParser was created, and notifies the specified HTMLEditorKit.ParserCallback object of the document structure by calling its various methods.

public class DocumentParser extends Parser {
// Public Constructors
public DocumentParser (DTD dtd);
// Public Instance Methods
public void parse (java.io.Reader in, HTMLEditorKit.ParserCallback callback, boolean ignoreCharSet) throws java.io.IOException;
// Protected Methods Overriding Parser
protected void handleComment (char[ ] text);
protected void handleEmptyTag (TagElement tag) throws ChangedCharSetException;
protected void handleEndTag (TagElement tag);
protected void handleError (int ln, String errorMsg);
protected void handleStartTag (TagElement tag);
protected void handleText (char[ ] data);
}

Hierarchy: Object-->Parser(DTDConstants)-->DocumentParser

DTDJava 1.2
javax.swing.text.html.parser

This class represents a document type definition (DTD). A DTD specifies the grammar of the document to be parsed. The methods of this class allow you to define the elements and entities of the grammar and look those elements and entities up by name. It also defines a read() method that can read a DTD stored in a binary format. ParserDelegator reads the default HTML 3.2 DTD from the file html32.bdtd, which is stored in the same directory or ZIP archive as the DTD.class class file.

public class DTD implements DTDConstants {
// Protected Constructors
protected DTD (String name);
// Public Class Methods
public static DTD getDTD (String name) throws java.io.IOException;
public static void putDTDHash (String name, DTD dtd);
// Public Instance Methods
public Entity defEntity (String name, int type, int ch);
public void defineAttributes (String name, AttributeList atts);
public javax.swing.text.html.parser.Element defineElement (String name, int type, boolean omitStart, boolean omitEnd, ContentModel content, java.util.BitSet exclusions, java.util.BitSet inclusions, AttributeList atts);
public Entity defineEntity (String name, int type, char[ ] data);
public javax.swing.text.html.parser.Element getElement (String name);
public javax.swing.text.html.parser.Element getElement (int index);
public Entity getEntity (String name);
public Entity getEntity (int ch);
public String getName ();
public void read (java.io.DataInputStream in) throws java.io.IOException;
// Public Methods Overriding Object
public String toString ();
// Protected Instance Methods
protected AttributeList defAttributeList (String name, int type, int modifier, String value, String values, AttributeList atts);
protected ContentModel defContentModel (int type, Object obj, ContentModel next);
protected javax.swing.text.html.parser.Element defElement (String name, int type, boolean omitStart, boolean omitEnd, ContentModel content, String[ ] exclusions, String[ ] inclusions, AttributeList atts);
protected Entity defEntity (String name, int type, String str);
// Public Class Fields
public static int FILE_VERSION ;
// Public Instance Fields
public final javax.swing.text.html.parser.Element applet ;
public final javax.swing.text.html.parser.Element base ;
public final javax.swing.text.html.parser.Element body ;
public java.util.Hashtable elementHash ;
public java.util.Vector elements ;
public java.util.Hashtable entityHash ;
public final javax.swing.text.html.parser.Element head ;
public final javax.swing.text.html.parser.Element html ;
public final javax.swing.text.html.parser.Element isindex ;
public final javax.swing.text.html.parser.Element meta ;
public String name ;
public final javax.swing.text.html.parser.Element p ;
public final javax.swing.text.html.parser.Element param ;
public final javax.swing.text.html.parser.Element pcdata ;
public final javax.swing.text.html.parser.Element title ;
}

Hierarchy: Object-->DTD(DTDConstants)

Passed To: DocumentParser.DocumentParser(), DTD.putDTDHash(), Parser.Parser(), ParserDelegator.createDTD()

Returned By: DTD.getDTD(), ParserDelegator.createDTD()

Type Of: Parser.dtd

DTDConstantsJava 1.2
javax.swing.text.html.parser

This interface defines various integer constants used in a DTD.

public abstract interface DTDConstants {
// Public Constants
public static final int ANY ; =19
public static final int CDATA ; =1
public static final int CONREF ; =4
public static final int CURRENT ; =3
public static final int DEFAULT ; =131072
public static final int EMPTY ; =17
public static final int ENDTAG ; =14
public static final int ENTITIES ; =3
public static final int ENTITY ; =2
public static final int FIXED ; =1
public static final int GENERAL ; =65536
public static final int ID ; =4
public static final int IDREF ; =5
public static final int IDREFS ; =6
public static final int IMPLIED ; =5
public static final int MD ; =16
public static final int MODEL ; =18
public static final int MS ; =15
public static final int NAME ; =7
public static final int NAMES ; =8
public static final int NMTOKEN ; =9
public static final int NMTOKENS ; =10
public static final int NOTATION ; =11
public static final int NUMBER ; =12
public static final int NUMBERS ; =13
public static final int NUTOKEN ; =14
public static final int NUTOKENS ; =15
public static final int PARAMETER ; =262144
public static final int PI ; =12
public static final int PUBLIC ; =10
public static final int RCDATA ; =16
public static final int REQUIRED ; =2
public static final int SDATA ; =11
public static final int STARTTAG ; =13
public static final int SYSTEM ; =17
}

Implementations: AttributeList, DTD, javax.swing.text.html.parser.Element, Entity, Parser

ElementJava 1.2
javax.swing.text.html.parserserializable

This class encapsulates all of the details of a single ELEMENT of a DTD. It describes the type of a tag, its allowed attributes and their types, and the content model of the tag.

public final class Element implements DTDConstants, Serializable {
// No Constructor
// Public Class Methods
public static int name2type (String nm);
// Property Accessor Methods (by property name)
public AttributeList getAttributes ();
public ContentModel getContent ();
public boolean isEmpty ();
public int getIndex ();
public String getName ();
public int getType ();
// Public Instance Methods
public AttributeList getAttribute (String name);
public AttributeList getAttributeByValue (String name);
public boolean omitEnd ();
public boolean omitStart ();
// Public Methods Overriding Object
public String toString ();
// Public Instance Fields
public AttributeList atts ;
public ContentModel content ;
public Object data ;
public java.util.BitSet exclusions ;
public java.util.BitSet inclusions ;
public int index ;
public String name ;
public boolean oEnd ;
public boolean oStart ;
public int type ;
}

Hierarchy: Object-->javax.swing.text.html.parser.Element(DTDConstants,Serializable)

Passed To: ContentModel.ContentModel(), Parser.{makeTag(), markFirstTime()}, TagElement.TagElement()

Returned By: ContentModel.first(), DTD.{defElement(), defineElement(), getElement()}, TagElement.getElement()

Type Of: DTD.{applet, base, body, head, html, isindex, meta, p, param, pcdata, title}

EntityJava 1.2
javax.swing.text.html.parser

This class represents an ENTITY specification in a DTD. It specifies the name, type, and value of the entity.

public final class Entity implements DTDConstants {
// Public Constructors
public Entity (String name, int type, char[ ] data);
// Public Class Methods
public static int name2type (String nm);
// Property Accessor Methods (by property name)
public char[ ] getData ();
public boolean isGeneral ();
public String getName ();
public boolean isParameter ();
public String getString ();
public int getType ();
// Public Instance Fields
public char[ ] data ;
public String name ;
public int type ;
}

Hierarchy: Object-->Entity(DTDConstants)

Returned By: DTD.{defEntity(), defineEntity(), getEntity()}

ParserJava 1.2
javax.swing.text.html.parser

This class is an HTML parser that uses a DTD object to specify the specific HTML grammar it should parse. The parse() method reads HTML text from a stream and parses it. Parser calls its various protected methods at appropriate points during the parsing process. In order to do anything useful, a subclass must provide non-empty implementations for these methods. See also DocumentParser.

public class Parser implements DTDConstants {
// Public Constructors
public Parser (DTD dtd);
// Public Instance Methods
public void parse (java.io.Reader in) throws java.io.IOException; synchronized
public String parseDTDMarkup () throws java.io.IOException;
// Protected Instance Methods
protected void endTag (boolean omitted);
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);
protected void flushAttributes ();
protected SimpleAttributeSet getAttributes ();
protected int getCurrentLine ();
protected int getCurrentPos ();
protected void handleComment (char[ ] text); empty
protected void handleEmptyTag (TagElement tag) throws ChangedCharSetException; empty
protected void handleEndTag (TagElement tag); empty
protected void handleEOFInComment ();
protected void handleError (int ln, String msg);
protected void handleStartTag (TagElement tag); empty
protected void handleText (char[ ] text); empty
protected void handleTitle (char[ ] text);
protected TagElement makeTag (javax.swing.text.html.parser.Element elem);
protected TagElement makeTag (javax.swing.text.html.parser.Element elem, boolean fictional);
protected void markFirstTime (javax.swing.text.html.parser.Element elem);
protected boolean parseMarkupDeclarations (StringBuffer strBuff) throws java.io.IOException;
protected void startTag (TagElement tag) throws ChangedCharSetException;
// Protected Instance Fields
protected DTD dtd ;
protected boolean strict ;
}

Hierarchy: Object-->Parser(DTDConstants)

Subclasses: DocumentParser

ParserDelegatorJava 1.2
javax.swing.text.html.parser

This class extends the HTMLEditorKit.Parser class and provides a definition of the parse() method, which reads HTML text from a stream and parses it into a sequence of calls to the methods of the specified HTMLEditorKit.ParserCallback object. Each time parse() is called, the ParserDelegator class creates a new instance of DocumentParser to perform the parsing and maintain state for the parsing process.

public class ParserDelegator extends HTMLEditorKit.Parser {
// Public Constructors
public ParserDelegator ();
// Protected Class Methods
protected static DTD createDTD (DTD dtd, String name);
protected static void setDefaultDTD ();
// Public Methods Overriding HTMLEditorKit.Parser
public void parse (java.io.Reader r, HTMLEditorKit.ParserCallback cb, boolean ignoreCharSet) throws java.io.IOException;
}

Hierarchy: Object-->HTMLEditorKit.Parser-->ParserDelegator

TagElementJava 1.2
javax.swing.text.html.parser

This class is used internally by DocumentParser and its superclass Parser to describe the type and behavior of an HTML tag that has been parsed.

public class TagElement {
// Public Constructors
public TagElement (javax.swing.text.html.parser.Element elem);
public TagElement (javax.swing.text.html.parser.Element elem, boolean fictional);
// Public Instance Methods
public boolean breaksFlow ();
public boolean fictional ();
public javax.swing.text.html.parser.Element getElement ();
public HTML.Tag getHTMLTag ();
public boolean isPreformatted ();
}

Passed To: DocumentParser.{handleEmptyTag(), handleEndTag(), handleStartTag()}, Parser.{handleEmptyTag(), handleEndTag(), handleStartTag(), startTag()}

Returned By: Parser.makeTag()



Library Navigation Links

Copyright © 2001 O'Reilly & Associates. All rights reserved.