Class HTMLDocumentImpl
- All Implemented Interfaces:
Cloneable, Document, DocumentEvent, EventTarget, org.w3c.dom.html.HTMLDocument, Node, NodeList
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(Node) or Node.insertBefore(Node, 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(String)) and HTTP attribute
methods (getURL(), getCookie()).
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate HTMLCollectionImplHoldsHTMLCollectionImplobject with live collection of all anchors in document.private HTMLCollectionImplHoldsHTMLCollectionImplobject with live collection of all applets in document.private static final Class<?>[]Signature used to locate constructor of HTML element classes.private static final FastHashMap<String, HTMLDocumentImpl.ElementTypesHTMLHolder> Holds names and classes of HTML element types.private static final FastHashMap<String, HTMLDocumentImpl.ElementTypesHTMLHolder> private HTMLCollectionImplHoldsHTMLCollectionImplobject with live collection of all forms in document.private static final String[]All valid HTML5 tags without deprecated elements https://www.tutorialrepublic.com/html-reference/html5-tags.phpprivate HTMLCollectionImplHoldsHTMLCollectionImplobject with live collection of all images in document.private HTMLCollectionImplHoldsHTMLCollectionImplobject with live collection of all links in document.private StringWriterHolds string writer used by direct manipulation operation (open().Fields inherited from class CoreDocumentImpl
allowGrammarAccess, changes, errorCheckingFields inherited from class ParentNode
firstChild, fNodeListCache, ownerDocumentFields inherited from class ChildNode
nextSibling_, previousSibling_Fields inherited from class NodeImpl
DOCUMENT_POSITION_CONTAINS, DOCUMENT_POSITION_DISCONNECTED, DOCUMENT_POSITION_FOLLOWING, DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC, DOCUMENT_POSITION_IS_CONTAINED, DOCUMENT_POSITION_PRECEDING, FIRSTCHILD, HASSTRING, ID, NORMALIZED, OWNED, ownerNode_, READONLY, SPECIFIED, SYNCCHILDRENFields inherited from interface Node
ATTRIBUTE_NODE, CDATA_SECTION_NODE, COMMENT_NODE, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_POSITION_CONTAINED_BY, DOCUMENT_POSITION_CONTAINS, DOCUMENT_POSITION_DISCONNECTED, DOCUMENT_POSITION_FOLLOWING, DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC, DOCUMENT_POSITION_PRECEDING, DOCUMENT_TYPE_NODE, ELEMENT_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE, NOTATION_NODE, PROCESSING_INSTRUCTION_NODE, TEXT_NODE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleancanRenameElements(String newNamespaceURI, String newNodeName, ElementImpl el) cloneNode(boolean deep) Deep-clone a document, including fixing ownerDoc for the cloned children.voidclose()createAttribute(String name) Creates an Attribute having this Document as its OwnerDoc.createElement(String tagName) Factory method; creates an Element having this Document as its OwnerDoc.createElementNS(String namespaceURI, String qualifiedname) Introduced in DOM Level 2.createElementNS(String namespaceURI, String qualifiedName, String localpart) Xerces-specific constructor.org.w3c.dom.html.HTMLCollectionorg.w3c.dom.html.HTMLCollectionorg.w3c.dom.html.HTMLElementgetBody()Convenience method, allowing direct access to the child node which is considered the root of the actual document content.getElementById(String elementId) Introduced in DOM Level 2 Returns the Element whose ID is given by elementId.private ElementgetElementById(String elementId, Node node) Recursive method retreives an element by itsidattribute.getElementsByName(String elementname) final NodeListgetElementsByTagName(String tagName) Return a live collection of all descendant Elements (not just immediate children) having the specified tag name.final NodeListgetElementsByTagNameNS(String namespaceURI, String localName) Introduced in DOM Level 2.org.w3c.dom.html.HTMLCollectiongetForms()org.w3c.dom.html.HTMLElementgetHead()Obtains the <HEAD> element in the document, creating one if does not exist before.org.w3c.dom.html.HTMLCollectionorg.w3c.dom.html.HTMLCollectiongetLinks()getTitle()getURL()voidopen()voidsetBody(org.w3c.dom.html.HTMLElement newBody) voidvoidvoidvoidMethods inherited from class DocumentImpl
createEvent, getImplementationMethods inherited from class CoreDocumentImpl
addEventListener, adoptNode, changed, changes, checkDOMNSErr, checkNamespaceWF, checkQName, clearIdentifiers, clone, cloneNode, copyEventListeners, createAttributeNS, createAttributeNS, createCDATASection, createComment, createDocumentFragment, createDocumentType, createEntity, createEntityReference, createProcessingInstruction, createTextNode, getBaseURI, getDoctype, getDocumentURI, getDomConfig, getErrorChecking, getIdentifier, getInputEncoding, getNodeName, getNodeNumber, getNodeNumber, getNodeType, getOwnerDocument, getStrictErrorChecking, getTextContent, getXmlEncoding, getXmlStandalone, getXmlVersion, importNode, insertBefore, isKidOK, isValidQName, isXMLName, normalizeDocument, putIdentifier, removeChild, removeEventListener, removeIdentifier, renameNode, replaceChild, setDocumentURI, setErrorChecking, setInputEncoding, setStrictErrorChecking, setTextContent, setXmlEncoding, setXmlStandalone, setXmlVersion, undeferChildrenMethods inherited from class ParentNode
getChildNodes, getChildNodesUnoptimized, getFirstChild, getLastChild, getLength, hasChildNodes, isEqualNode, item, setOwnerDocument, synchronizeChildrenMethods inherited from class ChildNode
getNextSibling, getParentNode, getPreviousSiblingMethods inherited from class NodeImpl
addEventListener, appendChild, compareDocumentPosition, dispatchEvent, getAttributes, getFeature, getLocalName, getNamespaceURI, getNodeValue, getPrefix, getUserData, hasAttributes, isDefaultNamespace, isSameNode, isSupported, lookupNamespaceURI, lookupPrefix, needsSyncChildren, normalize, removeEventListener, setNodeValue, setPrefix, setUserData, toStringMethods inherited from class Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Document
adoptNode, createAttributeNS, createCDATASection, createComment, createDocumentFragment, createEntityReference, createProcessingInstruction, createTextNode, getDoctype, getDocumentURI, getDomConfig, getImplementation, getInputEncoding, getStrictErrorChecking, getXmlEncoding, getXmlStandalone, getXmlVersion, importNode, normalizeDocument, renameNode, setDocumentURI, setStrictErrorChecking, setXmlStandalone, setXmlVersionMethods inherited from interface Node
appendChild, compareDocumentPosition, getAttributes, getBaseURI, getChildNodes, getFeature, getFirstChild, getLastChild, getLocalName, getNamespaceURI, getNextSibling, getNodeName, getNodeType, getNodeValue, getOwnerDocument, getParentNode, getPrefix, getPreviousSibling, getTextContent, getUserData, hasAttributes, hasChildNodes, insertBefore, isDefaultNamespace, isEqualNode, isSameNode, isSupported, lookupNamespaceURI, lookupPrefix, normalize, removeChild, replaceChild, setNodeValue, setPrefix, setTextContent, setUserData
-
Field Details
-
HTML5ELEMENTS
All valid HTML5 tags without deprecated elements https://www.tutorialrepublic.com/html-reference/html5-tags.php -
anchors_
HoldsHTMLCollectionImplobject with live collection of all anchors in document. This reference is on demand only once. -
forms_
HoldsHTMLCollectionImplobject with live collection of all forms in document. This reference is on demand only once. -
images_
HoldsHTMLCollectionImplobject with live collection of all images in document. This reference is on demand only once. -
links_
HoldsHTMLCollectionImplobject with live collection of all links in document. This reference is on demand only once. -
applets_
HoldsHTMLCollectionImplobject with live collection of all applets in document. This reference is on demand only once. -
writer_
Holds string writer used by direct manipulation operation (open().write(String), etc) to write new contents into the document and parse that text into a document tree. -
elementTypesHTMLLower_
private static final FastHashMap<String, HTMLDocumentImpl.ElementTypesHTMLHolder> elementTypesHTMLLower_Holds names and classes of HTML element types. When an element with a particular tag name is created, the matchingClassis used to create the element object. For example, <A> matchesHTMLAnchorElementImpl. This static table is shared across all HTML documents.- See Also:
-
elementTypesHTMLUpper_
private static final FastHashMap<String, HTMLDocumentImpl.ElementTypesHTMLHolder> elementTypesHTMLUpper_ -
elemClassSigHTML_
Signature used to locate constructor of HTML element classes. This static array is shared across all HTML documents.- See Also:
-
-
Constructor Details
-
HTMLDocumentImpl
public HTMLDocumentImpl()
-
-
Method Details
-
getDocumentElement
Description copied from class:CoreDocumentImplConvenience 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:
getDocumentElementin interfaceDocument- Overrides:
getDocumentElementin classCoreDocumentImpl
-
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 callinggetDocumentElement(). If the element does not exist, one is created.Called by
getTitle(),setTitle(String),getBody()andsetBody(HTMLElement)to assure the document has the <HEAD> element correctly placed.- Returns:
- The <HEAD> element
-
getTitle
- Specified by:
getTitlein interfaceorg.w3c.dom.html.HTMLDocument
-
setTitle
- Specified by:
setTitlein interfaceorg.w3c.dom.html.HTMLDocument
-
getBody
public org.w3c.dom.html.HTMLElement getBody()- Specified by:
getBodyin interfaceorg.w3c.dom.html.HTMLDocument
-
setBody
public void setBody(org.w3c.dom.html.HTMLElement newBody) - Specified by:
setBodyin interfaceorg.w3c.dom.html.HTMLDocument
-
getElementById
Description copied from class:CoreDocumentImplIntroduced 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:
getElementByIdin interfaceDocument- Overrides:
getElementByIdin classCoreDocumentImpl- See Also:
-
getElementsByName
-
getElementsByTagName
Description copied from class:CoreDocumentImplReturn a live collection of all descendant Elements (not just immediate children) having the specified tag name.- Specified by:
getElementsByTagNamein interfaceDocument- Overrides:
getElementsByTagNamein classCoreDocumentImpl- Parameters:
tagName- The type of Element we want to gather. "*" will be taken as a wildcard, meaning "all elements in the document."- See Also:
-
getElementsByTagNameNS
Description copied from class:CoreDocumentImplIntroduced 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:
getElementsByTagNameNSin interfaceDocument- Overrides:
getElementsByTagNameNSin classCoreDocumentImpl- 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:
createElementNSin classCoreDocumentImpl- 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
Description copied from class:CoreDocumentImplIntroduced 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:
createElementNSin interfaceDocument- Overrides:
createElementNSin classCoreDocumentImpl- 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
Description copied from class:CoreDocumentImplFactory method; creates an Element having this Document as its OwnerDoc.- Specified by:
createElementin interfaceDocument- Overrides:
createElementin classCoreDocumentImpl- 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- INVALID_NAME_ERR if the tag name is not acceptable.
-
createAttribute
Creates an Attribute having this Document as its OwnerDoc. OverridesCoreDocumentImpl.createAttribute(String)and returns and attribute whose name is lower case.- Specified by:
createAttributein interfaceDocument- Overrides:
createAttributein classCoreDocumentImpl- 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
- Specified by:
getReferrerin interfaceorg.w3c.dom.html.HTMLDocument
-
getDomain
- Specified by:
getDomainin interfaceorg.w3c.dom.html.HTMLDocument
-
getURL
- Specified by:
getURLin interfaceorg.w3c.dom.html.HTMLDocument
-
getCookie
- Specified by:
getCookiein interfaceorg.w3c.dom.html.HTMLDocument
-
setCookie
- Specified by:
setCookiein interfaceorg.w3c.dom.html.HTMLDocument
-
getImages
public org.w3c.dom.html.HTMLCollection getImages()- Specified by:
getImagesin interfaceorg.w3c.dom.html.HTMLDocument
-
getApplets
public org.w3c.dom.html.HTMLCollection getApplets()- Specified by:
getAppletsin interfaceorg.w3c.dom.html.HTMLDocument
-
getLinks
public org.w3c.dom.html.HTMLCollection getLinks()- Specified by:
getLinksin interfaceorg.w3c.dom.html.HTMLDocument
-
getForms
public org.w3c.dom.html.HTMLCollection getForms()- Specified by:
getFormsin interfaceorg.w3c.dom.html.HTMLDocument
-
getAnchors
public org.w3c.dom.html.HTMLCollection getAnchors()- Specified by:
getAnchorsin interfaceorg.w3c.dom.html.HTMLDocument
-
open
public void open()- Specified by:
openin interfaceorg.w3c.dom.html.HTMLDocument
-
close
public void close()- Specified by:
closein interfaceorg.w3c.dom.html.HTMLDocument
-
write
- Specified by:
writein interfaceorg.w3c.dom.html.HTMLDocument
-
writeln
- Specified by:
writelnin interfaceorg.w3c.dom.html.HTMLDocument
-
cloneNode
Description copied from class:DocumentImplDeep-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. 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:
cloneNodein interfaceNode- Overrides:
cloneNodein classDocumentImpl- Parameters:
deep- boolean, iff true replicate children- Returns:
- org.w3c.dom.Node
- See Also:
-
canRenameElements
- Overrides:
canRenameElementsin classCoreDocumentImpl
-
getElementById
Recursive method retreives an element by itsidattribute. Called bygetElementById(String).- Parameters:
elementId- Theidvalue to look for- Returns:
- The node in which to look for
-