javax.swing.text.html.parser

Class DTD

Implemented Interfaces:
DTDConstants

public class DTD
extends Object
implements DTDConstants

Representation or the SGML DTD document. Provides basis for describing a syntax of the HTML documents. The fields of this class are NOT initialized in constructor. You need to do this separately before passing this data structure to the HTML parser. The subclasses with the fields, pre- initialized, for example, for HTML 4.01, can be available only between the implementation specific classes ( for example, gnu.javax.swing.text.html.parser.HTML_401F in this implementation).

If you need more information about SGML DTD documents, the author suggests to read SGML tutorial on http://www.w3.org/TR/WD-html40-970708/intro/sgmltut.html. We also recommend Goldfarb C.F (1991) The SGML Handbook, Oxford University Press, 688 p, ISBN: 0198537379.

Warning: the html, head and other tag fields will only be automatically assigned if the VM has the correctly implemented reflection mechanism. As these fields are not used anywhere in the implementation, not exception will be thrown in the opposite case.

Field Summary

Hashtable
Element>()
The element for accessing all DTD elements by name.
Hashtable
Entity>()
The entity table for accessing all DTD entities by name.
Hashtable
Entity>entityHash
The entity table for accessing all DTD entities by name.
static int
FILE_VERSION
The version of the persistent data format.
Element
applet
The applet element for this DTD.
Element
base
The base element for this DTD.
Element
body
The body element for this DTD.
Hashtable
elementHash
The element for accessing all DTD elements by name.
Vector
elements
Contains all elements in this DTD.
Element
head
The head element for this DTD.
Element
html
The html element for this DTD.
Element
isindex
The isindex element of for this DTD.
Element
meta
The meta element for this DTD.
String
name
The name of this DTD.
Element
p
The p element for this DTD.
Element
param
The param element for this DTD.
Element
pcdata
The pcdata for this DTD.
Element
title
The title element for this DTD.

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

DTD(String a_name)
Create a new DTD with the specified name.

Method Summary

protected AttributeList
defAttributeList(String name, int type, int modifier, String default_value, String allowed_values, AttributeList atts)
Creates and returns new attribute (not an attribute list).
protected ContentModel
defContentModel(int type, Object content, ContentModel next)
Creates a new content model.
protected Element
defElement(String name, int type, boolean headless, boolean tailless, ContentModel content, String[] exclusions, String[] inclusions, AttributeList attributes)
Defines a new element and adds it to the element table.
Entity
defEntity(String name, int type, int character)
Creates, adds into the entity table and returns the character entity like &lt; (means '<' );
protected Entity
defEntity(String name, int type, String data)
Creates, intializes and adds to the entity table the new entity.
void
defineAttributes(String forElement, AttributeList attributes)
Define the attributes for the element with the given name.
Element
defineElement(String name, int type, boolean headless, boolean tailless, ContentModel content, BitSet exclusions, BitSet inclusions, AttributeList attributes)
Defines the element and adds it to the element table.
Entity
defineEntity(String name, int type, char[] data)
Creates, intializes and adds to the entity table the new entity.
static DTD
getDTD(String name)
Get this DTD by name.
Element
getElement(int index)
Get the element by the value of its Element.index field.
Element
getElement(String element_name)
Get the element by the element name.
Entity
getEntity(int id)
Get the entity with the given identifier.
Entity
getEntity(String entity_name)
Get the named entity by its name.
String
getName()
Get the name of this instance of DTD
static void
putDTDHash(String name, DTD dtd)
Place this DTD into the DTD table.
void
read(DataInputStream stream)
Reads DTD from an archived format.
String
toString()
Returns the name of this instance of DTD.

Methods inherited from class java.lang.Object

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

Field Details

Element>()

public Hashtable Element>()
The element for accessing all DTD elements by name.

Entity>()

public HashtableEntity>()
The entity table for accessing all DTD entities by name.

Entity>entityHash

public HashtableEntity>entityHash
The entity table for accessing all DTD entities by name.

FILE_VERSION

public static final int FILE_VERSION
The version of the persistent data format.
Field Value:
1

applet

public Element applet
The applet element for this DTD.

base

public Element base
The base element for this DTD.

body

public Element body
The body element for this DTD.

elementHash

public Hashtable elementHash
The element for accessing all DTD elements by name.

elements

public Vector elements
Contains all elements in this DTD. The javax.swing.text.html.parser.Element#index field of all elements in this vector is set to the element position in this vector.

head

public Element head
The head element for this DTD.

html

public Element html
The html element for this DTD.

isindex

public Element isindex
The isindex element of for this DTD.

meta

public Element meta
The meta element for this DTD.

name

public String name
The name of this DTD.

p

public Element p
The p element for this DTD.

param

public Element param
The param element for this DTD.

pcdata

public Element pcdata
The pcdata for this DTD.

title

public Element title
The title element for this DTD.

Constructor Details

DTD

protected DTD(String a_name)
Create a new DTD with the specified name.

Method Details

defAttributeList

