Top Description Fields Constructors Methods
org.apache.html.dom

public Class HTMLDocumentImpl

extends DocumentImpl
implements HTMLDocument
Class Inheritance
All Implemented Interfaces
org.w3c.dom.html.HTMLDocument, org.w3c.dom.Document, org.w3c.dom.Node
Imports
java.io.StringWriter, java.lang.reflect.Constructor, java.util.Hashtable, .Locale, org.apache.xerces.dom.DocumentImpl, .ElementImpl, org.w3c.dom.Attr, .DOMException, .Element, .Node, .NodeList, .UserDataHandler, org.w3c.dom.html.HTMLBodyElement, .HTMLCollection, .HTMLDocument, .HTMLElement, .HTMLFrameSetElement, .HTMLHeadElement, .HTMLHtmlElement, .HTMLTitleElement

Implements an HTML document. Provides access to the top level element in the document, its body and title.

Several methods create new nodes of all basic types (comment, text, element, etc.). These methods create new nodes but do not place them in the document tree. The nodes may be placed in the document tree using org.w3c.dom.Node#appendChild or org.w3c.dom.Node#insertBefore, or they may be placed in some other document tree.

Note

<FRAMESET> documents are not supported at the moment, neither are direct document writing (open, write) and HTTP attribute methods (getURL, getCookie).

Author
Assaf Arkin
Version
$Revision: 1029415 $ $Date: 2010-10-31 22:32:22 +0530 (Sun, 31 Oct 2010) $
See Also
org.w3c.dom.html.HTMLDocument

Field Summary

Modifier and TypeField and Description
private HTMLCollectionImpl
_anchors

Holds HTMLCollectionImpl object with live collection of all anchors in document.

private HTMLCollectionImpl
_applets

Holds HTMLCollectionImpl object with live collection of all applets in document.

private static final Class<T>[]
_elemClassSigHTML

Signature used to locate constructor of HTML element classes.

private static Hashtable<K, V>
_elementTypesHTML

Holds names and classes of HTML element types.

private HTMLCollectionImpl
_forms

Holds HTMLCollectionImpl object with live collection of all forms in document.

private HTMLCollectionImpl
_images

Holds HTMLCollectionImpl object with live collection of all images in document.

private HTMLCollectionImpl
_links

Holds HTMLCollectionImpl object with live collection of all links in document.

private StringWriter
_writer

