Enhydra 3.0.1 API

org.apache.html.dom
Class HTMLDocumentImpl

java.lang.Object
  |
  +--org.apache.xerces.dom.NodeImpl
        |
        +--org.apache.xerces.dom.NodeContainer
              |
              +--org.apache.xerces.dom.DocumentImpl
                    |
                    +--org.apache.html.dom.HTMLDocumentImpl

public class HTMLDocumentImpl
extends DocumentImpl
implements HTMLDocument

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 Node.appendChild(org.w3c.dom.Node) or Node.insertBefore(org.w3c.dom.Node, org.w3c.dom.Node), 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(java.lang.String)) and HTTP attribute methods (getURL(), getCookie()).

Version:
$Revision: 1.1.1.1 $ $Date: 2000/02/20 03:13:59 $
See Also:
HTMLDocument, Serialized Form

Fields inherited from class org.apache.xerces.dom.DocumentImpl
allowGrammarAccess, docElement, docType, errorChecking, identifiers, iterators, mutationEvents, ranges, treeWalkers
 
Fields inherited from class org.apache.xerces.dom.NodeContainer
firstChild, kidOK, lastChild, nodeListChanges, nodeListIndex, nodeListLength, nodeListNode, syncChildren
 
Fields inherited from class org.apache.xerces.dom.NodeImpl
ELEMENT_DEFINITION_NODE, fInternalSetNodeValue, MUTATION_AGGREGATE, MUTATION_ALL, MUTATION_LOCAL, MUTATION_NONE, name, nextSibling, ownerDocument, parentNode, previousSibling, readOnly, syncData, userData, value
 
Fields inherited from interface org.w3c.dom.Node
ATTRIBUTE_NODE, CDATA_SECTION_NODE, COMMENT_NODE, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_TYPE_NODE, ELEMENT_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE, NOTATION_NODE, PROCESSING_INSTRUCTION_NODE, TEXT_NODE
 
Constructor Summary
HTMLDocumentImpl()
           
 
Method Summary
 Node cloneNode(boolean deep)
          Returns a duplicate of this node, i.e., serves as a generic copy constructor for nodes.
 void close()
          Closes a document stream opened by open()and forces rendering.
 Attr createAttribute(java.lang.String name)
          Creates an Attribute having this Document as its OwnerDoc.
 Element createElement(java.lang.String tagName)
          Creates an element of the type specified.
 Element createElementNS(java.lang.String namespaceURI, java.lang.String qualifiedName)
          Creates an element of the given qualified name and namespace URI.
 HTMLCollection getAnchors()
          A collection of all the anchor (A) elements in a document with a value for the name attribute.Note.
 HTMLCollection getApplets()
          A collection of all the OBJECT elements that includeapplets and APPLET (deprecated) elements ina document.
 HTMLElement getBody()
          The element that contains the content for the document.
 java.lang.String getCookie()
          The cookies associated with this document.
 Element getDocumentElement()
          This is a convenience attribute that allows direct access to the child node that is the root element of the document.
 java.lang.String getDomain()
          The domain name of the server that served the document, or null if the server cannot be identified by a domain name.
 Element getElementById(java.lang.String elementId)
          Returns the Element whose id is given by elementId.
 NodeList getElementsByName(java.lang.String elementName)
          Returns the (possibly empty) collection of elements whosename value is given by elementName.
 NodeList getElementsByTagName(java.lang.String tagName)
          Returns a NodeList of all the Elements with a given tag name in the order in which they would be encountered in a preorder traversal of the Document tree.
 NodeList getElementsByTagNameNS(java.lang.String namespaceURI, java.lang.String localName)
          Returns a NodeList of all the Elements with a given local name and namespace URI in the order in which they would be encountered in a preorder traversal of the Document tree.
 HTMLCollection getForms()
          A collection of all the forms of a document.
 HTMLElement getHead()
          Obtains the <HEAD> element in the document, creating one if does not exist before.
 HTMLCollection getImages()
          A collection of all the IMG elements in a document.The behavior is limited to IMG elements forbackwards compatibility.
 HTMLCollection getLinks()
          A collection of all AREA elements andanchor (A) elements in a documentwith a value for the href attribute.
 java.lang.String getReferrer()
          Returns the URI of the page that linked to this page.
 java.lang.String getTitle()
          The title of a document as specified by the TITLEelement in the head of the document.
 java.lang.String getURL()
          The complete URI of the document.
 void open()
          Note.This method and the ones following allow a user to add to or replace the structuremodel of a document using strings of unparsed HTML.
 void setBody(HTMLElement newBody)
           
 void setCookie(java.lang.String cookie)
           
 void setTitle(java.lang.String newTitle)
           
 void write(java.lang.String text)
          Write a string of text to a document stream opened byopen().
 void writeln(java.lang.String text)
          Write a string of text followed by a newline character to a document stream opened by open().
 
