org.apache.html.dom
Class HTMLDocumentImpl

java.lang.Object
  |
  +--org.apache.xerces.dom.NodeImpl
        |
        +--org.apache.xerces.dom.ChildNode
              |
              +--org.apache.xerces.dom.ParentNode
                    |
                    +--org.apache.xerces.dom.CoreDocumentImpl
                          |
                          +--org.apache.xerces.dom.DocumentImpl
                                |
                                +--org.apache.html.dom.HTMLDocumentImpl
All Implemented Interfaces:
java.lang.Cloneable, org.w3c.dom.Document, org.w3c.dom.events.DocumentEvent, org.w3c.dom.ranges.DocumentRange, org.w3c.dom.traversal.DocumentTraversal, org.w3c.dom.events.EventTarget, org.w3c.dom.html.HTMLDocument, org.w3c.dom.Node, org.w3c.dom.NodeList, java.io.Serializable

public class HTMLDocumentImpl
extends org.apache.xerces.dom.DocumentImpl
implements org.w3c.dom.html.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.18 $ $Date: 2004/02/17 07:14:48 $
Author:
Assaf Arkin
See Also:
HTMLDocument, Serialized Form

Fields inherited from class org.apache.xerces.dom.DocumentImpl
eventListeners, iterators, mutationEvents, ranges
 
Fields inherited from class org.apache.xerces.dom.CoreDocumentImpl
actualEncoding, allowGrammarAccess, changes, docElement, docType, encoding, errorChecking, fDocumentURI, identifiers, standalone, userData, version, xmlVersionChanged
 
Fields inherited from class org.apache.xerces.dom.ParentNode
firstChild, fNodeListCache, ownerDocument
 
Fields inherited from class org.apache.xerces.dom.ChildNode
nextSibling, previousSibling
 
Fields inherited from class org.apache.xerces.dom.NodeImpl
DOCUMENT_POSITION_CONTAINS, DOCUMENT_POSITION_DISCONNECTED, DOCUMENT_POSITION_FOLLOWING, DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC, DOCUMENT_POSITION_IS_CONTAINED, DOCUMENT_POSITION_PRECEDING, ELEMENT_DEFINITION_NODE, FIRSTCHILD, flags, HASSTRING, ID, IGNORABLEWS, NORMALIZED, OWNED, ownerNode, READONLY, SPECIFIED, SYNCCHILDREN, SYNCDATA, TREE_POSITION_ANCESTOR, TREE_POSITION_DESCENDANT, TREE_POSITION_DISCONNECTED, TREE_POSITION_EQUIVALENT, TREE_POSITION_FOLLOWING, TREE_POSITION_PRECEDING, TREE_POSITION_SAME_NODE
 
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
 org.w3c.dom.Node cloneNode(boolean deep)
          Deep-clone a document, including fixing ownerDoc for the cloned children.
 void close()
           
 org.w3c.dom.Attr createAttribute(java.lang.String name)
          Creates an Attribute having this Document as its OwnerDoc.
 org.w3c.dom.Element createElement(java.lang.String tagName)
          Creates an element of the type specified.
 org.w3c.dom.Element createElementNS(java.lang.String namespaceURI, java.lang.String qualifiedName)
          Creates an element of the given qualified name and namespace URI.
 org.w3c.dom.Element createElementNS(java.lang.String namespaceURI, java.lang.String qualifiedName, java.lang.String localpart)
          Xerces-specific constructor.
 org.w3c.dom.html.HTMLCollection getAnchors()
           
 org.w3c.dom.html.HTMLCollection getApplets()
           
 org.w3c.dom.html.HTMLElement getBody()
           
 java.lang.String getCookie()
           
 org.w3c.dom.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()
           
 org.w3c.dom.Element getElementById(java.lang.String elementId)
          Returns the Element whose ID is given by elementId.
 org.w3c.dom.NodeList getElementsByName(java.lang.String elementName)
           
 org.w3c.dom.NodeList getElementsByTagName(java.lang.String tagName)
          Returns a NodeList of all the Elements with a given tag name in the order in which they are encountered in a preorder traversal of the Document tree.
 org.w3c.dom.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 are encountered in a preorder traversal of the Document tree.
 org.w3c.dom.html.HTMLCollection getForms()
           
 org.w3c.dom.html.HTMLElement getHead()
          Obtains the <HEAD> element in the document, creating one if does not exist before.
 org.w3c.dom.html.HTMLCollection getImages()
           
 org.w3c.dom.html.HTMLCollection getLinks()
           
 java.lang.String getReferrer()
           
 java.lang.String getTitle()
           
 java.lang.String getURL()
           
 void open()
           
 void setBody(org.w3c.dom.html.HTMLElement newBody)
           
 void setCookie(java.lang.String cookie)
           
 void setTitle(java.lang.String newTitle)
           
 void write(java.lang.String text)
           
 void writeln(java.lang.String text)
           
 
