Class HTMLDocumentImpl

  • All Implemented Interfaces:
    java.lang.Cloneable, org.w3c.dom.Document, org.w3c.dom.events.DocumentEvent, org.w3c.dom.events.EventTarget, org.w3c.dom.html.HTMLDocument, org.w3c.dom.Node, org.w3c.dom.NodeList

    public class HTMLDocumentImpl
    extends 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()).

    See Also:
    HTMLDocument
    • Field Detail

      • HTML5ELEMENTS

        private static final java.lang.String[] HTML5ELEMENTS
        All valid HTML5 tags without deprecated elements https://www.tutorialrepublic.com/html-reference/html5-tags.php
      • anchors_

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

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

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

        private HTMLCollectionImpl links_
        Holds HTMLCollectionImpl object with live collection of all links in document. This reference is on demand only once.
      • applets_

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

        private java.io.StringWriter writer_
        Holds string writer used by direct manipulation operation (open(). write(java.lang.String), etc) to write new contents into the document and parse that text into a document tree.
      • elemClassSigHTML_

        private static final java.lang.Class<?>[] elemClassSigHTML_
        Signature used to locate constructor of HTML element classes. This static array is shared across all HTML documents.
        See Also:
        createElement(java.lang.String)
    • Constructor Detail

      • HTMLDocumentImpl

        public HTMLDocumentImpl()
    • Method Detail

      • getDocumentElement

        public org.w3c.dom.Element getDocumentElement()
        Description copied from class: 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 org.w3c.dom.Document
        Overrides:
        getDocumentElement in class 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 class: 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 org.w3c.dom.Document
        Overrides:
        getElementById in class CoreDocumentImpl
        See Also:
        CoreDocumentImpl.getIdentifier(java.lang.String)
      • 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 class: CoreDocumentImpl
        Return a live collection of all descendant Elements (not just immediate children) having the specified tag name.
        Specified by:
        getElementsByTagName in interface org.w3c.dom.Document
        Overrides:
        getElementsByTagName in class 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 org.w3c.dom.NodeList getElementsByTagNameNS​(java.lang.String namespaceURI,
                                                                 java.lang.String localName)
        Description copied from class: 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 org.w3c.dom.Document
        Overrides:
        getElementsByTagNameNS in class 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 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 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:
        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 class: 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 org.w3c.dom.Document
        Overrides:
        createElementNS in class 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 org.w3c.dom.Element createElement​(java.lang.String tagName)
                                          throws org.w3c.dom.DOMException
        Description copied from class: CoreDocumentImpl
        Factory method; creates an Element having this Document as its OwnerDoc.
        Specified by:
        createElement in interface org.w3c.dom.Document
        Overrides:
        createElement in class 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:
        org.w3c.dom.DOMException - INVALID_NAME_ERR if the tag name is not acceptable.
      • 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 CoreDocumentImpl
        Parameters:
        name - The name of the attribute
        Returns:
        An attribute whose name is all lower case
        Throws:
        org.w3c.dom.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
      • getElementById

        private org.w3c.dom.Element getElementById​(java.lang.String elementId,
                                                   org.w3c.dom.Node node)
        Recursive method retreives an element by its id attribute. Called by getElementById(String).
        Parameters:
        elementId - The id value to look for
        Returns:
        The node in which to look for