com.gargoylesoftware.htmlunit.html
Class DomNode

java.lang.Object
  extended by com.gargoylesoftware.htmlunit.html.DomNode
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable
Direct Known Subclasses:
DomCharacterData, DomDocumentFragment, DomNamespaceNode, HtmlAttr, HtmlPage

public abstract class DomNode
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable

Base class for nodes in the HTML DOM tree. This class is modeled after the W3C DOM specification, but does not implement it.

Version:
$Revision: 1.3 $
Author:
Mike Bowler, Mike J. Bresnahan, David K. Taylor, Christian Sell, Chris Erskine, Mike Williams, Marc Guillemot, Denis N. Antonioli, Daniel Gredler, Ahmed Ashour, Rodney Gitzel
See Also:
Serialized Form

Field Summary
static java.lang.String PROPERTY_ELEMENT
 The name of the "element" property.
static java.lang.String READY_STATE_COMPLETE
 A ready state constant for IE (state 5).
static java.lang.String READY_STATE_INTERACTIVE
 A ready state constant for IE (state 4).
static java.lang.String READY_STATE_LOADED
 A ready state constant for IE (state 3).
static java.lang.String READY_STATE_LOADING
 A ready state constant for IE (state 2).
static java.lang.String READY_STATE_UNINITIALIZED
 A ready state constant for IE (state 1).
 
Method Summary
 void addDomChangeListener(DomChangeListener listener)
 Adds a DomChangeListener to the listener list.
 DomNode appendDomChild(DomNode node)
 append a child node to the end of the current list
 java.lang.String asText()
 Returns a text representation of this element that represents what would be visible to the user if this page was shown in a web browser.
 java.lang.String asXml()
 Return a string representation of the xml document from this element and all it's children (recursively).
 DomNode cloneDomNode(boolean deep)
 Make a clone of this node
 java.util.Iterator getAllHtmlChildElements()
 Return an iterator that will recursively iterate over every child element below this one.
 java.util.List getByXPath(java.lang.String xpathExpr)
 Facility to evaluate an xpath from the current node.
 java.util.Iterator getChildIterator()
  
 int getEndColumnNumber()
 Get the column number in the source page where the DOM node ends.
 int getEndLineNumber()
 Get the line number in the source page where the DOM node ends.
 org.mozilla.javascript.Function getEventHandler(java.lang.String eventName)
 INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
 DomNode getFirstDomChild()
  
 DomNode getLastDomChild()
 Get the last child DomNode.
 DomNode getNextDomSibling()
  
abstract  java.lang.String getNodeName()
 Get the name for the current node.
abstract  short getNodeType()
 Get the type of the current node.
 java.lang.String getNodeValue()
 Get the value for the current node.
 HtmlPage getPage()
 Return the HtmlPage that contains this node
 DomNode getParentDomNode()
  
 DomNode getPreviousDomSibling()
  
 java.lang.String getReadyState()
 Return this node's ready state (IE only).
 org.mozilla.javascript.ScriptableObject getScriptObject()
 INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
 int getStartColumnNumber()
 Get the column number in the source page where the DOM node starts.
 int getStartLineNumber()
 Get the line number in the source page where the DOM node starts.
 void insertBefore(DomNode newNode)
 Inserts a new child node before this node into the child relationship this node is a part of.
 void remove()
 remove this node from all relationships this node has with siblings an parents
 void removeAllChildren()
 Remove all the children of this node.
 void removeDomChangeListener(DomChangeListener listener)
 Removes an DomChangeListener from the listener list.
 void removeEventHandler(java.lang.String eventName)
 INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
 void replace(DomNode newNode)
 Replaces this node with another node.
 void setEventHandler(java.lang.String eventName, org.mozilla.javascript.Function eventHandler)
 INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
 void setEventHandler(java.lang.String eventName, java.lang.String jsSnippet)
 INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
 void setNodeValue(java.lang.String x)
  
 void setReadyState(java.lang.String state)
 Sets this node's ready state (IE only).
 void setScriptObject(org.mozilla.javascript.ScriptableObject scriptObject)
 INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROPERTY_ELEMENT

public static final java.lang.String PROPERTY_ELEMENT
The name of the "element" property. Used when watching property change events.

See Also:
Constant Field Values

READY_STATE_COMPLETE

public static final java.lang.String READY_STATE_COMPLETE
A ready state constant for IE (state 5).

See Also:
Constant Field Values

READY_STATE_INTERACTIVE

public static final java.lang.String READY_STATE_INTERACTIVE
A ready state constant for IE (state 4).

See Also:
Constant Field Values

READY_STATE_LOADED

public static final java.lang.String READY_STATE_LOADED
A ready state constant for IE (state 3).

See Also:
Constant Field Values

READY_STATE_LOADING

public static final java.lang.String READY_STATE_LOADING
A ready state constant for IE (state 2).

See Also:
Constant Field Values

READY_STATE_UNINITIALIZED

public static final java.lang.String READY_STATE_UNINITIALIZED
A ready state constant for IE (state 1).

See Also:
Constant Field Values
Method Detail

addDomChangeListener

public void addDomChangeListener(DomChangeListener listener)
Adds a DomChangeListener to the listener list. The listener is registered for all children nodes of this DomNode, as well as the descendant nodes.

Parameters:
listener - the dom structure change listener to be added.
See Also:
removeDomChangeListener(DomChangeListener)

appendDomChild

public DomNode appendDomChild(DomNode node)
append a child node to the end of the current list

Parameters:
node - the node to append
Returns:
the node added

asText

public java.lang.String asText()
Returns a text representation of this element that represents what would be visible to the user if this page was shown in a web browser. For example, a single-selection select element would return the currently selected value as text.

Returns:
The element as text.

asXml