Methods inherited from class org.apache.xerces.dom.DocumentImpl
addEventListener, copyEventListeners, createEvent, createNodeIterator, createNodeIterator, createRange, createTreeWalker, createTreeWalker, dispatchAggregateEvents, dispatchAggregateEvents, dispatchEvent, dispatchEventToSubtree, getEventListeners, getImplementation, removeEventListener, saveEnclosingAttr, setEventListeners
 
Methods inherited from class org.apache.xerces.dom.CoreDocumentImpl
abort, adoptNode, changed, changes, checkDOMNSErr, checkNamespaceWF, checkQName, clearIdentifiers, clone, cloneNode, createAttributeNS, createAttributeNS, createCDATASection, createComment, createDocumentFragment, createDocumentType, createElementDefinition, createEntity, createEntityReference, createNotation, createProcessingInstruction, createTextNode, getAsync, getBaseURI, getDoctype, getDocumentURI, getDomConfig, getErrorChecking, getFeature, getIdentifier, getIdentifiers, getInputEncoding, getNodeName, getNodeNumber, getNodeNumber, getNodeType, getOwnerDocument, getStrictErrorChecking, getTextContent, getUserData, getUserData, getXmlEncoding, getXmlStandalone, getXmlVersion, importNode, insertBefore, isKidOK, isValidQName, isXMLName, load, loadXML, normalizeDocument, putIdentifier, removeChild, removeIdentifier, renameNode, replaceChild, saveXML, setAsync, setDocumentURI, setErrorChecking, setInputEncoding, setStrictErrorChecking, setTextContent, setUserData, setUserData, setXmlEncoding, setXmlStandalone, setXmlVersion
 
Methods inherited from class org.apache.xerces.dom.ParentNode
getChildNodes, getChildNodesUnoptimized, getFirstChild, getLastChild, getLength, hasChildNodes, isEqualNode, item, normalize, setReadOnly, synchronizeChildren
 
Methods inherited from class org.apache.xerces.dom.ChildNode
getNextSibling, getParentNode, getPreviousSibling
 
Methods inherited from class org.apache.xerces.dom.NodeImpl
addEventListener, appendChild, compareDocumentPosition, compareTreePosition, dispatchEvent, getAttributes, getContainer, getLocalName, getNamespaceURI, getNodeValue, getPrefix, getReadOnly, getUserData, getUserData, hasAttributes, isDefaultNamespace, isSameNode, isSupported, lookupNamespaceURI, lookupPrefix, needsSyncChildren, removeEventListener, setNodeValue, setPrefix, setUserData, setUserData, synchronizeData, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.w3c.dom.Document
createAttributeNS, createCDATASection, createComment, createDocumentFragment, createEntityReference, createProcessingInstruction, createTextNode, getDoctype, getImplementation, importNode
 
Methods inherited from interface org.w3c.dom.Node
appendChild, getAttributes, getChildNodes, getFirstChild, getLastChild, getLocalName, getNamespaceURI, getNextSibling, getNodeName, getNodeType, getNodeValue, getOwnerDocument, getParentNode, getPrefix, getPreviousSibling, hasAttributes, hasChildNodes, insertBefore, isSupported, normalize, removeChild, replaceChild, setNodeValue, setPrefix
 

