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:
Serializable, Cloneable, Document, DocumentEvent, EventTarget, HTMLDocument, Node, NodeList, DocumentRange, DocumentTraversal

public class HTMLDocumentImpl extends org.apache.xerces.dom.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()).

INTERNAL:

Usage of this class is not supported. It may be altered or removed at any time.
Version:
$Revision: 1029415 $ $Date: 2010-10-31 22:32:22 +0530 (Sun, 31 Oct 2010) $
Author:
Assaf Arkin
See Also:
  • Constructor Details

    • HTMLDocumentImpl

      public HTMLDocumentImpl()
  • Method Details

    • getDocumentElement

      public Element getDocumentElement()
      Description copied from class: org.apache.xerces.dom.CoreDocumentImpl
      Convenience method, allowing direct access to the child node which is considered the root of the actual document content. For HTML, where it is legal to have more than one Element at the top level of the document, we pick the one with the tagName "HTML". For XML there should be only one top-level (HTML not yet supported.)
      Specified by:
      getDocumentElement in interface Document
      Overrides:
      getDocumentElement in class org.apache.xerces.dom.CoreDocumentImpl
    • 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 String getTitle()
      Specified by:
      getTitle in interface HTMLDocument
    • setTitle

      public void setTitle(String newTitle)
      Specified by:
      setTitle in interface HTMLDocument
    • getBody

      public HTMLElement getBody()
      Specified by:
      getBody in interface HTMLDocument
    • setBody

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

      public Element getElementById(String elementId)
      Description copied from class: org.apache.xerces.dom.CoreDocumentImpl
      Introduced in DOM Level 2 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.

      Note: 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 Document
      Overrides:
      getElementById in class org.apache.xerces.dom.CoreDocumentImpl
      See Also:
      • CoreDocumentImpl.getIdentifier(java.lang.String)
    • getElementsByName

      public NodeList getElementsByName(String elementName)
      Specified by:
      getElementsByName in interface HTMLDocument
    • getElementsByTagName

      public final NodeList getElementsByTagName(String tagName)
      Description copied from class: org.apache.xerces.dom.CoreDocumentImpl
      Return a live collection of all descendent Elements (not just immediate children) having the specified tag name.
      Specified by:
      getElementsByTagName in interface Document
      Overrides:
      getElementsByTagName in class org.apache.xerces.dom.CoreDocumentImpl
      Parameters:
      tagName - The type of Element we want to gather. "*" will be taken as a wildcard, meaning "all elements in the document."
      See Also:
      • DeepNodeListImpl
    • getElementsByTagNameNS

      public final NodeList getElementsByTagNameNS(String namespaceURI, String localName)
      Description copied from class: org.apache.xerces.dom.CoreDocumentImpl
      Introduced in DOM Level 2.

      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.

      Specified by:
      getElementsByTagNameNS in interface Document
      Overrides:
      getElementsByTagNameNS in class org.apache.xerces.dom.CoreDocumentImpl
      Parameters:
      namespaceURI - The namespace URI of the elements to match on. The special value "*" matches all namespaces. When it is null or an empty string, this method behaves like getElementsByTagName.
      localName - 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.
    • createElementNS

      public Element createElementNS(String namespaceURI, String qualifiedName, String localpart) throws 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.
      localpart - The local name of the element to instantiate.
      Returns:
      Element A new Element object with the following attributes:
      Throws:
      DOMException - INVALID_CHARACTER_ERR: Raised if the specified name contains an invalid character.
    • createElementNS

      public Element createElementNS(String namespaceURI, String qualifiedName)
      Description copied from class: org.apache.xerces.dom.CoreDocumentImpl
      Introduced in DOM Level 2.

      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" [Namespaces].

      Specified by:
      createElementNS in interface Document
      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.
      Returns:
      Element A new Element object with the following attributes:
    • createElement

      public Element createElement(String tagName) throws DOMException
      Description copied from class: org.apache.xerces.dom.CoreDocumentImpl
      Factory method; creates an Element having this Document as its OwnerDoc.
      Specified by:
      createElement in interface Document
      Overrides:
      createElement in class org.apache.xerces.dom.CoreDocumentImpl
      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.
      Throws:
      DOMException
    • createAttribute

      public Attr createAttribute(String name) throws 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 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
    • getReferrer

      public String getReferrer()
      Specified by:
      getReferrer in interface HTMLDocument
    • getDomain

      public String getDomain()
      Specified by:
      getDomain in interface HTMLDocument
    • getURL

      public String getURL()
      Specified by:
      getURL in interface HTMLDocument
    • getCookie

      public String getCookie()
      Specified by:
      getCookie in interface HTMLDocument
    • setCookie

      public void setCookie(String cookie)
      Specified by:
      setCookie in interface HTMLDocument
    • getImages

      public HTMLCollection getImages()
      Specified by:
      getImages in interface HTMLDocument
    • getApplets

      public HTMLCollection getApplets()
      Specified by:
      getApplets in interface HTMLDocument
    • getLinks

      public HTMLCollection getLinks()
      Specified by:
      getLinks in interface HTMLDocument
    • getForms

      public HTMLCollection getForms()
      Specified by:
      getForms in interface HTMLDocument
    • getAnchors

      public HTMLCollection getAnchors()
      Specified by:
      getAnchors in interface HTMLDocument
    • open

      public void open()
      Specified by:
      open in interface HTMLDocument
    • close

      public void close()
      Specified by:
      close in interface HTMLDocument
    • write

      public void write(String text)
      Specified by:
      write in interface HTMLDocument
    • writeln

      public void writeln(String text)
      Specified by:
      writeln in interface HTMLDocument
    • cloneNode

      public 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 Node
      Overrides:
      cloneNode in class org.apache.xerces.dom.DocumentImpl
      Parameters:
      deep - boolean, iff true replicate children
      Returns:
      org.w3c.dom.Node
      See Also:
      • Example: Cloning a Text node will copy both the node and the text it contains.

        Example: Cloning something that has children -- Element or Attr, for example -- will _not_ clone those children unless a "deep clone" has been requested. A shallow clone of an Attr node will yield an empty Attr of the same name.

        NOTE: Clones will always be read/write, even if the node being cloned is read-only, to permit applications using only the DOM API to obtain editable copies of locked portions of the tree.

    • canRenameElements

      protected boolean canRenameElements(String newNamespaceURI, String newNodeName, org.apache.xerces.dom.ElementImpl el)
      Overrides:
      canRenameElements in class org.apache.xerces.dom.CoreDocumentImpl