com.gargoylesoftware.htmlunit.javascript.host
Class Node

java.lang.Object
  extended by net.sourceforge.htmlunit.corejs.javascript.ScriptableObject
      extended by com.gargoylesoftware.htmlunit.javascript.SimpleScriptable
          extended by com.gargoylesoftware.htmlunit.javascript.host.Node
All Implemented Interfaces:
Serializable, Cloneable, net.sourceforge.htmlunit.corejs.javascript.ConstProperties, net.sourceforge.htmlunit.corejs.javascript.debug.DebuggableObject, net.sourceforge.htmlunit.corejs.javascript.Scriptable
Direct Known Subclasses:
Attr, CharacterDataImpl, DocumentFragment, DocumentType, EventNode, ProcessingInstruction

public class Node
extends SimpleScriptable

The JavaScript object "Node" which is the base class for all DOM objects. This will typically wrap an instance of DomNode.

Version:
$Revision: 9096 $
Author:
Mike Bowler, David K. Taylor, Barnaby Court, Christian Sell, George Murnock, Chris Erskine, Bruce Faulkner, Ahmed Ashour, Ronald Brill, Frank Danek
See Also:
Serialized Form

Field Summary
static short ATTRIBUTE_NODE
           
static short CDATA_SECTION_NODE
           
static short COMMENT_NODE
           
static short DOCUMENT_FRAGMENT_NODE
           
static short DOCUMENT_NODE
           
static short DOCUMENT_POSITION_CONTAINED_BY
           
static short DOCUMENT_POSITION_CONTAINS
           
static short DOCUMENT_POSITION_DISCONNECTED
           
static short DOCUMENT_POSITION_FOLLOWING
           
static short DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC
           
static short DOCUMENT_POSITION_PRECEDING
           
static short DOCUMENT_TYPE_NODE
           
static short ELEMENT_NODE
           
static short ENTITY_NODE
           
static short ENTITY_REFERENCE_NODE
           
static short NOTATION_NODE
           
static short PROCESSING_INSTRUCTION_NODE
           
static short TEXT_NODE
           
 
Fields inherited from class net.sourceforge.htmlunit.corejs.javascript.ScriptableObject
CONST, DONTENUM, EMPTY, PERMANENT, READONLY, UNINITIALIZED_CONST
 
Fields inherited from interface net.sourceforge.htmlunit.corejs.javascript.Scriptable
NOT_FOUND
 
Constructor Summary
Node()
          Creates an instance.
 
Method Summary
 void addEventListener(String type, net.sourceforge.htmlunit.corejs.javascript.Function listener, boolean useCapture)
          Allows the registration of event listeners on the event target.
 Object appendChild(Object childObject)
          Adds a DOM node to the node.
protected  net.sourceforge.htmlunit.corejs.javascript.RhinoException asJavaScriptException(DOMException exception)
          Encapsulates the given DOMException into a Rhino-compatible exception.
 boolean attachEvent(String type, net.sourceforge.htmlunit.corejs.javascript.Function listener)
          Allows the registration of event listeners on the event target.
 Object cloneNode(boolean deep)
          Clones this node.
 short compareDocumentPosition(Object node)
          Compares the positions of this node and the provided node within the document.
 boolean contains(Object element)
          Checks whether the given element is contained within this object.
 void detachEvent(String type, net.sourceforge.htmlunit.corejs.javascript.Function listener)
          Allows the removal of event listeners on the event target.
 ScriptResult executeEvent(Event event)
          Executes the event on this object only (needed for instance for onload on (i)frame tags).
 ScriptResult fireEvent(Event event)
          Fires the event on the node with capturing and bubbling phase.
static ScriptResult fireEvent(SimpleScriptable scriptable, Event event)
          Fires the event on the node with capturing and bubbling phase.
 Object getAttributes()
          Returns the attributes of this XML element.
 Object getBaseName()
          Returns the base name of this element.
 NodeList getChildNodes()
          Returns the child nodes of the current element.
 net.sourceforge.htmlunit.corejs.javascript.Function getEventHandler(String eventName)
          Returns the specified event handler.
protected  Object getEventHandlerProp(String eventName)
          Gets the property defined as event handler (not necessary a Function if something else has been set).
 Node getFirstChild()
          Gets the JavaScript property "firstChild" for the node that contains the current node.
