gnu.xml.dom

Class DomDoctype

Implemented Interfaces:
Cloneable, Comparable<T>, DocumentEvent, DocumentType, EventTarget, Node, NodeList

public class DomDoctype
extends DomExtern
implements DocumentType

"DocumentType" implementation (with no extensions for supporting any document typing information). This is a non-core DOM class, supporting the "XML" feature.

Few XML applications will actually care about this partial DTD support, since it doesn't expose any (!) of the data typing facilities which can motivate applications to use DTDs. It does not expose element content models, or information about attribute typing rules. Plus the information it exposes isn't very useful; as one example, DOM exposes information about unparsed ENTITY objects, which is only used with certain element attributes, but does not expose the information about those attributes which is needed to apply that data!

Also, note that there are no nonportable ways to associate even the notation and entity information exposed by DOM with a DocumentType. While there is a DOM L2 method to construct a DocumentType, it only gives access to the textual content of the <!DOCTYPE ...> declaration.

In short, you are strongly advised not to rely on this incomplete DTD functionality in your application code.

See Also:
DomEntity, DomEntityReference, DomNotation

Fields inherited from interface org.w3c.dom.Node

ATTRIBUTE_NODE, CDATA_SECTION_NODE, COMMENT_NODE, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_POSITION_CONTAINED_BY, DOCUMENT_POSITION_CONTAINS, DOCUMENT_POSITION_DISCONNECTED, DOCUMENT_POSITION_FOLLOWING, DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC, DOCUMENT_POSITION_PRECEDING, DOCUMENT_TYPE_NODE, ELEMENT_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE, NOTATION_NODE, PROCESSING_INSTRUCTION_NODE, TEXT_NODE

Constructor Summary

DomDoctype(DomDocument doc, String name, String publicId, String systemId)
JAXP builder constructor.
DomDoctype(DOMImplementation impl, String name, String publicId, String systemId, String internalSubset)
Constructs a DocumentType node associated with the specified implementation, with the specified name.

Method Summary

void
attributeDecl(String eName, String aName, String type, String mode, String value)
Object
clone()
Shallow clone of the doctype, except that associated entities and notations are (deep) cloned.
Entity
declareEntity(String name, String publicId, String systemId, String notation)
Records the declaration of a general entity in this DocumentType.
Notation
declareNotation(String name, String publicId, String systemId)
Records the declaration of a notation in this DocumentType.
void
elementDecl(String name, String model)
String
getBaseURI()
The base URI of a DocumentType is always null.
NamedNodeMap
getEntities()
DOM L1 Returns information about any general entities declared in the DTD.
DOMImplementation
getImplementation()
Returns the implementation associated with this document type.
String
getInternalSubset()
DOM L2 Returns the internal subset of the document, as a string of unparsed XML declarations (and comments, PIs, whitespace); or returns null if there is no such subset.
String
getName()
DOM L1 Returns the root element's name (just like getNodeName).
NamedNodeMap
getNotations()
DOM L1 Returns information about any notations declared in the DTD.
boolean
isSameNode(Node arg)
void
makeReadonly()
Sets the internal "readonly" flag so the node and its associated data (only lists of entities and notations, no type information at the moment) can't be changed.
boolean
supports(String feature, String version)
DOM L2 Consults the DOM implementation to determine if the requested feature is supported.

Methods inherited from class gnu.xml.dom.DomExtern

getLocalName, getNodeName, getPublicId, getSystemId

Methods inherited from class gnu.xml.dom.DomNode

addEventListener, appendChild, clone, cloneNode, compact, compareDocumentPosition, compareTo, createEvent, dispatchEvent, getAttributes, getBaseURI, getChildNodes, getElementsByTagName, getElementsByTagNameNS, getFeature, getFirstChild, getLastChild, getLength, getLocalName, getNamespaceURI, getNextSibling, getNodeName, getNodeType, getNodeValue, getOwnerDocument, getParentNode, getPrefix, getPreviousSibling, getTextContent, getUserData, hasAttributes, hasChildNodes, insertBefore, isDefaultNamespace, isEqualNode, isReadonly, isSameNode, isSupported, item, list, lookupNamespaceURI, lookupPrefix, makeReadonly, nameAndTypeEquals, normalize, removeChild, removeEventListener, replaceChild, setNodeValue, setPrefix, setTextContent, setUserData, toString, trimToSize

Methods inherited from class java.lang.Object

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

Constructor Details

DomDoctype

public DomDoctype(DomDocument doc,
                  String name,
                  String publicId,
                  String systemId)
JAXP builder constructor.
Parameters:
doc - the document
name - the name of the document element
publicId - the public ID of the document type declaration
systemId - the system ID of the document type declaration

