// Helper method for getEquivalentLogical private Node getSibling(final Node n, final boolean lookLeft) { if (n == null) { return null; } if (isNodeVisible(n)) { return null; } final Node sibling; if (lookLeft) { sibling = n.jsxGet_previousSibling(); } else { sibling = n.jsxGet_nextSibling(); } if (sibling == null) { // If this node has no logical siblings at or below it's "level", it might have one above if (n == root_) { return null; } return getSibling(n.jsxGet_parentNode(), lookLeft); } return getEquivalentLogical(sibling, lookLeft); }
/** * 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, returns <code>null</code>, and retains the current * node. * * @return The new node, or <code>null</code> if the current node has no next sibling in the * TreeWalker's logical view. */ public Node jsxFunction_nextSibling() { if (currentNode_ == root_) { return null; } final Node newNode = getEquivalentLogical(currentNode_.jsxGet_nextSibling(), false); if (newNode != null) { currentNode_ = newNode; } return newNode; }
/** * Helper method to get the first uncle node in document order (preorder traversal) from the given * node. */ private Node getFirstUncleNode(final Node n) { if (n == root_ || n == null) { return null; } final Node parent = n.jsxGet_parentNode(); if (parent == null) { return null; } final Node uncle = getEquivalentLogical(parent.jsxGet_nextSibling(), false); if (uncle != null) { return uncle; } return getFirstUncleNode(parent); }
/** * 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, returns <code>null</code>, and retains * the current node. * * @return The new node, or <code>null</code> if the current node has no next node in the * TreeWalker's logical view. */ public Node jsxFunction_nextNode() { final Node leftChild = getEquivalentLogical(currentNode_.jsxGet_firstChild(), false); if (leftChild != null) { currentNode_ = leftChild; return leftChild; } final Node rightSibling = getEquivalentLogical(currentNode_.jsxGet_nextSibling(), false); if (rightSibling != null) { currentNode_ = rightSibling; return rightSibling; } final Node uncle = getFirstUncleNode(currentNode_); if (uncle != null) { currentNode_ = uncle; return uncle; } return null; }