protected  Node getJavaScriptNode(DomNode domNode)
          Gets the JavaScript node for a given DomNode.
 Node getLastChild()
          Gets the JavaScript property "lastChild" for the node that contains the current node.
 String getLocalName()
          Returns the local name of this element.
 String getNamespaceURI()
          Returns The URI that identifies an XML namespace.
 Node getNextSibling()
          Gets the JavaScript property "nextSibling" for the node that contains the current node.
 String getNodeName()
          Gets the JavaScript property "nodeName" for the current node.
 short getNodeType()
          Gets the JavaScript property "nodeType" for the current node.
 String getNodeValue()
          Gets the JavaScript property "nodeValue" for the current node.
 Object getOwnerDocument()
          Returns the owner document.
 Node getParent()
          Returns this node's parent node.
 Element getParentElement()
          Gets the JavaScript property "parentElement".
 Object getParentNode()
          Gets the JavaScript property "parentNode" for the node that contains the current node.
 String getPrefix()
          Returns the namespace prefix.
 Node getPreviousSibling()
          Gets the JavaScript property "previousSibling" for the node that contains the current node.
 String getTextContent()
          Gets the textContent attribute.
 Object getXml()
          Represents the xml content of the node and its descendants.
 boolean hasChildNodes()
          Returns whether this node has any children.
 boolean hasEventHandlers(String eventName)
          Returns true if there are any event handlers for the specified event.
static Object insertBefore(net.sourceforge.htmlunit.corejs.javascript.Context context, net.sourceforge.htmlunit.corejs.javascript.Scriptable thisObj, Object[] args, net.sourceforge.htmlunit.corejs.javascript.Function function)
          Add a DOM node as a child to this node before the referenced node.
protected  Object insertBeforeImpl(Object[] args)
          Add a DOM node as a child to this node before the referenced node.
 boolean isSameNode(Object other)
          This method provides a way to determine whether two Node references returned by the implementation reference the same object.
 void normalize()
          Merges adjacent TextNode objects to produce a normalized document object model.
 Object removeChild(Object childObject)
          Removes a DOM node from this node.
 void removeEventListener(String type, net.sourceforge.htmlunit.corejs.javascript.Function listener, boolean useCapture)
          Allows the removal of event listeners on the event target.
 Object replaceChild(Object newChildObject, Object oldChildObject)
          Replaces a child DOM node with another DOM node.
 void setEventHandler(String eventName, net.sourceforge.htmlunit.corejs.javascript.Function eventHandler)
          Defines an event handler.
protected  void setEventHandlerProp(String eventName, Object value)
          Defines an event handler (or maybe any other object).
 void setNodeValue(String newValue)
          Sets the JavaScript property "nodeValue" for the current node.
 void setTextContent(Object value)
          Replace all children elements of this element with the supplied value.
 
Methods inherited from class com.gargoylesoftware.htmlunit.javascript.SimpleScriptable
clone, defineFunctionProperties, defineProperty, equivalentValues, get, getBrowserVersion, getClassName, getDefaultValue, getDomNodeOrDie, getDomNodeOrNull, getPrototype, getScriptableFor, getStartingScope, getTransformerScriptableFor, getWindow, getWindow, getWithPreemption, hasInstance, initParentScope, isReadOnlySettable, makeScriptableFor, setCaseSensitive, setDomNode, setDomNode, setHtmlElement, setParentScope
 
Methods inherited from class net.sourceforge.htmlunit.corejs.javascript.ScriptableObject
applyDescriptorToAttributeBitset, associateValue, avoidObjectDetection, buildDataDescriptor, callMethod, callMethod, checkPropertyChange, checkPropertyDefinition, defineClass, defineClass, defineClass, defineConst, defineConstProperty, defineOwnProperties, defineOwnProperty, defineOwnProperty, defineProperty, defineProperty, defineProperty, delete, delete, deleteProperty, deleteProperty, ensureScriptable, ensureScriptableObject, get, get, getAllIds, getArrayPrototype, getAssociatedValue, getAttributes, getAttributes, getAttributes, getAttributes, getClassPrototype, getDefaultValue, getFunctionPrototype, getGetterOrSetter, getIds, getObjectPrototype, getOwnPropertyDescriptor, getParentScope, getProperty, getProperty, getPropertyIds, getPrototype, getSlot, getTopLevelScope, getTopScopeValue, getTypedProperty, getTypedProperty, getTypeOf, has, has, hasProperty, hasProperty, isAccessorDescriptor, isConst, isDataDescriptor, isEmpty, isExtensible, isFalse, isGenericDescriptor, isGetterOrSetter, isSealed, isTrue, preventExtensions, put, put, putConst, putConstProperty, putProperty, putProperty, redefineProperty, sameValue, sealObject, setAttributes, setAttributes, setAttributes, setAttributes, setGetterOrSetter, setPrototype, size
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ELEMENT_NODE

public static final short ELEMENT_NODE
See Also:
Node.ELEMENT_NODE, Constant Field Values

ATTRIBUTE_NODE