Methods inherited from class org.apache.xerces.dom.DocumentImpl
createAttributeNS, createCDATASection, createComment, createDocumentFragment, createDocumentType, createElementDefinition, createEntity, createEntityReference, createEvent, createNodeIterator, createNodeIterator, createNotation, createProcessingInstruction, createRange, createTextNode, createTreeWalker, createTreeWalker, getDoctype, getErrorChecking, getIdentifier, getIdentifiers, getImplementation, getMutationEvents, getNodeIterators, getNodeName, getNodeType, getNodeValue, getRanges, getTreeWalkers, importNode, insertBefore, isKidOK, isXMLName, putIdentifier, removeChild, removeIdentifier, removeTreeWalker, setErrorChecking, setMutationEvents, setNodeValue
 
Methods inherited from class org.apache.xerces.dom.NodeContainer
appendChild, getChildNodes, getFirstChild, getLastChild, getLength, hasChildNodes, item, normalize, replaceChild, setReadOnly, synchronizeChildren
 
Methods inherited from class org.apache.xerces.dom.NodeImpl
addEventListener, changed, dispatchEvent, finalize, getAttributes, getLocalName, getNamespaceURI, getNextSibling, getOwnerDocument, getParentNode, getPrefix, getPreviousSibling, getReadOnly, getUserData, removeEventListener, setPrefix, setUserData, supports, synchronizeData, toString
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

HTMLDocumentImpl

public HTMLDocumentImpl()
Method Detail

getDocumentElement

public Element getDocumentElement()
Description copied from interface: Document
This is a convenience attribute that allows direct access to the child node that is the root element of the document. For HTML documents, this is the element with the tagName "HTML".
Overrides:
getDocumentElement in class DocumentImpl

getHead

public 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(java.lang.String), getBody() and setBody(org.w3c.dom.html.HTMLElement) to assure the document has the <HEAD> element correctly placed.

Returns:
The <HEAD> element

getTitle

public java.lang.String getTitle()
Description copied from interface: HTMLDocument
The title of a document as specified by the TITLEelement in the head of the document.
Specified by:
getTitle in interface HTMLDocument

setTitle

public void setTitle(java.lang.String newTitle)
Specified by:
setTitle in interface HTMLDocument

getBody

public HTMLElement getBody()
Description copied from interface: HTMLDocument
The element that contains the content for the document. In documentswith BODY contents, returns the BODYelement, and in frameset documents, this returns the outermostFRAMESET element.
Specified by:
getBody in interface HTMLDocument

setBody

public void setBody(HTMLElement newBody)
Specified by:
setBody in interface HTMLDocument

getElementById

public Element getElementById(java.lang.String elementId)
Description copied from interface: HTMLDocument
Returns the Element whose id is given by elementId. If no such element exists, returns null. Behavior is not defined if more than one element has this id.
Specified by:
getElementById in interface HTMLDocument
Overrides:
getElementById in class DocumentImpl
Tags copied from interface: HTMLDocument
Parameters:
elementId - The unique id value for an element.
Returns:
The matching element.