Holds string writer used by direct manipulation operation (open.

private static final long
Inherited from org.apache.xerces.dom.DocumentImpl:
eventListenersiteratorReferenceQueueiteratorsmutationEventsrangeReferenceQueueranges

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected boolean
public Node
cloneNode(boolean
If true, recursively clone the subtree under the specified node; if false, clone only the node itself (and its attributes, if it is an Element).
deep
)

Overrides org.apache.xerces.dom.DocumentImpl.cloneNode.

Implements org.w3c.dom.Node.cloneNode.

Returns a duplicate of this node, i.e., serves as a generic copy constructor for nodes.
public void
close()

Implements org.w3c.dom.html.HTMLDocument.close.

Closes a document stream opened by open() and forces rendering.
public Attr

Returns:

An attribute whose name is all lower case
createAttribute
(String
The name of the attribute
name
)

Overrides org.apache.xerces.dom.CoreDocumentImpl.createAttribute.

Implements org.w3c.dom.Document.createAttribute.

Creates an Attribute having this Document as its OwnerDoc.
public Element
createElement(String
The name of the element type to instantiate. For XML, this is case-sensitive, otherwise it depends on the case-sensitivity of the markup language in use. In that case, the name is mapped to the canonical form of that markup by the DOM implementation.
tagName
)

Overrides org.apache.xerces.dom.CoreDocumentImpl.createElement.

Implements org.w3c.dom.Document.createElement.

Creates an element of the type specified.
public Element

Returns:

Element A new Element object with the following attributes:
createElementNS
(String
The namespace URI of the element to create.
namespaceURI
,
String
The qualified name of the element type to instantiate.
qualifiedName
,
String
The local name of the element to instantiate.
localpart
)

Overrides org.apache.xerces.dom.CoreDocumentImpl.createElementNS.

Xerces-specific constructor.
public Element
createElementNS(String
The namespace URI of the element to create.
namespaceURI
,
String
The qualified name of the element type to instantiate.
qualifiedName
)

Overrides org.apache.xerces.dom.CoreDocumentImpl.createElementNS.

Implements org.w3c.dom.Document.createElementNS.

Creates an element of the given qualified name and namespace URI.
public HTMLCollection
getAnchors()

Implements org.w3c.dom.html.HTMLDocument.getAnchors.

A collection of all the anchor (A ) elements in a document with a value for the name attribute.
public HTMLCollection
getApplets()

Implements org.w3c.dom.html.HTMLDocument.getApplets.

A collection of all the OBJECT elements that include applets and APPLET ( deprecated ) elements in a document.
public synchronized HTMLElement
getBody()

Implements org.w3c.dom.html.HTMLDocument.getBody.

The element that contains the content for the document.
public String
getCookie()

Implements org.w3c.dom.html.HTMLDocument.getCookie.

The cookies associated with this document.
public synchronized Element
getDocumentElement()

Overrides org.apache.xerces.dom.CoreDocumentImpl.getDocumentElement.

Implements org.w3c.dom.Document.getDocumentElement.

This is a convenience attribute that allows direct access to the child node that is the document element of the document.
public String
getDomain()

Implements org.w3c.dom.html.HTMLDocument.getDomain.

The domain name of the server that served the document, or null if the server cannot be identified by a domain name.
public synchronized Element
getElementById(String
The unique id value for an element.
elementId
)

Overrides org.apache.xerces.dom.CoreDocumentImpl.getElementById.

Implements org.w3c.dom.Document.getElementById.

Returns the Element that has an ID attribute with the given value.
private Element

Returns:

The node in which to look for
getElementById
(String
The id value to look for
elementId
,
Node node)

Recursive method retreives an element by its id attribute.

public NodeList
getElementsByName(String
The name attribute value for an element.
elementName
)

Implements org.w3c.dom.html.HTMLDocument.getElementsByName.

Returns the (possibly empty) collection of elements whose name value is given by elementName .
public final NodeList
getElementsByTagName(String
The name of the tag to match on. The special value "*" matches all tags. For XML, the tagname parameter is case-sensitive, otherwise it depends on the case-sensitivity of the markup language in use.
tagName
)

Overrides org.apache.xerces.dom.CoreDocumentImpl.getElementsByTagName.

Implements org.w3c.dom.Document.getElementsByTagName.

Returns a NodeList of all the Elements in document order with a given tag name and are contained in the document.
public final NodeList
getElementsByTagNameNS(String
The namespace URI of the elements to match on. The special value "*" matches all namespaces.
namespaceURI
,
String
The local name of the elements to match on. The special value "*" matches all local names.
localName
)

Overrides org.apache.xerces.dom.CoreDocumentImpl.getElementsByTagNameNS.

Implements org.w3c.dom.Document.getElementsByTagNameNS.

Returns a NodeList of all the Elements with a given local name and namespace URI in document order.
public HTMLCollection
getForms()

Implements org.w3c.dom.html.HTMLDocument.getForms.

A collection of all the forms of a document.
public synchronized HTMLElement

Returns:

The <HEAD> element
getHead
()

Obtains the <HEAD> element in the document, creating one if does not exist before.

public HTMLCollection
getImages()

Implements org.w3c.dom.html.HTMLDocument.getImages.

A collection of all the IMG elements in a document.
public String
getReferrer()

Implements org.w3c.dom.html.HTMLDocument.getReferrer.

Returns the URI of the page that linked to this page.
public synchronized String
getTitle()

Implements org.w3c.dom.html.HTMLDocument.getTitle.

The title of a document as specified by the TITLE element in the head of the document.
public String
getURL()

Implements org.w3c.dom.html.HTMLDocument.getURL.

The complete URI of the document.
public void
private static void
populateElementType(String tagName, String className)

private static synchronized void
populateElementTypes()

Called by the constructor to populate the element types list (see _elementTypesHTML).

public synchronized void
public void
public synchronized void
public void
write(String
The string to be parsed into some structure in the document structure model.
text
)

Implements org.w3c.dom.html.HTMLDocument.write.

Write a string of text to a document stream opened by open() .
public void
writeln(String
The string to be parsed into some structure in the document structure model.
text
)

Implements org.w3c.dom.html.HTMLDocument.writeln.

Write a string of text followed by a newline character to a document stream opened by open() .
Inherited from org.apache.xerces.dom.DocumentImpl:
addEventListenercopyEventListenerscreateEventcreateNodeIteratorcreateNodeIteratorcreateRangecreateTreeWalkercreateTreeWalkerdispatchAggregateEventsdispatchAggregateEventsdispatchEventdispatchEventToSubtreedispatchingEventToSubtreegetEventListenersgetImplementationremoveEventListenersaveEnclosingAttrsetEventListeners

Field Detail

_anchorsback to summary
private HTMLCollectionImpl _anchors

Holds HTMLCollectionImpl object with live collection of all anchors in document. This reference is on demand only once.

_appletsback to summary
private HTMLCollectionImpl _applets

Holds HTMLCollectionImpl object with live collection of all applets in document. This reference is on demand only once.

_elemClassSigHTMLback to summary
private static final Class<T>[] _elemClassSigHTML

Signature used to locate constructor of HTML element classes. This static array is shared across all HTML documents.

See Also
createElement
_elementTypesHTMLback to summary
private static Hashtable<K, V> _elementTypesHTML

Holds names and classes of HTML element types. When an element with a particular tag name is created, the matching java.lang.Class is used to create the element object. For example, <A> matches HTMLAnchorElementImpl. This static table is shared across all HTML documents.

See Also
createElement
_formsback to summary
private HTMLCollectionImpl _forms

Holds HTMLCollectionImpl object with live collection of all forms in document. This reference is on demand only once.

_imagesback to summary
private HTMLCollectionImpl _images

Holds HTMLCollectionImpl object with live collection of all images in document. This reference is on demand only once.

_writerback to summary
private StringWriter _writer

Holds string writer used by direct manipulation operation (open. write, etc) to write new contents into the document and parse that text into a document tree.

serialVersionUIDback to summary
private static final long serialVersionUID

Hides org.apache.xerces.dom.DocumentImpl.serialVersionUID.

Constructor Detail

HTMLDocumentImplback to summary
public HTMLDocumentImpl()

Method Detail

canRenameElementsback to summary
protected boolean canRenameElements(String newNamespaceURI, String newNodeName, ElementImpl el)

Overrides org.apache.xerces.dom.CoreDocumentImpl.canRenameElements.

cloneNodeback to summary
public Node cloneNode(boolean deep)

Overrides org.apache.xerces.dom.DocumentImpl.cloneNode.

Implements org.w3c.dom.Node.cloneNode.

Doc from org.w3c.dom.Node.cloneNode.

Returns a duplicate of this node, i.e., serves as a generic copy constructor for nodes. The duplicate node has no parent ( parentNode is null) and no user data. User data associated to the imported node is not carried over. However, if any UserDataHandlers has been specified along with the associated data these handlers will be called with the appropriate parameters before this method returns.
Cloning an Element copies all attributes and their values, including those generated by the XML processor to represent defaulted attributes, but this method does not copy any children it contains unless it is a deep clone. This includes text contained in an the Element since the text is contained in a child Text node. Cloning an Attr directly, as opposed to be cloned as part of an Element cloning operation, returns a specified attribute (specified is true). Cloning an Attr always clones its children, since they represent its value, no matter whether this is a deep clone or not. Cloning an EntityReference automatically constructs its subtree if a corresponding Entity is available, no matter whether this is a deep clone or not. Cloning any other type of node simply returns a copy of this node.
Note that cloning an immutable subtree results in a mutable copy, but the children of an EntityReference clone are readonly . In addition, clones of unspecified Attr nodes are specified. And, cloning Document, DocumentType, Entity, and Notation nodes is implementation dependent.

Parameters
deep:boolean

If true, recursively clone the subtree under the specified node; if false, clone only the node itself (and its attributes, if it is an Element).

Returns:Node

The duplicate node.

closeback to summary
public void close()

Implements org.w3c.dom.html.HTMLDocument.close.

Doc from org.w3c.dom.html.HTMLDocument.close.

Closes a document stream opened by open() and forces rendering.

createAttributeback to summary
public Attr createAttribute(String name) throws DOMException

Overrides org.apache.xerces.dom.CoreDocumentImpl.createAttribute.

Implements org.w3c.dom.Document.createAttribute.

Creates an Attribute having this Document as its OwnerDoc. Overrides DocumentImpl#createAttribute and returns and attribute whose name is lower case.

Parameters
name:String

The name of the attribute

Returns:Attr

An attribute whose name is all lower case

Exceptions
DOMException:

Doc from org.w3c.dom.Document.createAttribute.

INVALID_CHARACTER_ERR: Raised if the specified name is not an XML name according to the XML version in use specified in the Document.xmlVersion attribute.

INVALID_CHARACTER_ERR:
if the attribute name is not acceptable
createElementback to summary
public Element createElement(String tagName) throws DOMException

Overrides org.apache.xerces.dom.CoreDocumentImpl.createElement.

Implements org.w3c.dom.Document.createElement.

Doc from org.w3c.dom.Document.createElement.

Creates an element of the type specified. Note that the instance returned implements the Element interface, so attributes can be specified directly on the returned object.
In addition, if there are known attributes with default values, Attr nodes representing them are automatically created and attached to the element.
To create an element with a qualified name and namespace URI, use the createElementNS method.

Parameters
tagName:String

The name of the element type to instantiate. For XML, this is case-sensitive, otherwise it depends on the case-sensitivity of the markup language in use. In that case, the name is mapped to the canonical form of that markup by the DOM implementation.

Returns:Element

A new Element object with the nodeName attribute set to tagName, and localName, prefix, and namespaceURI set to null.

Exceptions
DOMException:
INVALID_CHARACTER_ERR: Raised if the specified name is not an XML name according to the XML version in use specified in the Document.xmlVersion attribute.
createElementNSback to summary
public Element createElementNS(String namespaceURI, String qualifiedName, String localpart) throws DOMException

Overrides org.apache.xerces.dom.CoreDocumentImpl.createElementNS.

Xerces-specific constructor. "localName" is passed in, so we don't need to create a new String for it.

Parameters
namespaceURI:String

The namespace URI of the element to create.

qualifiedName:String

The qualified name of the element type to instantiate.

localpart:String

The local name of the element to instantiate.

Returns:Element

Element A new Element object with the following attributes:

Exceptions
DOMException:
INVALID_CHARACTER_ERR: Raised if the specified name contains an invalid character.
createElementNSback to summary
public Element createElementNS(String namespaceURI, String qualifiedName)

Overrides org.apache.xerces.dom.CoreDocumentImpl.createElementNS.

Implements org.w3c.dom.Document.createElementNS.

Doc from org.w3c.dom.Document.createElementNS.

Creates an element of the given qualified name and namespace URI.
Per [XML Namespaces] , applications must use the value null as the namespaceURI parameter for methods if they wish to have no namespace.

Parameters
namespaceURI:String

The namespace URI of the element to create.

qualifiedName:String

The qualified name of the element type to instantiate.

Returns:Element

A new Element object with the following attributes:

Attributes of the Element object
Attribute Value
Node.nodeName qualifiedName
Node.namespaceURI namespaceURI
Node.prefix prefix, extracted from qualifiedName, or null if there is no prefix
Node.localName local name, extracted from qualifiedName
Element.tagName qualifiedName
getAnchorsback to summary
public HTMLCollection getAnchors()

Implements org.w3c.dom.html.HTMLDocument.getAnchors.

Doc from org.w3c.dom.html.HTMLDocument.getAnchors.

A collection of all the anchor (A ) elements in a document with a value for the name attribute. Note. For reasons of backwards compatibility, the returned set of anchors only contains those anchors created with the name attribute, not those created with the id attribute.

getAppletsback to summary
public HTMLCollection getApplets()

Implements org.w3c.dom.html.HTMLDocument.getApplets.

Doc from org.w3c.dom.html.HTMLDocument.getApplets.

A collection of all the OBJECT elements that include applets and APPLET ( deprecated ) elements in a document.

getBodyback to summary
public synchronized HTMLElement getBody()

Implements org.w3c.dom.html.HTMLDocument.getBody.

Doc from org.w3c.dom.html.HTMLDocument.getBody.

The element that contains the content for the document. In documents with BODY contents, returns the BODY element. In frameset documents, this returns the outermost FRAMESET element.

getCookieback to summary
public String getCookie()

Implements org.w3c.dom.html.HTMLDocument.getCookie.

Doc from org.w3c.dom.html.HTMLDocument.getCookie.

The cookies associated with this document. If there are none, the value is an empty string. Otherwise, the value is a string: a semicolon-delimited list of "name, value" pairs for all the cookies associated with the page. For example, name=value;expires=date .

getDocumentElementback to summary
public synchronized Element getDocumentElement()

Overrides org.apache.xerces.dom.CoreDocumentImpl.getDocumentElement.

Implements org.w3c.dom.Document.getDocumentElement.

Doc from org.w3c.dom.Document.getDocumentElement.

This is a convenience attribute that allows direct access to the child node that is the document element of the document.

getDomainback to summary
public String getDomain()

Implements org.w3c.dom.html.HTMLDocument.getDomain.

Doc from org.w3c.dom.html.HTMLDocument.getDomain.

The domain name of the server that served the document, or null if the server cannot be identified by a domain name.

getElementByIdback to summary
public synchronized Element getElementById(String elementId)

Overrides org.apache.xerces.dom.CoreDocumentImpl.getElementById.

Implements org.w3c.dom.Document.getElementById.

Doc from org.w3c.dom.Document.getElementById.

Returns the Element that has an ID attribute with the given value. If no such element exists, this returns null . If more than one element has an ID attribute with that value, what is returned is undefined.
The DOM implementation is expected to use the attribute Attr.isId to determine if an attribute is of type ID.

Note

Attributes with the name "ID" or "id" are not of type ID unless so defined.

Parameters
elementId:String

The unique id value for an element.

Returns:Element

The matching element or null if there is none.

getElementByIdback to summary
private Element getElementById(String elementId, Node node)

Recursive method retreives an element by its id attribute. Called by getElementById(String).

Parameters
elementId:String

The id value to look for

Returns:Element

The node in which to look for

getElementsByNameback to summary
public NodeList getElementsByName(String elementName)

Implements org.w3c.dom.html.HTMLDocument.getElementsByName.

Doc from org.w3c.dom.html.HTMLDocument.getElementsByName.

Returns the (possibly empty) collection of elements whose name value is given by elementName .

Parameters
elementName:String

The name attribute value for an element.

Returns:NodeList

The matching elements.

getElementsByTagNameback to summary
public final NodeList getElementsByTagName(String tagName)

Overrides org.apache.xerces.dom.CoreDocumentImpl.getElementsByTagName.

Implements org.w3c.dom.Document.getElementsByTagName.

Doc from org.w3c.dom.Document.getElementsByTagName.

Returns a NodeList of all the Elements in document order with a given tag name and are contained in the document.

Parameters
tagName:String

The name of the tag to match on. The special value "*" matches all tags. For XML, the tagname parameter is case-sensitive, otherwise it depends on the case-sensitivity of the markup language in use.

Returns:NodeList

A new NodeList object containing all the matched Elements.

getElementsByTagNameNSback to summary
public final NodeList getElementsByTagNameNS(String namespaceURI, String localName)

Overrides org.apache.xerces.dom.CoreDocumentImpl.getElementsByTagNameNS.

Implements org.w3c.dom.Document.getElementsByTagNameNS.

Doc from org.w3c.dom.Document.getElementsByTagNameNS.

Returns a NodeList of all the Elements with a given local name and namespace URI in document order.

Parameters
namespaceURI:String

The namespace URI of the elements to match on. The special value "*" matches all namespaces.

localName:String

The local name of the elements to match on. The special value "*" matches all local names.

Returns:NodeList

A new NodeList object containing all the matched Elements.

getFormsback to summary
public HTMLCollection getForms()

Implements org.w3c.dom.html.HTMLDocument.getForms.

Doc from org.w3c.dom.html.HTMLDocument.getForms.

A collection of all the forms of a document.

getHeadback to summary
public synchronized HTMLElement getHead()

Obtains the <HEAD> element in the document, creating one if does not exist before. The <HEAD> element is the first element in the <HTML> in the document. The <HTML> element is obtained by calling getDocumentElement. If the element does not exist, one is created.

Called by getTitle, setTitle, getBody and setBody to assure the document has the <HEAD> element correctly placed.

Returns:HTMLElement

The <HEAD> element

getImagesback to summary
public HTMLCollection getImages()

Implements org.w3c.dom.html.HTMLDocument.getImages.

Doc from org.w3c.dom.html.HTMLDocument.getImages.

A collection of all the IMG elements in a document. The behavior is limited to IMG elements for backwards compatibility.

getReferrerback to summary
public String getReferrer()

Implements org.w3c.dom.html.HTMLDocument.getReferrer.

Doc from org.w3c.dom.html.HTMLDocument.getReferrer.

Returns the URI of the page that linked to this page. The value is an empty string if the user navigated to the page directly (not through a link, but, for example, via a bookmark).

getTitleback to summary
public synchronized String getTitle()

Implements org.w3c.dom.html.HTMLDocument.getTitle.

Doc from org.w3c.dom.html.HTMLDocument.getTitle.

The title of a document as specified by the TITLE element in the head of the document.

getURLback to summary
public String getURL()

Implements org.w3c.dom.html.HTMLDocument.getURL.

Doc from org.w3c.dom.html.HTMLDocument.getURL.

The complete URI of the document.

openback to summary
public void open()

Implements org.w3c.dom.html.HTMLDocument.open.

Doc from org.w3c.dom.html.HTMLDocument.open.

Note. This method and the ones following allow a user to add to or replace the structure model of a document using strings of unparsed HTML. At the time of writing alternate methods for providing similar functionality for both HTML and XML documents were being considered. The following methods may be deprecated at some point in the future in favor of a more general-purpose mechanism.
Open a document stream for writing. If a document exists in the target, this method clears it.

populateElementTypeback to summary
private static void populateElementType(String tagName, String className)
populateElementTypesback to summary
private static synchronized void populateElementTypes()

Called by the constructor to populate the element types list (see _elementTypesHTML). Will be called multiple times but populate the list only the first time. Replacement for static constructor.

setBodyback to summary
public synchronized void setBody(HTMLElement newBody)

Implements org.w3c.dom.html.HTMLDocument.setBody.

setCookieback to summary
public void setCookie(String cookie)

Implements org.w3c.dom.html.HTMLDocument.setCookie.

setTitleback to summary
public synchronized void setTitle(String newTitle)

Implements org.w3c.dom.html.HTMLDocument.setTitle.

writeback to summary
public void write(String text)

Implements org.w3c.dom.html.HTMLDocument.write.

Doc from org.w3c.dom.html.HTMLDocument.write.

Write a string of text to a document stream opened by open() . The text is parsed into the document's structure model.

Parameters
text:String

The string to be parsed into some structure in the document structure model.

writelnback to summary
public void writeln(String text)

Implements org.w3c.dom.html.HTMLDocument.writeln.

Doc from org.w3c.dom.html.HTMLDocument.writeln.

Write a string of text followed by a newline character to a document stream opened by open() . The text is parsed into the document's structure model.

Parameters
text:String

The string to be parsed into some structure in the document structure model.