Package org.htmlunit.javascript.host.dom
Class Node
- java.lang.Object
-
- org.htmlunit.corejs.javascript.ScriptableObject
-
- org.htmlunit.javascript.HtmlUnitScriptable
-
- org.htmlunit.javascript.host.event.EventTarget
-
- org.htmlunit.javascript.host.dom.Node
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable,org.htmlunit.corejs.javascript.ConstProperties,org.htmlunit.corejs.javascript.debug.DebuggableObject,org.htmlunit.corejs.javascript.Scriptable,org.htmlunit.corejs.javascript.SymbolScriptable
- Direct Known Subclasses:
Attr,CharacterData,Document,DocumentFragment,DocumentType,Element
public class Node extends EventTarget
The JavaScript objectNodewhich is the base class for all DOM objects. This will typically wrap an instance ofDomNode.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static intATTRIBUTE_NODEstatic intCDATA_SECTION_NODEprivate NodeListchildNodes_"Live" child nodes collection; has to be a member to have equality (==) working.static intCOMMENT_NODEstatic intDOCUMENT_FRAGMENT_NODEstatic intDOCUMENT_NODEstatic intDOCUMENT_POSITION_CONTAINED_BYstatic intDOCUMENT_POSITION_CONTAINSstatic intDOCUMENT_POSITION_DISCONNECTEDstatic intDOCUMENT_POSITION_FOLLOWINGstatic intDOCUMENT_POSITION_IMPLEMENTATION_SPECIFICstatic intDOCUMENT_POSITION_PRECEDINGstatic intDOCUMENT_TYPE_NODEstatic intELEMENT_NODEstatic intENTITY_NODEstatic intENTITY_REFERENCE_NODEstatic intNOTATION_NODEstatic intPROCESSING_INSTRUCTION_NODEstatic intTEXT_NODE
-
Constructor Summary
Constructors Constructor Description Node()Creates an instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected static voidafter(org.htmlunit.corejs.javascript.Context context, org.htmlunit.corejs.javascript.Scriptable thisObj, java.lang.Object[] args, org.htmlunit.corejs.javascript.Function function)Inserts a set of Node or DOMString objects in the children list of this ChildNode's parent, just after this ChildNode.protected static voidappend(org.htmlunit.corejs.javascript.Context context, org.htmlunit.corejs.javascript.Scriptable thisObj, java.lang.Object[] args, org.htmlunit.corejs.javascript.Function function)Inserts a set of Node objects or string objects after the last child of the Element.java.lang.ObjectappendChild(java.lang.Object childObject)Adds a DOM node to the node.protected static voidbefore(org.htmlunit.corejs.javascript.Context context, org.htmlunit.corejs.javascript.Scriptable thisObj, java.lang.Object[] args, org.htmlunit.corejs.javascript.Function function)Inserts a set of Node or DOMString objects in the children list of this ChildNode's parent, just before this ChildNode.java.lang.ObjectcloneNode(boolean deep)Clones this node.intcompareDocumentPosition(java.lang.Object node)Compares the positions of this node and the provided node within the document.booleancontains(java.lang.Object element)Checks whether the given element is contained within this object.java.lang.ObjectgetAttributes()Returns the attributes of this XML element.java.lang.StringgetBaseURI()Returns the Base URI as a string.protected intgetChildElementCount()Returns the current number of child elements.NodeListgetChildNodes()Returns the child nodes of the current element.protected HTMLCollectiongetChildren()Gets the children of the current node.NodegetFirstChild()Gets the JavaScript propertyfirstChildfor the node that contains the current node.protected ElementgetFirstElementChild()Returns the first element child.protected NodegetJavaScriptNode(DomNode domNode)Gets the JavaScript node for a given DomNode.NodegetLastChild()Gets the JavaScript propertylastChildfor the node that contains the current node.protected ElementgetLastElementChild()Returns the last element child.java.lang.ObjectgetLocalName()Returns the local name of this attribute.java.lang.ObjectgetNamespaceURI()Returns the URI that identifies an XML namespace.NodegetNextSibling()Gets the JavaScript propertynextSiblingfor the node that contains the current node.java.lang.StringgetNodeName()Gets the JavaScript propertynodeNamefor the current node.intgetNodeType()Gets the JavaScript propertynodeTypefor the current node.java.lang.StringgetNodeValue()Gets the JavaScript propertynodeValuefor the current node.HtmlUnitScriptablegetOwnerDocument()Returns the owner document.NodegetParent()Returns this node's parent node.ElementgetParentElement()Gets the JavaScript propertyparentElement.java.lang.ObjectgetParentNode()Gets the JavaScript propertyparentNodefor the node that contains the current node.java.lang.ObjectgetPrefix()Returns the namespace prefix.NodegetPreviousSibling()Gets the JavaScript propertypreviousSiblingfor the node that contains the current node.java.lang.ObjectgetRootNode()Returns the owner document.java.lang.StringgetTextContent()Gets the textContent attribute.booleanhasAttributes()Returns true when the current element has any attributes or not.booleanhasChildNodes()Returns whether this node has any children.private static voidinitInlineFrameIfNeeded(DomNode childDomNode)If we have added a new iframe that had no source attribute, we have to take care the 'onload' handler is triggered.static java.lang.ObjectinsertBefore(org.htmlunit.corejs.javascript.Context context, org.htmlunit.corejs.javascript.Scriptable scope, org.htmlunit.corejs.javascript.Scriptable thisObj, java.lang.Object[] args, org.htmlunit.corejs.javascript.Function function)Add a DOM node as a child to this node before the referenced node.protected java.lang.ObjectinsertBeforeImpl(java.lang.Object[] args)Add a DOM node as a child to this node before the referenced node.booleanisEqualNode(Node other)Check if 2 nodes are equals.private static booleanisNodeInsertable(Node childObject)Indicates if the node can be inserted.booleanisSameNode(java.lang.Object other)This method provides a way to determine whether two Node references returned by the implementation reference the same object.voidjsConstructor()JavaScript constructor.voidnormalize()Merges adjacent TextNode objects to produce a normalized document object model.protected static voidprepend(org.htmlunit.corejs.javascript.Context context, org.htmlunit.corejs.javascript.Scriptable thisObj, java.lang.Object[] args, org.htmlunit.corejs.javascript.Function function)Inserts a set of Node objects or string objects before the first child of the Element.protected voidremove()Removes the DOM node from its parent.java.lang.ObjectremoveChild(java.lang.Object childObject)Removes a DOM node from this node.java.lang.ObjectreplaceChild(java.lang.Object newChildObject, java.lang.Object oldChildObject)Replaces a child DOM node with another DOM node.protected static voidreplaceChildren(org.htmlunit.corejs.javascript.Context context, org.htmlunit.corejs.javascript.Scriptable thisObj, java.lang.Object[] args, org.htmlunit.corejs.javascript.Function function)Replaces the existing children of a Node with a specified new set of children.protected static voidreplaceWith(org.htmlunit.corejs.javascript.Context context, org.htmlunit.corejs.javascript.Scriptable thisObj, java.lang.Object[] args, org.htmlunit.corejs.javascript.Function function)Replaces this ChildNode in the children list of its parent with a set of Node or DOMString objects.voidsetNodeValue(java.lang.String newValue)Sets the JavaScript propertynodeValuefor the current node.voidsetTextContent(java.lang.Object value)Replace all children elements of this element with the supplied value.private static NodetoNodeOrTextNode(Node thisObj, java.lang.Object obj)-
Methods inherited from class org.htmlunit.javascript.host.event.EventTarget
addEventListener, clearEventListenersContainer, dispatchEvent, executeEventLocally, fireEvent, getEventHandler, getEventListenersContainer, hasEventHandlers, isEventHandlerOnWindow, removeEventListener, setEventHandler
-
Methods inherited from class org.htmlunit.javascript.HtmlUnitScriptable
clone, equivalentValues, get, getBrowserVersion, getClassName, getDefaultValue, getDomNodeOrDie, getDomNodeOrNull, getPrototype, getScriptableFor, getStartingScope, getWindow, getWindow, getWithPreemption, has, hasInstance, initParentScope, makeScriptableFor, put, setClassName, setDomNode, setDomNode, setParentScope, setupPromise, setupRejectedPromise
-
Methods inherited from class org.htmlunit.corejs.javascript.ScriptableObject
applyDescriptorToAttributeBitset, associateValue, avoidObjectDetection, buildDataDescriptor, callMethod, callMethod, checkPropertyChange, checkPropertyDefinition, defineClass, defineClass, defineClass, defineConst, defineConstProperty, defineFunctionProperties, defineOwnProperties, defineOwnProperty, defineOwnProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, delete, delete, delete, deleteProperty, deleteProperty, deleteProperty, ensureScriptable, ensureScriptableObject, ensureSymbolScriptable, get, get, get, getAllIds, getArrayPrototype, getAssociatedValue, getAttributes, getAttributes, getAttributes, getAttributes, getAttributes, getClassPrototype, getDefaultValue, getExternalArrayData, getExternalArrayLength, getFunctionPrototype, getGeneratorFunctionPrototype, getGetterOrSetter, getGetterOrSetter, getIds, getObjectPrototype, getOwnPropertyDescriptor, getParentScope, getProperty, getProperty, getProperty, getPropertyIds, getPrototype, getTopLevelScope, getTopScopeValue, getTypedProperty, getTypedProperty, getTypeOf, has, has, hasProperty, hasProperty, hasProperty, isAccessorDescriptor, isConst, isDataDescriptor, isEmpty, isExtensible, isFalse, isGenericDescriptor, isGetterOrSetter, isSealed, isTrue, preventExtensions, put, put, putConst, putConstProperty, putProperty, putProperty, putProperty, querySlot, redefineProperty, sameValue, sealObject, setAttributes, setAttributes, setAttributes, setAttributes, setAttributes, setCommonDescriptorProperties, setExternalArrayData, setGetterOrSetter, setPrototype, size
-
-
-
-
Field Detail
-
ELEMENT_NODE
public static final int ELEMENT_NODE
- See Also:
Node.ELEMENT_NODE, Constant Field Values
-
ATTRIBUTE_NODE
public static final int ATTRIBUTE_NODE
- See Also:
Node.ATTRIBUTE_NODE, Constant Field Values
-
TEXT_NODE
public static final int TEXT_NODE
- See Also:
Node.TEXT_NODE, Constant Field Values
-
CDATA_SECTION_NODE
public static final int CDATA_SECTION_NODE
- See Also:
Node.CDATA_SECTION_NODE, Constant Field Values
-
ENTITY_REFERENCE_NODE
public static final int ENTITY_REFERENCE_NODE
- See Also:
Node.ENTITY_REFERENCE_NODE, Constant Field Values
-
ENTITY_NODE
public static final int ENTITY_NODE
- See Also:
Node.ENTITY_NODE, Constant Field Values
-
PROCESSING_INSTRUCTION_NODE
public static final int PROCESSING_INSTRUCTION_NODE
- See Also:
Node.PROCESSING_INSTRUCTION_NODE, Constant Field Values
-
COMMENT_NODE
public static final int COMMENT_NODE
- See Also:
Node.COMMENT_NODE, Constant Field Values
-
DOCUMENT_NODE
public static final int DOCUMENT_NODE
- See Also:
Node.DOCUMENT_NODE, Constant Field Values
-
DOCUMENT_TYPE_NODE
public static final int DOCUMENT_TYPE_NODE
- See Also:
Node.DOCUMENT_TYPE_NODE, Constant Field Values
-
DOCUMENT_FRAGMENT_NODE
public static final int DOCUMENT_FRAGMENT_NODE
- See Also:
Node.DOCUMENT_FRAGMENT_NODE, Constant Field Values
-
NOTATION_NODE
public static final int NOTATION_NODE
- See Also:
Node.NOTATION_NODE, Constant Field Values
-
DOCUMENT_POSITION_DISCONNECTED
public static final int DOCUMENT_POSITION_DISCONNECTED
- See Also:
Node.DOCUMENT_POSITION_DISCONNECTED, Constant Field Values
-
DOCUMENT_POSITION_PRECEDING
public static final int DOCUMENT_POSITION_PRECEDING
- See Also:
Node.DOCUMENT_POSITION_PRECEDING, Constant Field Values
-
DOCUMENT_POSITION_FOLLOWING
public static final int DOCUMENT_POSITION_FOLLOWING
- See Also:
Node.DOCUMENT_POSITION_FOLLOWING, Constant Field Values
-
DOCUMENT_POSITION_CONTAINS
public static final int DOCUMENT_POSITION_CONTAINS
- See Also:
Node.DOCUMENT_POSITION_CONTAINS, Constant Field Values
-
DOCUMENT_POSITION_CONTAINED_BY
public static final int DOCUMENT_POSITION_CONTAINED_BY
- See Also:
Node.DOCUMENT_POSITION_CONTAINED_BY, Constant Field Values
-
DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC
public static final int DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC
- See Also:
Node.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC, Constant Field Values
-
childNodes_
private NodeList childNodes_
"Live" child nodes collection; has to be a member to have equality (==) working.
-
-
Method Detail
-
jsConstructor
public void jsConstructor()
JavaScript constructor.- Overrides:
jsConstructorin classEventTarget
-
getNodeType
public int getNodeType()
Gets the JavaScript propertynodeTypefor the current node.- Returns:
- the node type
-
getNodeName
public java.lang.String getNodeName()
Gets the JavaScript propertynodeNamefor the current node.- Returns:
- the node name
-
getNodeValue
public java.lang.String getNodeValue()
Gets the JavaScript propertynodeValuefor the current node.- Returns:
- the node value
-
setNodeValue
public void setNodeValue(java.lang.String newValue)
Sets the JavaScript propertynodeValuefor the current node.- Parameters:
newValue- the new node value
-
appendChild
public java.lang.Object appendChild(java.lang.Object childObject)
Adds a DOM node to the node.- Parameters:
childObject- the node to add to this node- Returns:
- the newly added child node
-
initInlineFrameIfNeeded
private static void initInlineFrameIfNeeded(DomNode childDomNode)
If we have added a new iframe that had no source attribute, we have to take care the 'onload' handler is triggered.
-
insertBefore
public static java.lang.Object insertBefore(org.htmlunit.corejs.javascript.Context context, org.htmlunit.corejs.javascript.Scriptable scope, org.htmlunit.corejs.javascript.Scriptable thisObj, java.lang.Object[] args, org.htmlunit.corejs.javascript.Function function)Add a DOM node as a child to this node before the referenced node. If the referenced node is null, append to the end.- Parameters:
context- the JavaScript contextscope- the scopethisObj- the scriptableargs- the arguments passed into the methodfunction- the function- Returns:
- the newly added child node
-
insertBeforeImpl
protected java.lang.Object insertBeforeImpl(java.lang.Object[] args)
Add a DOM node as a child to this node before the referenced node. If the referenced node is null, append to the end.- Parameters:
args- the arguments- Returns:
- the newly added child node
-
isNodeInsertable
private static boolean isNodeInsertable(Node childObject)
Indicates if the node can be inserted.- Parameters:
childObject- the node- Returns:
falseif it is not allowed here
-
remove
protected void remove()
Removes the DOM node from its parent.- See Also:
- MDN documentation
-
removeChild
public java.lang.Object removeChild(java.lang.Object childObject)
Removes a DOM node from this node.- Parameters:
childObject- the node to remove from this node- Returns:
- the removed child node
-
replaceChild
public java.lang.Object replaceChild(java.lang.Object newChildObject, java.lang.Object oldChildObject)Replaces a child DOM node with another DOM node.- Parameters:
newChildObject- the node to add as a child of this nodeoldChildObject- the node to remove as a child of this node- Returns:
- the removed child node
-
cloneNode
public java.lang.Object cloneNode(boolean deep)
Clones this node.- Parameters:
deep- iftrue, recursively clones all descendants- Returns:
- the newly cloned node
-
isEqualNode
public boolean isEqualNode(Node other)
Check if 2 nodes are equals. For detail specifications- Parameters:
other- the node to compare with- Returns:
- true or false
- See Also:
- concept-node-equals
-
isSameNode
public boolean isSameNode(java.lang.Object other)
This method provides a way to determine whether two Node references returned by the implementation reference the same object. When two Node references are references to the same object, even if through a proxy, the references may be used completely interchangeably, such that all attributes have the same values and calling the same DOM method on either reference always has exactly the same effect.- Parameters:
other- the node to test against- Returns:
- whether this node is the same node as the given one
-
hasChildNodes
public boolean hasChildNodes()
Returns whether this node has any children.- Returns:
- boolean true if this node has any children, false otherwise
-
getChildNodes
public NodeList getChildNodes()
Returns the child nodes of the current element.- Returns:
- the child nodes of the current element
-
getParent
public final Node getParent()
Returns this node's parent node.- Returns:
- this node's parent node
-
getParentNode
public java.lang.Object getParentNode()
Gets the JavaScript propertyparentNodefor the node that contains the current node.- Returns:
- the parent node
-
getNextSibling
public Node getNextSibling()
Gets the JavaScript propertynextSiblingfor the node that contains the current node.- Returns:
- the next sibling node or null if the current node has no next sibling.
-
getPreviousSibling
public Node getPreviousSibling()
Gets the JavaScript propertypreviousSiblingfor the node that contains the current node.- Returns:
- the previous sibling node or null if the current node has no previous sibling.
-
getFirstChild
public Node getFirstChild()
Gets the JavaScript propertyfirstChildfor the node that contains the current node.- Returns:
- the first child node or null if the current node has no children.
-
getLastChild
public Node getLastChild()
Gets the JavaScript propertylastChildfor the node that contains the current node.- Returns:
- the last child node or null if the current node has no children.
-
getJavaScriptNode
protected Node getJavaScriptNode(DomNode domNode)
Gets the JavaScript node for a given DomNode.- Parameters:
domNode- the DomNode- Returns:
- the JavaScript node or null if the DomNode was null
-
getOwnerDocument
public HtmlUnitScriptable getOwnerDocument()
Returns the owner document.- Returns:
- the document
-
getRootNode
public java.lang.Object getRootNode()
Returns the owner document.- Returns:
- the document
-
compareDocumentPosition
public int compareDocumentPosition(java.lang.Object node)
Compares the positions of this node and the provided node within the document.- Parameters:
node- node object that specifies the node to check- Returns:
- how the node is positioned relatively to the reference node.
- See Also:
- DOM level 3,
Node.compareDocumentPosition(org.w3c.dom.Node)
-
normalize
public void normalize()
Merges adjacent TextNode objects to produce a normalized document object model.
-
getTextContent
public java.lang.String getTextContent()
Gets the textContent attribute.- Returns:
- the contents of this node as text
-
setTextContent
public void setTextContent(java.lang.Object value)
Replace all children elements of this element with the supplied value.- Parameters:
value- - the new value for the contents of this node
-
getParentElement
public Element getParentElement()
Gets the JavaScript propertyparentElement.- Returns:
- the parent element
- See Also:
getParentNode()
-
getAttributes
public java.lang.Object getAttributes()
Returns the attributes of this XML element.- Returns:
- the attributes of this XML element
- See Also:
- Gecko DOM Reference
-
contains
public boolean contains(java.lang.Object element)
Checks whether the given element is contained within this object.- Parameters:
element- element object that specifies the element to check- Returns:
- true if the element is contained within this object
-
getBaseURI
public java.lang.String getBaseURI()
Returns the Base URI as a string.- Returns:
- the Base URI as a string
-
hasAttributes
public boolean hasAttributes()
Returns true when the current element has any attributes or not.- Returns:
- true if an attribute is specified on this element
-
getPrefix
public java.lang.Object getPrefix()
Returns the namespace prefix.- Returns:
- the namespace prefix
-
getLocalName
public java.lang.Object getLocalName()
Returns the local name of this attribute.- Returns:
- the local name of this attribute
-
getNamespaceURI
public java.lang.Object getNamespaceURI()
Returns the URI that identifies an XML namespace.- Returns:
- the URI that identifies an XML namespace
-
getChildElementCount
protected int getChildElementCount()
Returns the current number of child elements.- Returns:
- the child element count
-
getFirstElementChild
protected Element getFirstElementChild()
Returns the first element child.- Returns:
- the first element child
-
getLastElementChild
protected Element getLastElementChild()
Returns the last element child.- Returns:
- the last element child
-
getChildren
protected HTMLCollection getChildren()
Gets the children of the current node.- Returns:
- the child at the given position
- See Also:
- MSDN documentation
-
after
protected static void after(org.htmlunit.corejs.javascript.Context context, org.htmlunit.corejs.javascript.Scriptable thisObj, java.lang.Object[] args, org.htmlunit.corejs.javascript.Function function)Inserts a set of Node or DOMString objects in the children list of this ChildNode's parent, just after this ChildNode.- Parameters:
context- the contextthisObj- this objectargs- the argumentsfunction- the function
-
append
protected static void append(org.htmlunit.corejs.javascript.Context context, org.htmlunit.corejs.javascript.Scriptable thisObj, java.lang.Object[] args, org.htmlunit.corejs.javascript.Function function)Inserts a set of Node objects or string objects after the last child of the Element. String objects are inserted as equivalent Text nodes.- Parameters:
context- the contextthisObj- this objectargs- the argumentsfunction- the function
-
prepend
protected static void prepend(org.htmlunit.corejs.javascript.Context context, org.htmlunit.corejs.javascript.Scriptable thisObj, java.lang.Object[] args, org.htmlunit.corejs.javascript.Function function)Inserts a set of Node objects or string objects before the first child of the Element. String objects are inserted as equivalent Text nodes.- Parameters:
context- the contextthisObj- this objectargs- the argumentsfunction- the function
-
replaceChildren
protected static void replaceChildren(org.htmlunit.corejs.javascript.Context context, org.htmlunit.corejs.javascript.Scriptable thisObj, java.lang.Object[] args, org.htmlunit.corejs.javascript.Function function)Replaces the existing children of a Node with a specified new set of children. These can be string or Node objects.- Parameters:
context- the contextthisObj- this objectargs- the argumentsfunction- the function
-
before
protected static void before(org.htmlunit.corejs.javascript.Context context, org.htmlunit.corejs.javascript.Scriptable thisObj, java.lang.Object[] args, org.htmlunit.corejs.javascript.Function function)Inserts a set of Node or DOMString objects in the children list of this ChildNode's parent, just before this ChildNode.- Parameters:
context- the contextthisObj- this objectargs- the argumentsfunction- the function
-
replaceWith
protected static void replaceWith(org.htmlunit.corejs.javascript.Context context, org.htmlunit.corejs.javascript.Scriptable thisObj, java.lang.Object[] args, org.htmlunit.corejs.javascript.Function function)Replaces this ChildNode in the children list of its parent with a set of Node or DOMString objects.- Parameters:
context- the contextthisObj- this objectargs- the argumentsfunction- the function
-
-