Package org.htmlunit.javascript.host.dom
Class TreeWalker
java.lang.Object
org.htmlunit.corejs.javascript.ScriptableObject
org.htmlunit.javascript.HtmlUnitScriptable
org.htmlunit.javascript.host.dom.TreeWalker
- All Implemented Interfaces:
Serializable
,Cloneable
,org.htmlunit.corejs.javascript.ConstProperties
,org.htmlunit.corejs.javascript.debug.DebuggableObject
,org.htmlunit.corejs.javascript.Scriptable
,org.htmlunit.corejs.javascript.SymbolScriptable
The JavaScript object that represents a
TreeWalker
.- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.htmlunit.corejs.javascript.ScriptableObject
org.htmlunit.corejs.javascript.ScriptableObject.KeyComparator
-
Field Summary
FieldsFields inherited from class org.htmlunit.corejs.javascript.ScriptableObject
CONST, DONTENUM, EMPTY, PERMANENT, READONLY, UNINITIALIZED_CONST
Fields inherited from interface org.htmlunit.corejs.javascript.Scriptable
NOT_FOUND
-
Constructor Summary
ConstructorsConstructorDescriptionCreates an instance.TreeWalker
(Node root, int whatToShow, org.w3c.dom.traversal.NodeFilter filter, boolean expandEntityReferences) Creates an instance. -
Method Summary
Modifier and TypeMethodDescriptionMoves the TreeWalker to the first visible child of the current node, and returns the new node.Gets the node at which the TreeWalker is currently positioned.Gets the filter used to screen nodes.(package private) static int
getFlagForNode
(Node node) Given aNode
, return the appropriate constant for whatToShow.private static Node
getNodeOrNull
(DomNode domNode) getRoot()
Gets the root node of the TreeWalker, as specified when it was created.long
Gets the whatToShow attribute of the TreeWalker.void
Creates an instance.Moves the TreeWalker to the last visible child of the current node, and returns the new node.nextNode()
Moves the TreeWalker to the next visible node in document order relative to the current node, and returns the new node.Moves the TreeWalker to the next sibling of the current node, and returns the new node.Moves to and returns the closest visible ancestor node of the current node.Moves the TreeWalker to the previous visible node in document order relative to the current node, and returns the new node.Moves the TreeWalker to the previous sibling of the current node, and returns the new node.void
setCurrentNode
(Node currentNode) Sets the node at which the TreeWalker is currently positioned.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 Details
-
walker_
-
-
Constructor Details
-
TreeWalker
public TreeWalker()Creates an instance. -
TreeWalker
public TreeWalker(Node root, int whatToShow, org.w3c.dom.traversal.NodeFilter filter, boolean expandEntityReferences) throws DOMException Creates an instance.- Parameters:
root
- The root node of the TreeWalker. Must not benull
.whatToShow
- Flag specifying which types of nodes appear in the logical view of the TreeWalker. SeeNodeFilter
for the set of possible Show_ values.filter
- TheNodeFilter
to be used with this TreeWalker, ornull
to indicate no filter.expandEntityReferences
- If false, the contents of EntityReference nodes are not present in the logical view.- Throws:
DOMException
- on attempt to create a TreeWalker with a root that isnull
.
-
-
Method Details
-
jsConstructor
public void jsConstructor()Creates an instance. -
getRoot
Gets the root node of the TreeWalker, as specified when it was created.- Returns:
- the root node of the TreeWalker
-
getWhatToShow
public long getWhatToShow()Gets the whatToShow attribute of the TreeWalker. This attribute determines which node types are presented via the TreeWalker. The set of available constants is defined inNodeFilter
.- Returns:
- the value of the whatToShow attribute of the TreeWalker
-
getFilter
Gets the filter used to screen nodes.- Returns:
- the filter used to screen nodes
-
getCurrentNode
Gets the node at which the TreeWalker is currently positioned.- Returns:
- the currentNode
-
setCurrentNode
Sets the node at which the TreeWalker is currently positioned.- Parameters:
currentNode
- The node to be used as the current position of the TreeWalker.- Throws:
DOMException
- on attempt to set currentNode tonull
.
-
getFlagForNode
Given aNode
, return the appropriate constant for whatToShow.- Parameters:
node
- the node- Returns:
- the whatToShow constant for the type of specified node
-
parentNode
Moves to and returns the closest visible ancestor node of the current node. If the search for parentNode attempts to step upward from the TreeWalker's root node, or if it fails to find a visible ancestor node, this method retains the current position and returns null.- Returns:
- The new parent node, or
null
if the current node has no parent in the TreeWalker's logical view.
-
getNodeOrNull
-
firstChild
Moves the TreeWalker to the first visible child of the current node, and returns the new node. If the current node has no visible children, returnsnull
, and retains the current node.- Returns:
- The new node, or
null
if the current node has no visible children in the TreeWalker's logical view.
-
lastChild
Moves the TreeWalker to the last visible child of the current node, and returns the new node. If the current node has no visible children, returnsnull
, and retains the current node.- Returns:
- The new node, or
null
if the current node has no visible children in the TreeWalker's logical view.
-
previousSibling
Moves the TreeWalker to the previous sibling of the current node, and returns the new node. If the current node has no visible previous sibling, returnsnull
, and retains the current node.- Returns:
- The new node, or
null
if the current node has no previous sibling in the TreeWalker's logical view.
-
nextSibling
Moves the TreeWalker to the next sibling of the current node, and returns the new node. If the current node has no visible next sibling, returnsnull
, and retains the current node.- Returns:
- The new node, or
null
if the current node has no next sibling in the TreeWalker's logical view.
-
previousNode
Moves the TreeWalker to the previous visible node in document order relative to the current node, and returns the new node. If the current node has no previous node, or if the search for previousNode attempts to step upward from the TreeWalker's root node, returnsnull
, and retains the current node.- Returns:
- The new node, or
null
if the current node has no previous node in the TreeWalker's logical view.
-
nextNode
Moves the TreeWalker to the next visible node in document order relative to the current node, and returns the new node. If the current node has no next node, or if the search for nextNode attempts to step upward from the TreeWalker's root node, returnsnull
, and retains the current node.- Returns:
- The new node, or
null
if the current node has no next node in the TreeWalker's logical view.
-