public static final short ATTRIBUTE_NODE
See Also:
Node.ATTRIBUTE_NODE, Constant Field Values

TEXT_NODE

public static final short TEXT_NODE
See Also:
Node.TEXT_NODE, Constant Field Values

CDATA_SECTION_NODE

public static final short CDATA_SECTION_NODE
See Also:
Node.CDATA_SECTION_NODE, Constant Field Values

ENTITY_REFERENCE_NODE

public static final short ENTITY_REFERENCE_NODE
See Also:
Node.ENTITY_REFERENCE_NODE, Constant Field Values

ENTITY_NODE

public static final short ENTITY_NODE
See Also:
Node.ENTITY_NODE, Constant Field Values

PROCESSING_INSTRUCTION_NODE

public static final short PROCESSING_INSTRUCTION_NODE
See Also:
Node.PROCESSING_INSTRUCTION_NODE, Constant Field Values

COMMENT_NODE

public static final short COMMENT_NODE
See Also:
Node.COMMENT_NODE, Constant Field Values

DOCUMENT_NODE

public static final short DOCUMENT_NODE
See Also:
Node.DOCUMENT_NODE, Constant Field Values

DOCUMENT_TYPE_NODE

public static final short DOCUMENT_TYPE_NODE
See Also:
Node.DOCUMENT_TYPE_NODE, Constant Field Values

DOCUMENT_FRAGMENT_NODE

public static final short DOCUMENT_FRAGMENT_NODE
See Also:
Node.DOCUMENT_FRAGMENT_NODE, Constant Field Values

NOTATION_NODE

public static final short NOTATION_NODE
See Also:
Node.NOTATION_NODE, Constant Field Values

DOCUMENT_POSITION_DISCONNECTED

public static final short DOCUMENT_POSITION_DISCONNECTED
See Also:
Node.DOCUMENT_POSITION_DISCONNECTED, Constant Field Values

DOCUMENT_POSITION_PRECEDING

public static final short DOCUMENT_POSITION_PRECEDING
See Also:
Node.DOCUMENT_POSITION_PRECEDING, Constant Field Values

DOCUMENT_POSITION_FOLLOWING

public static final short DOCUMENT_POSITION_FOLLOWING
See Also:
Node.DOCUMENT_POSITION_FOLLOWING, Constant Field Values

DOCUMENT_POSITION_CONTAINS

public static final short DOCUMENT_POSITION_CONTAINS
See Also:
Node.DOCUMENT_POSITION_CONTAINS, Constant Field Values

DOCUMENT_POSITION_CONTAINED_BY

public static final short DOCUMENT_POSITION_CONTAINED_BY
See Also:
Node.DOCUMENT_POSITION_CONTAINED_BY, Constant Field Values

DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC

public static final short DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC
See Also:
Node.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC, Constant Field Values
Constructor Detail

Node

public Node()
Creates an instance.

Method Detail

getNodeType

public short getNodeType()
Gets the JavaScript property "nodeType" for the current node.

Returns:
the node type

getNodeName

public String getNodeName()
Gets the JavaScript property "nodeName" for the current node.

Returns:
the node name

getNodeValue

public String getNodeValue()
Gets the JavaScript property "nodeValue" for the current node.

Returns:
the node value

setNodeValue

public void setNodeValue(String newValue)
Sets the JavaScript property "nodeValue" for the current node.

Parameters:
newValue - the new node value

appendChild

public Object appendChild(Object childObject)
Adds a DOM node to the node.

Parameters:
childObject - the node to add to this node
Returns:
the newly added child node

asJavaScriptException

protected net.sourceforge.htmlunit.corejs.javascript.RhinoException asJavaScriptException(DOMException exception)
Encapsulates the given DOMException into a Rhino-compatible exception.

Parameters:
exception - the exception to encapsulate
Returns:
the created exception

insertBefore