protected AttributeList defAttributeList(String name,
                                         int type,
                                         int modifier,
                                         String default_value,
                                         String allowed_values,
                                         AttributeList atts)
Creates and returns new attribute (not an attribute list).
Parameters:
name - the name of this attribute
type - the type of this attribute (FIXED, IMPLIED or REQUIRED from DTDConstants).
modifier - the modifier of this attribute
default_value - the default value of this attribute
allowed_values - the allowed values of this attribute. The multiple possible values in this parameter are supposed to be separated by '|', same as in SGML DTD <!ATTLIST tag. This parameter can be null if no list of allowed values is specified.
atts - the previous attribute of this element. This is placed to the field AttributeList.next, creating a linked list.
Returns:
The attributes.

defContentModel

protected ContentModel defContentModel(int type,
                                       Object content,
                                       ContentModel next)
Creates a new content model.
Parameters:
type - specifies the BNF operation for this content model. The valid operations are documented in the ContentModel.type.
content - the content of this content model
next - if the content model is specified by BNF-like expression, contains the rest of this expression.
Returns:
The newly created content model.

defElement

protected Element defElement(String name,
                             int type,
                             boolean headless,
                             boolean tailless,
                             ContentModel content,
                             String[] exclusions,
                             String[] inclusions,
                             AttributeList attributes)
Defines a new element and adds it to the element table. If the element alredy exists, overrides it settings with the specified values.
Parameters:
name - the name of the new element
type - the type of the element
headless - true if the element needs no starting tag
tailless - true if the element needs no closing tag
content - the element content.
exclusions - the elements that must be excluded from the content of this element, in all levels of the hierarchy.
inclusions - the elements that can be included as the content of this element.
attributes - the element attributes.
Returns:
the created or updated element.

defEntity

public Entity defEntity(String name,
                        int type,
                        int character)
Creates, adds into the entity table and returns the character entity like &lt; (means '<' );
Parameters:
name - The entity name (without heading & and closing ;)
type - The entity type
character - The entity value (single character)
Returns:
The created entity

defEntity

protected Entity defEntity(String name,
                           int type,
                           String data)
Creates, intializes and adds to the entity table the new entity.
Parameters:
name - the name of the entity
type - the type of the entity
data - the data section of the entity
Returns:
the created entity

defineAttributes

public void defineAttributes(String forElement,
                             AttributeList attributes)
Define the attributes for the element with the given name. If the element is not exist, it is created.
Parameters:
forElement -
attributes -

defineElement

public Element defineElement(String name,
                             int type,
                             boolean headless,
                             boolean tailless,
                             ContentModel content,
                             BitSet exclusions,
                             BitSet inclusions,
                             AttributeList attributes)
Defines the element and adds it to the element table. Sets the Element.index field to the value, unique for this instance of DTD. If the element with the given name already exists, replaces all other its settings by the method argument values.
Parameters:
name - the name of the element
type - the type of the element
headless - true if the element needs no starting tag (should not occur in HTML).
tailless - true if the element needs no ending tag (like <hr>
content - the element content
exclusions - the set of elements that must not occur inside this element. The Element.index value defines which bit in this bitset corresponds to that element.
inclusions - the set of elements that can occur inside this element. the Element.index value defines which bit in this bitset corresponds to that element.
attributes - the element attributes.
Returns:
the newly defined element.

defineEntity

public Entity defineEntity(String name,
                           int type,
                           char[] data)
Creates, intializes and adds to the entity table the new entity.
Parameters:
name - the name of the entity
type - the type of the entity
data - the data section of the entity
Returns:
the created entity

getDTD

public static DTD getDTD(String name)
            throws IOException
Get this DTD by name. The current implementation only looks in the internal table of DTD documents. If no corresponding entry is found, the new entry is created, placed into the table and returned.

getElement

public Element getElement(int index)
Get the element by the value of its Element.index field.

getElement

public Element getElement(String element_name)
Get the element by the element name. If the element is not yet defined, it is newly created and placed into the element table. If the element name matches (ingoring case) a public non static element field in this class, this field is assigned to the value of the newly created element.

getEntity

public Entity getEntity(int id)
Get the entity with the given identifier.
Parameters:
id - that can be returned by javax.swing.text.html.parser.Entity.name2type(String an_entity)
Returns:
The entity from this DTD or null if there is no entity with such id or such entity is not present in the table of this instance.

getEntity

public Entity getEntity(String entity_name)
Get the named entity by its name.

getName

public String getName()
Get the name of this instance of DTD

putDTDHash

public static void putDTDHash(String name,
                              DTD dtd)
Place this DTD into the DTD table.

read

public void read(DataInputStream stream)
            throws IOException
Reads DTD from an archived format. This format is not standardized and differs between implementations.

This implementation reads and defines all entities and elements using ObjectInputStream. The elements and entities can be written into the stream in any order. The objects other than elements and entities are ignored.

Parameters:
stream - A data stream to read from.
Throws:
IOException - If one is thrown by the input stream

toString

public String toString()
Returns the name of this instance of DTD.
Overrides:
toString in interface Object

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