Top Description Fields Constructors Methods
org.apache.xml.serialize

public final Class HTMLdtd

extends Object
Class Inheritance
Imports
java.io.BufferedReader, .InputStream, .InputStreamReader, java.util.Hashtable, .Locale, org.apache.xerces.dom.DOMMessageFormatter

Deprecated

This class was deprecated in Xerces 2.9.0. It is recommended that new applications use JAXP's Transformation API for XML (TrAX) for serializing HTML. See the Xerces documentation for more information.

Utility class for accessing information specific to HTML documents. The HTML DTD is expressed as three utility function groups. Two methods allow for checking whether an element requires an open tag on printing (isEmptyTag) or on parsing (isOptionalClosing).

Two other methods translate character references from name to value and from value to name. A small entities resource is loaded into memory the first time any of these methods is called for fast and efficient access.

Author
Assaf Arkin
Version
$Revision: 699892 $ $Date: 2008-09-29 02:38:27 +0530 (Mon, 29 Sep 2008) $

Field Summary

Modifier and TypeField and Description
private static Hashtable<K, V>
private static Hashtable<K, V>
_byChar

Table of reverse character reference mapping.

private static Hashtable<K, V>
_byName

Table of entity name to value mapping.

private static Hashtable<K, V>
_elemDefs

Holds element definitions.

private static final int
ALLOWED_HEAD

Allowed to appear in head.

private static final int
CLOSE_DD_DT

When opened, closes DD or DT.

private static final int
CLOSE_P

When opened, closes P.

private static final int
CLOSE_SELF

When opened, closes itself.

private static final int
CLOSE_TABLE

When opened, closes another table section.

private static final int
CLOSE_TH_TD

When opened, closes TH or TD.

private static final int
ELEM_CONTENT

Element contains element content only.

private static final int
EMPTY

Element is empty (also means only opening tag)

private static final String
ENTITIES_RESOURCE

Locates the HTML entities file that is loaded upon initialization.

public static final String
HTMLPublicId

Public identifier for HTML 4.01 (Strict) document type.

public static final String
HTMLSystemId

System identifier for HTML 4.01 (Strict) document type.

private static final int
ONLY_OPENING

Only opening tag should be printed.

private static final int
OPT_CLOSING

Optional closing tag.

private static final int
PRESERVE

Element preserve spaces.

public static final String
XHTMLPublicId

Public identifier for XHTML 1.0 (Strict) document type.

public static final String
XHTMLSystemId

System identifier for XHTML 1.0 (Strict) document type.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static int

Returns:

Character code or EOF (-1)
charFromName
(String
Name of character reference
name
)

Returns the value of an HTML character reference by its name.

private static void
defineBoolean(String tagName, String attrName)

private static void
defineBoolean(String tagName, String[] attrNames)

private static void
defineElement(String name, int flags)

private static void
defineEntity(String
The entity's name
name
,
char
The entity's value
value
)

Defines a new character reference.

public static String

Returns:

Entity's name or null
fromChar
(int
Character value of entity
value
)

Returns the name of an HTML character reference based on its character value.

private static void
initialize()

Initialize upon first access.

public static boolean
isBoolean(String
The element's tag name
tagName
,
String
The attribute's name
attrName
)

Returns true if the specified attribute is a boolean and should be printed without the value.

public static boolean

Returns:

True if closing tag closes opening tag
isClosing
(String
The newly opened element
tagName
,
String
The already opened element
openTag
)

Returns true if the opening of one element (tagName) implies the closing of another open element (openTag).

private static boolean
isElement(String name, int flag)

public static boolean

Returns:

True if element content
isElementContent
(String
The element tag name (upper case)
tagName
)

Returns true if element is declared to have element content.

public static boolean

Returns:

True if element is empty
isEmptyTag
(String
The element tag name (upper case)
tagName
)

Returns true if element is declared to be empty.

public static boolean

Returns:

True if only opening tag should be printed
isOnlyOpening
(String
The element tag name (upper case)
tagName
)

Returns true if element's closing tag is generally not printed.

public static boolean

Returns:

True if closing tag implied
isOptionalClosing
(String
The element tag name (upper case)
tagName
)

Returns true if element's closing tag is optional and need not exist.

public static boolean

Returns:

True if element's text content preserves spaces
isPreserveSpace
(String
The element tag name (upper case)
tagName
)

Returns true if element's textual contents preserves spaces.

public static boolean
isURI(String
The element's tag name
tagName
,
String
The attribute's name
attrName
)

Returns true if the specified attribute it a URI and should be escaped appropriately.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_boolAttrsback to summary
private static Hashtable<K, V> _boolAttrs
_byCharback to summary
private static Hashtable<K, V> _byChar

Table of reverse character reference mapping. Character codes are held as single-character strings, mapped to their reference name.

_byNameback to summary
private static Hashtable<K, V> _byName

Table of entity name to value mapping. Entities are held as strings, character references as Character objects.

_elemDefsback to summary
private static Hashtable<K, V> _elemDefs

Holds element definitions.

ALLOWED_HEADback to summary
private static final int ALLOWED_HEAD

Allowed to appear in head.

CLOSE_DD_DTback to summary
private static final int CLOSE_DD_DT

When opened, closes DD or DT.

CLOSE_Pback to summary
private static final int CLOSE_P

When opened, closes P.