Constructor Detail

HTMLDocumentImpl

public HTMLDocumentImpl()
Method Detail

getDocumentElement

public org.w3c.dom.Element getDocumentElement()
Description copied from interface: org.w3c.dom.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".
Specified by:
getDocumentElement in interface org.w3c.dom.Document
Overrides:
getDocumentElement in class org.apache.xerces.dom.CoreDocumentImpl

getHead

public org.w3c.dom.html.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()
Specified by:
getTitle in interface org.w3c.dom.html.HTMLDocument

setTitle

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

getBody

public org.w3c.dom.html.HTMLElement getBody()
Specified by:
getBody in interface org.w3c.dom.html.HTMLDocument

setBody

public void setBody(org.w3c.dom.html.HTMLElement newBody)
Specified by:
setBody in interface org.w3c.dom.html.HTMLDocument

getElementById

public org.w3c.dom.Element getElementById(java.lang.String elementId)
Description copied from interface: org.w3c.dom.Document
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. The DOM implementation must have information that says which attributes are of type ID. Attributes with the name "ID" are not of type ID unless so defined. Implementations that do not know whether attributes are of type ID or not are expected to return null.
Specified by:
getElementById in interface org.w3c.dom.html.HTMLDocument
Overrides:
getElementById in class org.apache.xerces.dom.CoreDocumentImpl
Following copied from interface: org.w3c.dom.Document
Parameters:
elementId - The unique id value for an element.
Returns:
The matching element.

getElementsByName

public org.w3c.dom.NodeList getElementsByName(java.lang.String elementName)
Specified by:
getElementsByName in interface org.w3c.dom.html.HTMLDocument

getElementsByTagName

public final org.w3c.dom.NodeList getElementsByTagName(java.lang.String tagName)
Description copied from interface: org.w3c.dom.Document
Returns a NodeList of all the Elements with a given tag name in the order in which they are encountered in a preorder traversal of the Document tree.
Specified by:
getElementsByTagName in interface org.w3c.dom.Document
Overrides:
getElementsByTagName in class org.apache.xerces.dom.CoreDocumentImpl
Following copied from interface: org.w3c.dom.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 org.w3c.dom.NodeList getElementsByTagNameNS(java.lang.String namespaceURI,
                                                         java.lang.String localName)
Description copied from interface: org.w3c.dom.Document
Returns a NodeList of all the Elements with a given local name and namespace URI in the order in which they are encountered in a preorder traversal of the Document tree.
Specified by:
getElementsByTagNameNS in interface org.w3c.dom.Document
Overrides:
getElementsByTagNameNS in class org.apache.xerces.dom.CoreDocumentImpl
Following copied from interface: org.w3c.dom.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 org.w3c.dom.Element createElementNS(java.lang.String namespaceURI,
                                           java.lang.String qualifiedName,
                                           java.lang.String localpart)
                                    throws org.w3c.dom.DOMException
Xerces-specific constructor. "localName" is passed in, so we don't need to create a new String for it.
Overrides:
createElementNS in class org.apache.xerces.dom.CoreDocumentImpl
Parameters:
namespaceURI - The namespace URI of the element to create.
qualifiedName - The qualified name of the element type to instantiate.
localName - The local name of the element to instantiate.
Returns:
Element A new Element object with the following attributes:
Throws:
org.w3c.dom.DOMException - INVALID_CHARACTER_ERR: Raised if the specified name contains an invalid character.

createElementNS

public org.w3c.dom.Element createElementNS(java.lang.String namespaceURI,
                                           java.lang.String qualifiedName)
