DTD (Java SE 26 & JDK 26)
Description: declaration: module: java.desktop, package: javax.swing.text.html.parser, class: DTD
Keywords: javax.swing.text.html.parser.DTD class

# Class DTD

java.lang.Object
javax.swing.text.html.parser.DTD

All Implemented Interfaces:
  `DTDConstants`

public class DTD extends Object implements DTDConstants
The representation of an SGML DTD. DTD describes a document syntax and is used in parsing of HTML documents. It contains a list of elements and their attributes as well as a list of entities defined in the DTD.

See Also:
  - `Element`
  - `AttributeList`
  - `ContentModel`
  - `Parser`

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `final Element`
  `applet`
  The element corresponding to applet.
  `final Element`
  `base`
  The element corresponding to base.
  `final Element`
  `body`
  The element corresponding to body.
  `Hashtable<String,Element>`
  `elementHash`
  The hash table contains the name of element and the corresponding element.
  `Vector<Element>`
  `elements`
  The vector of elements
  `Hashtable<Object,Entity>`
  `entityHash`
  The hash table contains an `Object` and the corresponding `Entity`
  `static final int`
  `FILE_VERSION`
  The version of a file
  `final Element`
  `head`
  The element corresponding to head.
  `final Element`
  `html`
  The element corresponding to html.
  `final Element`
  `isindex`
  The element corresponding to isindex.
  `final Element`
  `meta`
  The element corresponding to meta.
  `String`
  `name`
  the name of the DTD
  `final Element`
  `p`
  The element corresponding to p.
  `final Element`
  `param`
  The element corresponding to param.
  `final Element`
  `pcdata`
  The element corresponding to pcdata.
  `final Element`
  `title`
  The element corresponding to title.

  ### Fields declared in interface 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`
  Modifier and Type
  Field
  Description
  `static final int`
  `ANY`
  The DTD constant corresponds to ANY
  `static final int`
  `CDATA`
  The DTD constant corresponds to CDATA
  `static final int`
  `CONREF`
  The DTD constant corresponds to CONREF
  `static final int`
  `CURRENT`
  The DTD constant corresponds to CURRENT
  `static final int`
  `DEFAULT`
  The DTD constant corresponds to DEFAULT
  `static final int`
  `EMPTY`
  The DTD constant corresponds to EMPTY
  `static final int`
  `ENDTAG`
  The DTD constant corresponds to ENDTAG
  `static final int`
  `ENTITIES`
  The DTD constant corresponds to ENTITIES
  `static final int`
  `ENTITY`
  The DTD constant corresponds to ENTITY
  `static final int`
  `FIXED`
  The DTD constant corresponds to FIXED
  `static final int`
  `GENERAL`
  The DTD constant corresponds to GENERAL
  `static final int`
  `ID`
  The DTD constant corresponds to ID
  `static final int`
  `IDREF`
  The DTD constant corresponds to IDREF
  `static final int`
  `IDREFS`
  The DTD constant corresponds to IDREFS
  `static final int`
  `IMPLIED`
  The DTD constant corresponds to IMPLIED
  `static final int`
  `MD`
  The DTD constant corresponds to MD
  `static final int`
  `MODEL`
  The DTD constant corresponds to MODEL
  `static final int`
  `MS`
  The DTD constant corresponds to MS
  `static final int`
  `NAME`
  The DTD constant corresponds to NAME
  `static final int`
  `NAMES`
  The DTD constant corresponds to NAMES
  `static final int`
  `NMTOKEN`
  The DTD constant corresponds to NMTOKEN
  `static final int`
  `NMTOKENS`
  The DTD constant corresponds to NMTOKENS
  `static final int`
  `NOTATION`
  The DTD constant corresponds to NOTATION
  `static final int`
  `NUMBER`
  The DTD constant corresponds to NUMBER
  `static final int`
  `NUMBERS`
  The DTD constant corresponds to NUMBERS
  `static final int`
  `NUTOKEN`
  The DTD constant corresponds to NUTOKEN
  `static final int`
  `NUTOKENS`
  The DTD constant corresponds to NUTOKENS
  `static final int`
  `PARAMETER`
  The DTD constant corresponds to PARAMETER
  `static final int`
  `PI`
  The DTD constant corresponds to PI
  `static final int`
  `PUBLIC`
  The DTD constant corresponds to PUBLIC
  `static final int`
  `RCDATA`
  The DTD constant corresponds to RCDATA
  `static final int`
  `REQUIRED`
  The DTD constant corresponds to REQUIRED
  `static final int`
  `SDATA`
  The DTD constant corresponds to SDATA
  `static final int`
  `STARTTAG`
  The DTD constant corresponds to STARTTAG
  `static final int`
  `SYSTEM`
  The DTD constant corresponds to SYSTEM