DomDoctype

protected DomDoctype(DOMImplementation impl,
                     String name,
                     String publicId,
                     String systemId,
                     String internalSubset)
Constructs a DocumentType node associated with the specified implementation, with the specified name.

This constructor should only be invoked by a DOMImplementation as part of its createDocumentType functionality, or through a subclass which is similarly used in a "Sub-DOM" style layer.

Note that at this time there is no standard SAX API granting access to the internal subset text, so that relying on that value is not currently portable.

Parameters:
impl - The implementation with which this object is associated
name - Name of this root element
publicId - If non-null, provides the external subset's PUBLIC identifier
systemId - If non-null, provides the external subset's SYSTEM identifier
internalSubset - Provides the literal value (unparsed, no entities expanded) of the DTD's internal subset.

Method Details

attributeDecl

public void attributeDecl(String eName,
                          String aName,
                          String type,
                          String mode,
                          String value)

clone

public Object clone()
Shallow clone of the doctype, except that associated entities and notations are (deep) cloned.
Overrides:
clone in interface DomNode

declareEntity

public Entity declareEntity(String name,
                            String publicId,
                            String systemId,
                            String notation)
Records the declaration of a general entity in this DocumentType.
Parameters:
name - Name of the entity
publicId - If non-null, provides the entity's PUBLIC identifier
systemId - Provides the entity's SYSTEM identifier
notation - If non-null, provides the entity's notation (indicating an unparsed entity)
Returns:
The Entity that was declared, or null if the entity wasn't recorded (because it's a parameter entity or because an entity with this name was already declared).
Throws:
DOMException - NO_MODIFICATION_ALLOWED_ERR if the DocumentType is no longer writable.
DOMException - HIERARCHY_REQUEST_ERR if the DocumentType is not associated with a document.

declareNotation

public Notation declareNotation(String name,
                                String publicId,
                                String systemId)
Records the declaration of a notation in this DocumentType.
Parameters:
name - Name of the notation
publicId - If non-null, provides the notation's PUBLIC identifier
systemId - If non-null, provides the notation's SYSTEM identifier
Returns:
The notation that was declared.
Throws:
DOMException - NO_MODIFICATION_ALLOWED_ERR if the DocumentType is no longer writable.
DOMException - HIERARCHY_REQUEST_ERR if the DocumentType is not associated with a document.

elementDecl

public void elementDecl(String name,
                        String model)

getBaseURI

public final String getBaseURI()
The base URI of a DocumentType is always null. See the Infoset Mapping, appendix C.
Specified by:
getBaseURI in interface Node
Overrides:
getBaseURI in interface DomNode

getEntities

public NamedNodeMap getEntities()
DOM L1 Returns information about any general entities declared in the DTD.

Note: DOM L1 doesn't throw a DOMException here, but then it doesn't have the strange construction rules of L2.

Specified by:
getEntities in interface DocumentType
Throws:
DOMException - HIERARCHY_REQUEST_ERR if the DocumentType is not associated with a document.

getImplementation

public final DOMImplementation getImplementation()
Returns the implementation associated with this document type.

getInternalSubset

public String getInternalSubset()
DOM L2 Returns the internal subset of the document, as a string of unparsed XML declarations (and comments, PIs, whitespace); or returns null if there is no such subset. There is no vendor-independent expectation that this attribute be set, or that declarations found in it be reflected in the entities or notations attributes of this Document "Type" object.

Some application-specific XML profiles require that documents only use specific PUBLIC identifiers, without an internal subset to modify the interperetation of the declarations associated with that PUBLIC identifier through some standard.

Specified by:
getInternalSubset in interface DocumentType

getName

public final String getName()
DOM L1 Returns the root element's name (just like getNodeName).
Specified by:
getName in interface DocumentType

getNotations

public NamedNodeMap getNotations()
DOM L1 Returns information about any notations declared in the DTD.

Note: DOM L1 doesn't throw a DOMException here, but then it doesn't have the strange construction rules of L2.

Specified by:
getNotations in interface DocumentType
Throws:
DOMException - HIERARCHY_REQUEST_ERR if the DocumentType is not associated with a document.

isSameNode

public boolean isSameNode(Node arg)
Specified by:
isSameNode in interface Node
Overrides:
isSameNode in interface DomNode

makeReadonly

public void makeReadonly()
Sets the internal "readonly" flag so the node and its associated data (only lists of entities and notations, no type information at the moment) can't be changed.
Overrides:
makeReadonly in interface DomNode

supports

public final boolean supports(String feature,
                              String version)
DOM L2 Consults the DOM implementation to determine if the requested feature is supported.

DomDoctype.java -- Copyright (C) 1999,2000,2001,2004 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.