CLOSE_SELFback to summary
private static final int CLOSE_SELF

When opened, closes itself.

CLOSE_TABLEback to summary
private static final int CLOSE_TABLE

When opened, closes another table section.

CLOSE_TH_TDback to summary
private static final int CLOSE_TH_TD

When opened, closes TH or TD.

ELEM_CONTENTback to summary
private static final int ELEM_CONTENT

Element contains element content only.

EMPTYback to summary
private static final int EMPTY

Element is empty (also means only opening tag)

ENTITIES_RESOURCEback to summary
private static final String ENTITIES_RESOURCE

Locates the HTML entities file that is loaded upon initialization. This file is a resource loaded with the default class loader.

HTMLPublicIdback to summary
public static final String HTMLPublicId

Public identifier for HTML 4.01 (Strict) document type.

HTMLSystemIdback to summary
public static final String HTMLSystemId

System identifier for HTML 4.01 (Strict) document type.

ONLY_OPENINGback to summary
private static final int ONLY_OPENING

Only opening tag should be printed.

OPT_CLOSINGback to summary
private static final int OPT_CLOSING

Optional closing tag.

PRESERVEback to summary
private static final int PRESERVE

Element preserve spaces.

XHTMLPublicIdback to summary
public static final String XHTMLPublicId

Public identifier for XHTML 1.0 (Strict) document type.

XHTMLSystemIdback to summary
public static final String XHTMLSystemId

System identifier for XHTML 1.0 (Strict) document type.

Constructor Detail

HTMLdtdback to summary
public HTMLdtd()

Method Detail

charFromNameback to summary
public static int charFromName(String name)

Returns the value of an HTML character reference by its name. If the reference is not found or was not defined as a character reference, returns EOF (-1).

Parameters
name:String

Name of character reference

Returns:int

Character code or EOF (-1)

defineBooleanback to summary
private static void defineBoolean(String tagName, String attrName)
defineBooleanback to summary
private static void defineBoolean(String tagName, String[] attrNames)
defineElementback to summary
private static void defineElement(String name, int flags)
defineEntityback to summary
private static void defineEntity(String name, char value)

Defines a new character reference. The reference's name and value are supplied. Nothing happens if the character reference is already defined.

Unlike internal entities, character references are a string to single character mapping. They are used to map non-ASCII characters both on parsing and printing, primarily for HTML documents. '<amp;' is an example of a character reference.

Parameters
name:String

The entity's name

value:char

The entity's value

fromCharback to summary
public static String fromChar(int value)

Returns the name of an HTML character reference based on its character value. Only valid for entities defined from character references. If no such character value was defined, return null.

Parameters
value:int

Character value of entity

Returns:String

Entity's name or null

initializeback to summary
private static void initialize()

Initialize upon first access. Will load all the HTML character references into a list that is accessible by name or character value and is optimized for character substitution. This method may be called any number of times but will execute only once.

isBooleanback to summary
public static boolean isBoolean(String tagName, String attrName)

Returns true if the specified attribute is a boolean and should be printed without the value. This applies to attributes that are true if they exist, such as selected (OPTION/INPUT).

Parameters
tagName:String

The element's tag name

attrName:String

The attribute's name

isClosingback to summary
public static boolean isClosing(String tagName, String openTag)

Returns true if the opening of one element (tagName) implies the closing of another open element (openTag). For example, every opening LI will close the previously open LI, and every opening BODY will close the previously open HEAD.

Parameters
tagName:String

The newly opened element

openTag:String

The already opened element

Returns:boolean

True if closing tag closes opening tag

isElementback to summary
private static boolean isElement(String name, int flag)
isElementContentback to summary
public static boolean isElementContent(String tagName)

Returns true if element is declared to have element content. Whitespaces appearing inside element content will be ignored, other text will simply report an error.

Parameters
tagName:String

The element tag name (upper case)

Returns:boolean

True if element content

isEmptyTagback to summary
public static boolean isEmptyTag(String tagName)

Returns true if element is declared to be empty. HTML elements are defines as empty in the DTD, not by the document syntax.

Parameters
tagName:String

The element tag name (upper case)

Returns:boolean

True if element is empty

isOnlyOpeningback to summary
public static boolean isOnlyOpening(String tagName)

Returns true if element's closing tag is generally not printed. For example, LI should not print the closing tag.

Parameters
tagName:String

The element tag name (upper case)

Returns:boolean

True if only opening tag should be printed

isOptionalClosingback to summary
public static boolean isOptionalClosing(String tagName)

Returns true if element's closing tag is optional and need not exist. An error will not be reported for such elements if they are not closed. For example, LI is most often not closed.

Parameters
tagName:String

The element tag name (upper case)

Returns:boolean

True if closing tag implied

isPreserveSpaceback to summary
public static boolean isPreserveSpace(String tagName)

Returns true if element's textual contents preserves spaces. This only applies to PRE and TEXTAREA, all other HTML elements do not preserve space.

Parameters
tagName:String

The element tag name (upper case)

Returns:boolean

True if element's text content preserves spaces

isURIback to summary
public static boolean isURI(String tagName, String attrName)

Returns true if the specified attribute it a URI and should be escaped appropriately. In HTML URIs are escaped differently than normal attributes.

Parameters
tagName:String

The element's tag name

attrName:String

The attribute's name