- ## Constructor Summary

  Constructors
  Modifier
  Constructor
  Description
  `protected`
  `DTD(String name)`
  Creates a new DTD with the specified name.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected AttributeList`
  `defAttributeList(String name, int type, int modifier, String value, String values, AttributeList atts)`
  Creates and returns an `AttributeList` responding to a new attribute.
  `protected ContentModel`
  `defContentModel(int type, Object obj, ContentModel next)`
  Creates and returns a new content model.
  `protected Element`
  `defElement(String name, int type, boolean omitStart, boolean omitEnd, ContentModel content, String[] exclusions, String[] inclusions, AttributeList atts)`
  Creates and returns an `Element`.
  `Entity`
  `defEntity(String name, int type, int ch)`
  Creates and returns a character `Entity`.
  `protected Entity`
  `defEntity(String name, int type, String str)`
  Creates and returns an `Entity`.
  `void`
  `defineAttributes(String name, AttributeList atts)`
  Defines attributes for an `Element`.
  `Element`
  `defineElement(String name, int type, boolean omitStart, boolean omitEnd, ContentModel content, BitSet exclusions, BitSet inclusions, AttributeList atts)`
  Returns the `Element` which matches the specified parameters.
  `Entity`
  `defineEntity(String name, int type, char[] data)`
  Defines an entity.
  `static DTD`
  `getDTD(String name)`
  Returns a DTD with the specified `name`.
  `Element`
  `getElement(int index)`
  Gets an element by index.
  `Element`
  `getElement(String name)`
  Gets an element by name.
  `Entity`
  `getEntity(int ch)`
  Gets a character entity.
  `Entity`
  `getEntity(String name)`
  Gets an entity by name.
  `String`
  `getName()`
  Gets the name of the DTD.
  `static void`
  `putDTDHash(String name, DTD dtd)`
  Put a name and appropriate DTD to hashtable.
  `void`
  `read(DataInputStream in)`
  Recreates a DTD from an archived format.
  `String`
  `toString()`
  Returns a string representation of this DTD.

  ### Methods declared in class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`
  Modifier and Type
  Method
  Description
  `protected Object`
  `clone()`
  Creates and returns a copy of this object.
  `boolean`
  `equals(Object obj)`
  Indicates whether some other object is "equal to" this one.
  `protected void`
  `finalize()`
  Deprecated, for removal: This API element is subject to removal in a future version.
  Finalization is deprecated and subject to removal in a future release.
  `final Class<?>`
  `getClass()`
  Returns the runtime class of this `Object`.
  `int`
  `hashCode()`
  Returns a hash code value for this object.
  `final void`
  `notify()`
  Wakes up a single thread that is waiting on this object's monitor.
  `final void`
  `notifyAll()`
  Wakes up all threads that are waiting on this object's monitor.
  `final void`
  `wait()`
  Causes the current thread to wait until it is awakened, typically by being notified or interrupted.
  `final void`
  `wait(long timeoutMillis)`
  Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.
  `final void`
  `wait(long timeoutMillis, int nanos)`
  Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

- ## Field Details

  - ### name

    public String name
    the name of the DTD

  - ### elements

    public Vector<Element> elements
    The vector of elements

  - ### elementHash

    public Hashtable<String,Element> elementHash
    The hash table contains the name of element and the corresponding element.

  - ### entityHash

    public Hashtable<Object,Entity> entityHash
    The hash table contains an `Object` and the corresponding `Entity`

  - ### pcdata

    public final Element pcdata
    The element corresponding to pcdata.

  - ### html

    public final Element html
    The element corresponding to html.

  - ### meta

    public final Element meta
    The element corresponding to meta.

  - ### base

    public final Element base
    The element corresponding to base.

  - ### isindex

    public final Element isindex
    The element corresponding to isindex.

  - ### head

    public final Element head
    The element corresponding to head.

  - ### body

    public final Element body
    The element corresponding to body.

  - ### applet

    public final Element applet
    The element corresponding to applet.

  - ### param

    public final Element param
    The element corresponding to param.

  - ### p

    public final Element p
    The element corresponding to p.

  - ### title

    public final Element title
    The element corresponding to title.

  - ### FILE_VERSION

    public static final int FILE_VERSION
    The version of a file
    See Also:
      - Constant Field Values

- ## Constructor Details

  - ### DTD

    protected DTD(String name)
    Creates a new DTD with the specified name.
    Parameters:
      `name` - the name, as a `String` of the new DTD