public java.lang.String asXml()
Return a string representation of the xml document from this element and all it's children (recursively).

Returns:
The xml string.

cloneDomNode

public DomNode cloneDomNode(boolean deep)
Make a clone of this node

Parameters:
deep - if true, the clone will be propagated to the whole subtree below this one. Otherwise, the new node will not have any children. The page reference will always be the same as this node's.
Returns:
a new node

getAllHtmlChildElements

public java.util.Iterator getAllHtmlChildElements()
Return an iterator that will recursively iterate over every child element below this one.

Returns:
The iterator.

getByXPath

public java.util.List getByXPath(java.lang.String xpathExpr)
                          throws org.jaxen.JaxenException
Facility to evaluate an xpath from the current node. The current node is considered as the document root for the evaluation therefore parent nodes can't be reached.

Parameters:
xpathExpr - the xpath expression
Returns:
See XPath#selectNodes(Object)
Throws:
org.jaxen.JaxenException - if the xpath expression can't be parsed/evaluated

getChildIterator

public java.util.Iterator getChildIterator()
Returns:
an iterator over the children of this node

getEndColumnNumber

public int getEndColumnNumber()
Get the column number in the source page where the DOM node ends.

Returns:
See above.

getEndLineNumber

public int getEndLineNumber()
Get the line number in the source page where the DOM node ends.

Returns:
See above.

getEventHandler

public org.mozilla.javascript.Function getEventHandler(java.lang.String eventName)
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
Return a Function to be executed when a given event occurs.

Parameters:
eventName - Name of event such as "onclick" or "onblur", etc.
Returns:
A rhino javascript executable Function, or null if no event handler has been defined

getFirstDomChild

public DomNode getFirstDomChild()
Returns:
the previous sibling

getLastDomChild

public DomNode getLastDomChild()
Get the last child DomNode.

Returns:
The last child node or null if the current node has no children.

getNextDomSibling

public DomNode getNextDomSibling()
Returns:
the next sibling

getNodeName

public abstract java.lang.String getNodeName()
Get the name for the current node.

Returns:
The node name

getNodeType

public abstract short getNodeType()
Get the type of the current node.

Returns:
The node type

getNodeValue

public java.lang.String getNodeValue()
Get the value for the current node.

Returns:
The node value

getPage

public HtmlPage getPage()
Return the HtmlPage that contains this node

Returns:
See above

getParentDomNode

public DomNode getParentDomNode()
Returns:
the parent DomNode of this node, which may be null if this is the root node

getPreviousDomSibling

public DomNode getPreviousDomSibling()
Returns:
the previous sibling of this node, or null if this is the first node

getReadyState

public java.lang.String getReadyState()
Return this node's ready state (IE only).

Returns:
This node's ready state.

getScriptObject

public org.mozilla.javascript.ScriptableObject getScriptObject()
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
The logic of when and where the js object is created needs a clean up: functions using a js object of a dom node should not have to look if they should create it first Return the javascript object that corresponds to this node.

Returns:
The javascript object that corresponds to this node building it if necessary.

getStartColumnNumber

public int getStartColumnNumber()
Get the column number in the source page where the DOM node starts.

Returns:
See above.

getStartLineNumber

public int getStartLineNumber()
Get the line number in the source page where the DOM node starts.

Returns:
See above.

insertBefore

public void insertBefore(DomNode newNode)
                  throws java.lang.IllegalStateException
Inserts a new child node before this node into the child relationship this node is a part of.

Parameters:
newNode - the new node to insert
Throws:
java.lang.IllegalStateException - if this node is not a child of any other node

remove

public void remove()
            throws java.lang.IllegalStateException
remove this node from all relationships this node has with siblings an parents

Throws:
java.lang.IllegalStateException - if this node is not a child of any other node

removeAllChildren

public void removeAllChildren()
Remove all the children of this node.


removeDomChangeListener

public void removeDomChangeListener(DomChangeListener listener)
Removes an DomChangeListener from the listener list. This method should be used to remove DomChangeListener that were registered for all children nodes and descendant nodes of this DomNode.

Parameters:
listener - the dom structure change listener to be removed.
See Also:
addDomChangeListener(DomChangeListener)

removeEventHandler

public void removeEventHandler(java.lang.String eventName)
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
Removes the specified event handler.

Parameters:
eventName - Name of the event such as "onclick" or "onblur", etc.

replace

public void replace(DomNode newNode)
             throws java.lang.IllegalStateException
Replaces this node with another node.

Parameters:
newNode - the node to replace this one
Throws:
java.lang.IllegalStateException - if this node is not a child of any other node

setEventHandler

public void setEventHandler(java.lang.String eventName,
                            org.mozilla.javascript.Function eventHandler)
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
Register a Function as an event handler.

Parameters:
eventName - Name of event such as "onclick" or "onblur", etc.
eventHandler - A rhino javascript executable Function

setEventHandler

public void setEventHandler(java.lang.String eventName,
                            java.lang.String jsSnippet)
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
Register a snippet of javascript code as an event handler. The javascript code will be wrapped inside a unique function declaration which provides one argument named "event"

Parameters:
eventName - Name of event such as "onclick" or "onblur", etc.
jsSnippet - executable javascript code

setNodeValue

public void setNodeValue(java.lang.String x)
Parameters:
x - The new value

setReadyState

public void setReadyState(java.lang.String state)
Sets this node's ready state (IE only).

Parameters:
state - This node's ready state.

setScriptObject

public void setScriptObject(org.mozilla.javascript.ScriptableObject scriptObject)
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
Set the javascript object that corresponds to this node. This is not guaranteed to be set even if there is a javascript object for this DOM node.

Parameters:
scriptObject - The javascript object.


Copyright © 2003-2016 AppPerfect Corporation. All Rights Reserved.