Description copied from interface: org.w3c.dom.Document
Creates an element of the given qualified name and namespace URI.
Specified by:
createElementNS in interface org.w3c.dom.Document
Overrides:
createElementNS in class org.apache.xerces.dom.CoreDocumentImpl
Following copied from interface: org.w3c.dom.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:
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
Throws:
org.w3c.dom.DOMException - INVALID_CHARACTER_ERR: Raised if the specified qualified name contains an illegal character, per the XML 1.0 specification .
NAMESPACE_ERR: Raised if the qualifiedName is malformed per the Namespaces in XML specification, if the qualifiedName has a prefix and the namespaceURI is null, or if the qualifiedName has a prefix that is "xml" and the namespaceURI is different from " http://www.w3.org/XML/1998/namespace" .
NOT_SUPPORTED_ERR: Always thrown if the current document does not support the "XML" feature, since namespaces were defined by XML.

createElement

public org.w3c.dom.Element createElement(java.lang.String tagName)
                                  throws org.w3c.dom.DOMException
Description copied from interface: org.w3c.dom.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.
Specified by:
createElement in interface org.w3c.dom.Document
Overrides:
createElement in class org.apache.xerces.dom.CoreDocumentImpl
Following copied from interface: org.w3c.dom.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:
org.w3c.dom.DOMException - INVALID_CHARACTER_ERR: Raised if the specified name contains an illegal character.

createAttribute

public org.w3c.dom.Attr createAttribute(java.lang.String name)
                                 throws org.w3c.dom.DOMException
Creates an Attribute having this Document as its OwnerDoc. Overrides CoreDocumentImpl.createAttribute(java.lang.String) and returns and attribute whose name is lower case.
Specified by:
createAttribute in interface org.w3c.dom.Document
Overrides:
createAttribute in class org.apache.xerces.dom.CoreDocumentImpl
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()
Specified by:
getReferrer in interface org.w3c.dom.html.HTMLDocument

getDomain

public java.lang.String getDomain()
Specified by:
getDomain in interface org.w3c.dom.html.HTMLDocument

getURL

public java.lang.String getURL()
Specified by:
getURL in interface org.w3c.dom.html.HTMLDocument

getCookie

public java.lang.String getCookie()
Specified by:
getCookie in interface org.w3c.dom.html.HTMLDocument

setCookie

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

getImages

public org.w3c.dom.html.HTMLCollection getImages()
Specified by:
getImages in interface org.w3c.dom.html.HTMLDocument

getApplets

public org.w3c.dom.html.HTMLCollection getApplets()
Specified by:
getApplets in interface org.w3c.dom.html.HTMLDocument

getLinks

public org.w3c.dom.html.HTMLCollection getLinks()
Specified by:
getLinks in interface org.w3c.dom.html.HTMLDocument

getForms

public org.w3c.dom.html.HTMLCollection getForms()
Specified by:
getForms in interface org.w3c.dom.html.HTMLDocument

getAnchors

public org.w3c.dom.html.HTMLCollection getAnchors()
Specified by:
getAnchors in interface org.w3c.dom.html.HTMLDocument

open

public void open()
Specified by:
open in interface org.w3c.dom.html.HTMLDocument

close

public void close()
Specified by:
close in interface org.w3c.dom.html.HTMLDocument

write

public void write(java.lang.String text)
Specified by:
write in interface org.w3c.dom.html.HTMLDocument

writeln

public void writeln(java.lang.String text)
Specified by:
writeln in interface org.w3c.dom.html.HTMLDocument

cloneNode

public org.w3c.dom.Node cloneNode(boolean deep)
Description copied from class: org.apache.xerces.dom.DocumentImpl
Deep-clone a document, including fixing ownerDoc for the cloned children. Note that this requires bypassing the WRONG_DOCUMENT_ERR protection. I've chosen to implement it by calling importNode which is DOM Level 2.
Specified by:
cloneNode in interface org.w3c.dom.Node
Overrides:
cloneNode in class org.apache.xerces.dom.DocumentImpl
Following copied from class: org.apache.xerces.dom.DocumentImpl
Parameters:
deep - boolean, iff true replicate children
Returns:
org.w3c.dom.Node


Copyright © 1999-2004 Apache XML Project. All Rights Reserved.