- ## Method Details

  - ### getName

    public String getName()
    Gets the name of the DTD.
    Returns:
      the name of the DTD

  - ### getEntity

    public Entity getEntity(String name)
    Gets an entity by name.
    Parameters:
      `name` - the entity name
    Returns:
      the `Entity` corresponding to the `name` `String`

  - ### getEntity

    public Entity getEntity(int ch)
    Gets a character entity.
    Parameters:
      `ch` - the character
    Returns:
      the `Entity` corresponding to the `ch` character

  - ### getElement

    public Element getElement(String name)
    Gets an element by name. A new element is created if the element doesn't exist.
    Parameters:
      `name` - the requested `String`
    Returns:
      the `Element` corresponding to `name`, which may be newly created

  - ### getElement

    public Element getElement(int index)
    Gets an element by index.
    Parameters:
      `index` - the requested index
    Returns:
      the `Element` corresponding to `index`

  - ### defineEntity

    public Entity defineEntity(String name, int type, char[] data)
    Defines an entity. If the `Entity` specified by `name`, `type`, and `data` exists, it is returned; otherwise a new `Entity` is created and is returned.
    Parameters:
      `name` - the name of the `Entity` as a `String`
      `type` - the type of the `Entity`
      `data` - the `Entity`'s data
    Returns:
      the `Entity` requested or a new `Entity` if not found

  - ### defineElement

    public Element defineElement(String name, int type, boolean omitStart, boolean omitEnd, ContentModel content, BitSet exclusions, BitSet inclusions, AttributeList atts)
    Returns the `Element` which matches the specified parameters. If one doesn't exist, a new one is created and returned.
    Parameters:
      `name` - the name of the `Element`
      `type` - the type of the `Element`
      `omitStart` - `true` if start should be omitted
      `omitEnd` - `true` if end should be omitted
      `content` - the `ContentModel`
      `exclusions` - the set of elements that must not occur inside the element
      `inclusions` - the set of elements that can occur inside the element
      `atts` - the `AttributeList` specifying the `Element`
    Returns:
      the `Element` specified

  - ### defineAttributes

    public void defineAttributes(String name, AttributeList atts)
    Defines attributes for an `Element`.
    Parameters:
      `name` - the name of the `Element`
      `atts` - the `AttributeList` specifying the `Element`

  - ### defEntity

    public Entity defEntity(String name, int type, int ch)
    Creates and returns a character `Entity`.
    Parameters:
      `name` - the entity's name
      `type` - the entity's type
      `ch` - the entity's value (character)
    Returns:
      the new character `Entity`

  - ### defEntity

    protected Entity defEntity(String name, int type, String str)
    Creates and returns an `Entity`.
    Parameters:
      `name` - the entity's name
      `type` - the entity's type
      `str` - the entity's data section
    Returns:
      the new `Entity`

  - ### defElement

    protected Element defElement(String name, int type, boolean omitStart, boolean omitEnd, ContentModel content, String[] exclusions, String[] inclusions, AttributeList atts)
    Creates and returns an `Element`.
    Parameters:
      `name` - the element's name
      `type` - the element's type
      `omitStart` - `true` if the element needs no starting tag
      `omitEnd` - `true` if the element needs no closing tag
      `content` - the element's content
      `exclusions` - the elements that must be excluded from the content of the element
      `inclusions` - the elements that can be included as the content of the element
      `atts` - the attributes of the element
    Returns:
      the new `Element`

  - ### defAttributeList

    protected AttributeList defAttributeList(String name, int type, int modifier, String value, String values, AttributeList atts)
    Creates and returns an `AttributeList` responding to a new attribute.
    Parameters:
      `name` - the attribute's name
      `type` - the attribute's type
      `modifier` - the attribute's modifier
      `value` - the default value of the attribute
      `values` - the allowed values for the attribute (multiple values could be separated by '|')
      `atts` - the previous attribute of the element; to be placed to `AttributeList.next`, creating a linked list
    Returns:
      the new `AttributeList`

  - ### defContentModel

    protected ContentModel defContentModel(int type, Object obj, ContentModel next)
    Creates and returns a new content model.
    Parameters:
      `type` - the type of the new content model
      `obj` - the content of the content model
      `next` - pointer to the next content model
    Returns:
      the new `ContentModel`

  - ### toString

    public String toString()
    Returns a string representation of this DTD.
    Overrides:
      `toString` in class `Object`
    Returns:
      the string representation of this DTD

  - ### putDTDHash

    public static void putDTDHash(String name, DTD dtd)
    Put a name and appropriate DTD to hashtable.
    Parameters:
      `name` - the name of the DTD
      `dtd` - the DTD

  - ### getDTD

    public static DTD getDTD(String name) throws IOException
    Returns a DTD with the specified `name`. If a DTD with that name doesn't exist, one is created and returned. Any uppercase characters in the name are converted to lowercase.
    Parameters:
      `name` - the name of the DTD
    Returns:
      the DTD which corresponds to `name`
    Throws:
      `IOException` - if an I/O error occurs

  - ### read

    public void read(DataInputStream in) throws IOException
    Recreates a DTD from an archived format.
    Parameters:
      `in` - the `DataInputStream` to read from
    Throws:
      `IOException` - if an I/O error occurs