getElementsByName

public NodeList getElementsByName(java.lang.String elementName)
Description copied from interface: HTMLDocument
Returns the (possibly empty) collection of elements whosename value is given by elementName.
Specified by:
getElementsByName in interface HTMLDocument
Tags copied from interface: HTMLDocument
Parameters:
elementName - The name attribute value for an element.
Returns:
The matching elements.

getElementsByTagName

public final NodeList getElementsByTagName(java.lang.String tagName)
Description copied from interface: Document
Returns a NodeList of all the Elements with a given tag name in the order in which they would be encountered in a preorder traversal of the Document tree.
Overrides:
getElementsByTagName in class DocumentImpl
Tags copied from interface: Document
Parameters:
tagname - The name of the tag to match on. The special value "*" matches all tags.
Returns:
A new NodeList object containing all the matched Elements.

getElementsByTagNameNS

public final NodeList getElementsByTagNameNS(java.lang.String namespaceURI,
                                             java.lang.String localName)
Description copied from interface: Document
Returns a NodeList of all the Elements with a given local name and namespace URI in the order in which they would be encountered in a preorder traversal of the Document tree.
Overrides:
getElementsByTagNameNS in class DocumentImpl
Tags copied from interface: Document
Parameters:
namespaceURI - The namespace URI of the elements to match on. The special value "*" matches all namespaces.
localName - The local name of the elements to match on. The special value "*" matches all local names.
Returns:
A new NodeList object containing all the matched Elements.

createElementNS

public Element createElementNS(java.lang.String namespaceURI,
                               java.lang.String qualifiedName)
Description copied from interface: Document
Creates an element of the given qualified name and namespace URI. If the given namespaceURI is null or an empty string and the qualifiedName has a prefix that is "xml", the created element is bound to the predefined namespace "http://www.w3.org/XML/1998/namespace" .
HTML-only DOM implementations do not need to implement this method.
Overrides:
createElementNS in class DocumentImpl
Tags copied from interface: Document
Parameters:
namespaceURI - The namespace URI of the element to create.
qualifiedName - The qualified name of the element type to instantiate.
Returns:
A new Element object with the following attributes: AttributeValueNode.nodeNamequalifiedName Node.namespaceURInamespaceURI, or "http://www.w3.org/XML/1998/namespace" if namespaceURI is null or an empty string, and the prefix is "xml" Node.prefixprefix, extracted from qualifiedName, or null if there is no prefixNode.localNamelocal name, extracted from qualifiedNameElement.tagName qualifiedName
Throws:
DOMException - INVALID_CHARACTER_ERR: Raised if the specified qualified name contains an illegal character.
NAMESPACE_ERR: Raised if the qualifiedName is malformed, or if the qualifiedName has a prefix that is "xml" and the namespaceURI is neither null nor an empty string nor "http://www.w3.org/XML/1998/namespace".

createElement

public Element createElement(java.lang.String tagName)
                      throws DOMException
Description copied from interface: Document
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.
Overrides:
createElement in class DocumentImpl
Tags copied from interface: Document
Parameters:
tagName - The name of the element type to instantiate. For XML, this is case-sensitive. For HTML, the tagName parameter may be provided in any case, but it must be mapped to the canonical uppercase form by the DOM implementation.
Returns:
A new Element object with the nodeName attribute set to tagName, and localName, prefix, and namespaceURI set to null.
Throws:
DOMException - INVALID_CHARACTER_ERR: Raised if the specified name contains an illegal character.

createAttribute

public Attr createAttribute(java.lang.String name)
                     throws DOMException
Creates an Attribute having this Document as its OwnerDoc. Overrides DocumentImpl.createAttribute(java.lang.String) and returns and attribute whose name is lower case.
Overrides:
createAttribute in class DocumentImpl
Parameters:
name - The name of the attribute
Returns:
An attribute whose name is all lower case
Throws:
DOMException(INVALID_NAME_ERR) - if the attribute name is not acceptable