public static Object insertBefore(net.sourceforge.htmlunit.corejs.javascript.Context context,
                                  net.sourceforge.htmlunit.corejs.javascript.Scriptable thisObj,
                                  Object[] args,
                                  net.sourceforge.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 context
thisObj - the scriptable
args - the arguments passed into the method
function - the function
Returns:
the newly added child node

insertBeforeImpl

protected Object insertBeforeImpl(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

removeChild

public Object removeChild(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 Object replaceChild(Object newChildObject,
                           Object oldChildObject)
Replaces a child DOM node with another DOM node.

Parameters:
newChildObject - the node to add as a child of this node
oldChildObject - the node to remove as a child of this node
Returns:
the removed child node

cloneNode

public Object cloneNode(boolean deep)
Clones this node.

Parameters:
deep - if true, recursively clones all descendants
Returns:
the newly cloned node

isSameNode

public boolean isSameNode(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 Node getParent()
Returns this node's parent node.

Returns:
this node's parent node

getParentNode

public Object getParentNode()
Gets the JavaScript property "parentNode" for the node that contains the current node.

Returns:
the parent node

getNextSibling

public Node getNextSibling()
Gets the JavaScript property "nextSibling" for 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 property "previousSibling" for 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 property "firstChild" for 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 property "lastChild" for 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

attachEvent

public boolean attachEvent(String type,
                           net.sourceforge.htmlunit.corejs.javascript.Function listener)
Allows the registration of event listeners on the event target.

Parameters:
type - the event type to listen for (like "onclick")
listener - the event listener
Returns:
true if the listener has been added
See Also:
MSDN documentation, addEventListener(String, Function, boolean)

addEventListener

public void addEventListener(String type,
                             net.sourceforge.htmlunit.corejs.javascript.Function listener,
                             boolean useCapture)
Allows the registration of event listeners on the event target.

Parameters:
type - the event type to listen for (like "click")
listener - the event listener
useCapture - If true, indicates that the user wishes to initiate capture
See Also:
Mozilla documentation, attachEvent(String, Function)

detachEvent

public void detachEvent(String type,
                        net.sourceforge.htmlunit.corejs.javascript.Function listener)
Allows the removal of event listeners on the event target.

Parameters:
type - the event type to listen for (like "onclick")
listener - the event listener
See Also:
MSDN documentation

removeEventListener

public void removeEventListener(String type,
                                net.sourceforge.htmlunit.corejs.javascript.Function listener,
                                boolean useCapture)
Allows the removal of event listeners on the event target.

Parameters:
type - the event type to listen for (like "click")
listener - the event listener
useCapture - If true, indicates that the user wishes to initiate capture (not yet implemented)
See Also:
Mozilla documentation

executeEvent

public ScriptResult executeEvent(Event event)
Executes the event on this object only (needed for instance for onload on (i)frame tags).

Parameters:
event - the event
Returns:
the result

fireEvent

public ScriptResult fireEvent(Event event)
Fires the event on the node with capturing and bubbling phase.

Parameters:
event - the event
Returns:
the result

fireEvent

public static ScriptResult fireEvent(SimpleScriptable scriptable,
                                     Event event)
Fires the event on the node with capturing and bubbling phase.

Parameters:
scriptable - the scriptable to fire the event
event - the event
Returns:
the result

getEventHandler

public net.sourceforge.htmlunit.corejs.javascript.Function getEventHandler(String eventName)
Returns the specified event handler.

Parameters:
eventName - the event name (e.g. "onclick")
Returns:
the handler function, or null if the property is null or not a function

hasEventHandlers

public boolean hasEventHandlers(String eventName)
Returns true if there are any event handlers for the specified event.

Parameters:
eventName - the event name (e.g. "onclick")
Returns:
true if there are any event handlers for the specified event, false otherwise

setEventHandler

public void setEventHandler(String eventName,
                            net.sourceforge.htmlunit.corejs.javascript.Function eventHandler)
Defines an event handler.

Parameters:
eventName - the event name (e.g. "onclick")
eventHandler - the handler (null to reset it)

setEventHandlerProp

protected void setEventHandlerProp(String eventName,
                                   Object value)
Defines an event handler (or maybe any other object).

Parameters:
eventName - the event name (e.g. "onclick")
value - the property (null to reset it)

getEventHandlerProp

protected Object getEventHandlerProp(String eventName)
Gets the property defined as event handler (not necessary a Function if something else has been set).

Parameters:
eventName - the event name (e.g. "onclick")
Returns:
the property

getOwnerDocument

public Object getOwnerDocument()
Returns the owner document.

Returns:
the document

getPrefix

public String getPrefix()
Returns the namespace prefix.

Returns:
the namespace prefix

getLocalName

public String getLocalName()
Returns the local name of this element.

Returns:
the local name of this element

getNamespaceURI

public String getNamespaceURI()
Returns The URI that identifies an XML namespace.

Returns:
the URI that identifies an XML namespace

getBaseName

public Object getBaseName()
Returns the base name of this element.

Returns:
the base name of this element

compareDocumentPosition

public short compareDocumentPosition(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.


getXml

public Object getXml()
Represents the xml content of the node and its descendants.

Returns:
the xml content of the node and its descendants

getTextContent

public String getTextContent()
Gets the textContent attribute.

Returns:
the contents of this node as text

setTextContent

public void setTextContent(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 property "parentElement".

Returns:
the parent element
See Also:
getParentNode()

getAttributes

public 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(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


Copyright © 2002–2014 Gargoyle Software Inc.. All rights reserved.