Package org.htmlunit.html
Class HtmlDomTreeWalker
- java.lang.Object
-
- org.htmlunit.html.HtmlDomTreeWalker
-
public class HtmlDomTreeWalker extends java.lang.Object
In general this is an implementation of org.w3c.dom.traversal.TreeWalker. The class org.w3c.dom.traversal.TreeWalker is not available on Android therefore we have this impl as backend.- See Also:
- DOM-Level-2-Traversal-Range
-
-
Field Summary
Fields Modifier and Type Field Description private DomNode
currentNode_
private boolean
expandEntityReferences_
private org.w3c.dom.traversal.NodeFilter
filter_
private DomNode
root_
private int
whatToShow_
-
Constructor Summary
Constructors Constructor Description HtmlDomTreeWalker(DomNode root, int whatToShow, org.w3c.dom.traversal.NodeFilter filter, boolean expandEntityReferences)
Creates an instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private short
acceptNode(org.w3c.dom.Node n)
Test whether a specified node is visible in the logical view of a TreeWalker, based solely on the whatToShow constant.DomNode
firstChild()
DomNode
getCurrentNode()
private DomNode
getEquivalentLogical(DomNode n, boolean lookLeft)
Recursively find the logical node occupying the same position as this _actual_ node.boolean
getExpandEntityReferences()
org.w3c.dom.traversal.NodeFilter
getFilter()
private DomNode
getFirstUncleNode(DomNode n)
Helper method to get the first uncle node in document order (preorder traversal) from the given node.static int
getFlagForNode(org.w3c.dom.Node node)
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
Given aNode
, return the appropriate constant for whatToShow.private DomNode
getPreviousNode(DomNode n)
Helper method to get the previous node in document order (preorder traversal) from the given node.DomNode
getRoot()
private DomNode
getSibling(DomNode n, boolean lookLeft)
int
getWhatToShow()
private boolean
isNodeRejected(org.w3c.dom.Node n)
private boolean
isNodeSkipped(org.w3c.dom.Node n)
private boolean
isNodeVisible(org.w3c.dom.Node n)
Returns whether the node is visible by the TreeWalker.DomNode
lastChild()
DomNode
nextNode()
DomNode
nextSibling()
DomNode
parentNode()
DomNode
previousNode()
DomNode
previousSibling()
void
setCurrentNode(org.w3c.dom.Node currentNode)
-
-
-
Constructor Detail
-
HtmlDomTreeWalker
public HtmlDomTreeWalker(DomNode root, int whatToShow, org.w3c.dom.traversal.NodeFilter filter, boolean expandEntityReferences) throws org.w3c.dom.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:
org.w3c.dom.DOMException
- on attempt to create a TreeWalker with a root that isnull
.
-
-
Method Detail
-
getRoot
public DomNode getRoot()
- Returns:
- the root node
- See Also:
TreeWalker.getRoot()
-
getWhatToShow
public int getWhatToShow()
- Returns:
- NodeFilter constant
- See Also:
TreeWalker.getWhatToShow()
-
getFilter
public org.w3c.dom.traversal.NodeFilter getFilter()
- Returns:
- the filter
- See Also:
TreeWalker.getFilter()
-
getExpandEntityReferences
public boolean getExpandEntityReferences()
- Returns:
- the ExpandEntityReferences setting
- See Also:
TreeWalker.getExpandEntityReferences()
-
getCurrentNode
public DomNode getCurrentNode()
- Returns:
- the current node
- See Also:
TreeWalker.getCurrentNode()
-
setCurrentNode
public void setCurrentNode(org.w3c.dom.Node currentNode) throws org.w3c.dom.DOMException
- Parameters:
currentNode
- the current node- Throws:
org.w3c.dom.DOMException
- See Also:
TreeWalker.setCurrentNode(Node)
-
nextNode
public DomNode nextNode()
- Returns:
- the next node
- See Also:
TreeWalker.nextNode()
-
getFirstUncleNode
private DomNode getFirstUncleNode(DomNode n)
Helper method to get the first uncle node in document order (preorder traversal) from the given node.
-
getEquivalentLogical
private DomNode getEquivalentLogical(DomNode n, boolean lookLeft)
Recursively find the logical node occupying the same position as this _actual_ node. It could be the same node, a different node, or null depending on filtering.- Parameters:
n
- The actual node we are trying to find the "equivalent" oflookLeft
- If true, traverse the tree in the left direction. If false, traverse the tree to the right.- Returns:
- the logical node in the same position as n
-
isNodeVisible
private boolean isNodeVisible(org.w3c.dom.Node n)
Returns whether the node is visible by the TreeWalker.
-
acceptNode
private short acceptNode(org.w3c.dom.Node n)
Test whether a specified node is visible in the logical view of a TreeWalker, based solely on the whatToShow constant.- Parameters:
n
- The node to check to see if it should be shown or not- Returns:
- a constant to determine whether the node is accepted, rejected, or skipped.
-
getFlagForNode
public static int getFlagForNode(org.w3c.dom.Node node)
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
Given aNode
, return the appropriate constant for whatToShow.- Parameters:
node
- the node- Returns:
- the whatToShow constant for the type of specified node
-
isNodeSkipped
private boolean isNodeSkipped(org.w3c.dom.Node n)
-
isNodeRejected
private boolean isNodeRejected(org.w3c.dom.Node n)
-
nextSibling
public DomNode nextSibling()
- Returns:
- the next sibling node
- See Also:
TreeWalker.nextSibling()
-
parentNode
public DomNode parentNode()
- Returns:
- the parent node
- See Also:
TreeWalker.parentNode()
-
previousSibling
public DomNode previousSibling()
- Returns:
- the previous sibling node
- See Also:
TreeWalker.previousSibling()
-
lastChild
public DomNode lastChild()
- Returns:
- the last child node
- See Also:
TreeWalker.lastChild()
-
previousNode
public DomNode previousNode()
- Returns:
- the previous node
- See Also:
TreeWalker.previousNode()
-
getPreviousNode
private DomNode getPreviousNode(DomNode n)
Helper method to get the previous node in document order (preorder traversal) from the given node.
-
firstChild
public DomNode firstChild()
- Returns:
- the first child node
- See Also:
TreeWalker.firstChild()
-
-