getReferrer

public java.lang.String getReferrer()
Description copied from interface: HTMLDocument
Returns the URI of the page that linked to this page. The value isan empty string if the user navigated to the page directly (notthrough a link, but, for example, via a bookmark).
Specified by:
getReferrer in interface HTMLDocument

getDomain

public java.lang.String getDomain()
Description copied from interface: HTMLDocument
The domain name of the server that served the document, or null if the server cannot be identified by a domain name.
Specified by:
getDomain in interface HTMLDocument

getURL

public java.lang.String getURL()
Description copied from interface: HTMLDocument
The complete URI of the document.
Specified by:
getURL in interface HTMLDocument

getCookie

public java.lang.String getCookie()
Description copied from interface: HTMLDocument
The cookies associated with this document. If there are none, thevalue is an empty string. Otherwise, the value is a string: asemicolon-delimited list of "name, value" pairs for all the cookiesassociated with the page. For example, name=value;expires=date.
Specified by:
getCookie in interface HTMLDocument

setCookie

public void setCookie(java.lang.String cookie)
Specified by:
setCookie in interface HTMLDocument

getImages

public HTMLCollection getImages()
Description copied from interface: HTMLDocument
A collection of all the IMG elements in a document.The behavior is limited to IMG elements forbackwards compatibility.
Specified by:
getImages in interface HTMLDocument

getApplets

public HTMLCollection getApplets()
Description copied from interface: HTMLDocument
A collection of all the OBJECT elements that includeapplets and APPLET (deprecated) elements ina document.
Specified by:
getApplets in interface HTMLDocument

getLinks

public HTMLCollection getLinks()
Description copied from interface: HTMLDocument
A collection of all AREA elements andanchor (A) elements in a documentwith a value for the href attribute.
Specified by:
getLinks in interface HTMLDocument

getForms

public HTMLCollection getForms()
Description copied from interface: HTMLDocument
A collection of all the forms of a document.
Specified by:
getForms in interface HTMLDocument

getAnchors

public HTMLCollection getAnchors()
Description copied from interface: HTMLDocument
A collection of all the anchor (A) elements in a document with a value for the name attribute.Note. For reasons of backwardscompatibility, the returned set of anchors only contains those anchors created with the name attribute, not those created with the id attribute.
Specified by:
getAnchors in interface HTMLDocument

open

public void open()
Description copied from interface: HTMLDocument
Note.This method and the ones following allow a user to add to or replace the structuremodel 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 methodsmay 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.
Specified by:
open in interface HTMLDocument

close

public void close()
Description copied from interface: HTMLDocument
Closes a document stream opened by open()and forces rendering.
Specified by:
close in interface HTMLDocument

write

public void write(java.lang.String text)
Description copied from interface: HTMLDocument
Write a string of text to a document stream opened byopen(). The text is parsed into the document's structuremodel.
Specified by:
write in interface HTMLDocument
Tags copied from interface: HTMLDocument
Parameters:
text - The string to be parsed into some structure in the document structuremodel.

writeln

public void writeln(java.lang.String text)
Description copied from interface: HTMLDocument
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.
Specified by:
writeln in interface HTMLDocument
Tags copied from interface: HTMLDocument
Parameters:
text - The string to be parsed into some structure in the document structuremodel.

cloneNode

public Node cloneNode(boolean deep)
Description copied from interface: Node
Returns a duplicate of this node, i.e., serves as a generic copy constructor for nodes. The duplicate node has no parent ( parentNode returns null.).
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 text it contains unless it is a deep clone, since the text is contained in a child Text node. 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.
Overrides:
cloneNode in class DocumentImpl
Tags copied from interface: Node
Parameters:
deep - 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:
The duplicate node.

Enhydra 3.0.1 API