Java Code Examples for org.w3c.dom.Node#getPreviousSibling()

The following examples show how to use org.w3c.dom.Node#getPreviousSibling() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DOMUtil.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/** Finds and returns the last child node with the given name. */
public static Element getLastChildElement(Node parent, String elemNames[]) {

    // search for node
    Node child = parent.getLastChild();
    while (child != null) {
        if (child.getNodeType() == Node.ELEMENT_NODE) {
            for (int i = 0; i < elemNames.length; i++) {
                if (child.getNodeName().equals(elemNames[i])) {
                    return (Element)child;
                }
            }
        }
        child = child.getPreviousSibling();
    }

    // not found
    return null;

}
 
Example 2
Source File: DOMUtil.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Finds and returns the last child node with the given name and
 * attribute name, value pair.
 */
public static Element getLastChildElement(Node   parent,
        String elemName,
        String attrName,
        String attrValue) {

    // search for node
    Node child = parent.getLastChild();
    while (child != null) {
        if (child.getNodeType() == Node.ELEMENT_NODE) {
            Element element = (Element)child;
            if (element.getNodeName().equals(elemName) &&
                    element.getAttribute(attrName).equals(attrValue)) {
                return element;
            }
        }
        child = child.getPreviousSibling();
    }

    // not found
    return null;

}
 
Example 3
Source File: DOMUtil.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/** Finds and returns the last child node with the given qualified name. */
public static Element getLastChildElementNS(Node parent,
        String[][] elemNames) {

    // search for node
    Node child = parent.getLastChild();
    while (child != null) {
        if (child.getNodeType() == Node.ELEMENT_NODE) {
            for (int i = 0; i < elemNames.length; i++) {
                String uri = child.getNamespaceURI();
                if (uri != null && uri.equals(elemNames[i][0]) &&
                        child.getLocalName().equals(elemNames[i][1])) {
                    return (Element)child;
                }
            }
        }
        child = child.getPreviousSibling();
    }

    // not found
    return null;

}
 
Example 4
Source File: DOMUtil.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/** Finds and returns the last child node with the given qualified name. */
public static Element getLastChildElementNS(Node parent,
        String[][] elemNames) {

    // search for node
    Node child = parent.getLastChild();
    while (child != null) {
        if (child.getNodeType() == Node.ELEMENT_NODE) {
            for (int i = 0; i < elemNames.length; i++) {
                String uri = child.getNamespaceURI();
                if (uri != null && uri.equals(elemNames[i][0]) &&
                        child.getLocalName().equals(elemNames[i][1])) {
                    return (Element)child;
                }
            }
        }
        child = child.getPreviousSibling();
    }

    // not found
    return null;

}
 
Example 5
Source File: DOMUtil.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/** Finds and returns the last visible child element node.
 *  Overload previous method for non-Xerces node impl
 */
public static Element getLastVisibleChildElement(Node parent, Map<Node, String> hiddenNodes) {

    // search for node
    Node child = parent.getLastChild();
    while (child != null) {
        if (child.getNodeType() == Node.ELEMENT_NODE &&
                !isHidden(child, hiddenNodes)) {
            return (Element)child;
        }
        child = child.getPreviousSibling();
    }

    // not found
    return null;

}
 
Example 6
Source File: XmlParser.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
private void reapComments(org.w3c.dom.Element element, Element context) {
	Node node = element.getPreviousSibling();
	while (node != null && node.getNodeType() != Node.ELEMENT_NODE) {
		if (node.getNodeType() == Node.COMMENT_NODE)
			context.getComments().add(0, node.getTextContent());
		node = node.getPreviousSibling();
	}
	node = element.getLastChild();
	while (node != null && node.getNodeType() != Node.ELEMENT_NODE) {
		node = node.getPreviousSibling();
	}
	while (node != null) {
		if (node.getNodeType() == Node.COMMENT_NODE)
			context.getComments().add(node.getTextContent());
		node = node.getNextSibling();
	}
}
 
Example 7
Source File: XMLUtil.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public static Element getLastChild(Element e) {
  if (e == null)
    return null;
  Node n = e.getLastChild();
  while (n != null && n.getNodeType() != Node.ELEMENT_NODE)
    n = n.getPreviousSibling();
  return (Element) n;
}
 
Example 8
Source File: XmlElement.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns all leading comments in the source xml before the node to be adopted.
 * @param nodeToBeAdopted node that will be added as a child to this node.
 */
static List<Node> getLeadingComments(Node nodeToBeAdopted) {
    ImmutableList.Builder<Node> nodesToAdopt = new ImmutableList.Builder<Node>();
    Node previousSibling = nodeToBeAdopted.getPreviousSibling();
    while (previousSibling != null
            && (previousSibling.getNodeType() == Node.COMMENT_NODE
            || previousSibling.getNodeType() == Node.TEXT_NODE)) {
        // we really only care about comments.
        if (previousSibling.getNodeType() == Node.COMMENT_NODE) {
            nodesToAdopt.add(previousSibling);
        }
        previousSibling = previousSibling.getPreviousSibling();
    }
    return nodesToAdopt.build().reverse();
}
 
Example 9
Source File: TreeWalkerImpl.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/** Internal function.
 *  Return the previousSibling Node, from the input node
 *  after applying filter, whatToshow.
     *  NEVER TRAVERSES ABOVE THE SPECIFIED ROOT NODE.
 *  The current node is not consulted or set.
 */
Node getPreviousSibling(Node node, Node root) {

    if (node == null || node == root) return null;

    Node newNode = node.getPreviousSibling();
    if (newNode == null) {

        newNode = node.getParentNode();
        if (newNode == null || newNode == root)  return null;

        int parentAccept = acceptNode(newNode);

        if (parentAccept==NodeFilter.FILTER_SKIP) {
            return getPreviousSibling(newNode, root);
        }

        return null;
    }

    int accept = acceptNode(newNode);

    if (accept == NodeFilter.FILTER_ACCEPT)
        return newNode;
    else
    if (accept == NodeFilter.FILTER_SKIP) {
        Node fChild =  getLastChild(newNode);
        if (fChild == null) {
            return getPreviousSibling(newNode, root);
        }
        return fChild;
    }
    else
    //if (accept == NodeFilter.REJECT_NODE)
    {
        return getPreviousSibling(newNode, root);
    }

}
 
Example 10
Source File: DOMNodePointer.java    From commons-jxpath with Apache License 2.0 5 votes vote down vote up
/**
 * Get the relative position of this among sibling text nodes.
 * @return 1..n
 */
private int getRelativePositionOfTextNode() {
    int count = 1;
    Node n = node.getPreviousSibling();
    while (n != null) {
        if (n.getNodeType() == Node.TEXT_NODE
            || n.getNodeType() == Node.CDATA_SECTION_NODE) {
            count++;
        }
        n = n.getPreviousSibling();
    }
    return count;
}
 
Example 11
Source File: NodeIteratorImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/** The method previousNode(Node) returns the previous node
 *  from the actual DOM tree.
 */
Node previousNode(Node node) {

    Node result;

    // if we're at the root, return null.
    if (node == fRoot) return null;

    // get sibling
    result = node.getPreviousSibling();
    if (result == null) {
        //if 1st sibling, return parent
        result = node.getParentNode();
        return result;
    }

    // if sibling has children, keep getting last child of child.
    if (result.hasChildNodes()
        && !(!fEntityReferenceExpansion
            && result != null
            && result.getNodeType() == Node.ENTITY_REFERENCE_NODE))

    {
        while (result.hasChildNodes()) {
            result = result.getLastChild();
        }
    }

    return result;
}
 
Example 12
Source File: TextImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Concatenates the text of all logically-adjacent text nodes to the left of
 * the node
 * @param node
 * @param buffer
 * @param parent
 * @return true - if execution was stopped because the type of node
 *         other than EntityRef, Text, CDATA is encountered, otherwise
 *         return false
 */
private boolean getWholeTextBackward(Node node, StringBuffer buffer, Node parent){

    // boolean to indicate whether node is a child of an entity reference
    boolean inEntRef = false;
    if (parent!=null) {
            inEntRef = parent.getNodeType()==Node.ENTITY_REFERENCE_NODE;
    }

    while (node != null) {
        short type = node.getNodeType();
        if (type == Node.ENTITY_REFERENCE_NODE) {
            if (getWholeTextBackward(node.getLastChild(), buffer, node)){
                return true;
            }
        }
        else if (type == Node.TEXT_NODE ||
                 type == Node.CDATA_SECTION_NODE) {
            ((TextImpl)node).insertTextContent(buffer);
        }
        else {
            return true;
        }

        node = node.getPreviousSibling();
    }

    // if the parent node is an entity reference node, must
    // check nodes to the left of the parent entity reference node for logically adjacent
    // text nodes
    if (inEntRef) {
            getWholeTextBackward(parent.getPreviousSibling(), buffer, parent.getParentNode());
        return true;
    }

    return false;
}
 
Example 13
Source File: XmlElement.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Returns all leading comments in the source xml before the node to be adopted.
 * @param nodeToBeAdopted node that will be added as a child to this node.
 */
static List<Node> getLeadingComments(Node nodeToBeAdopted) {
    ImmutableList.Builder<Node> nodesToAdopt = new ImmutableList.Builder<Node>();
    Node previousSibling = nodeToBeAdopted.getPreviousSibling();
    while (previousSibling != null
            && (previousSibling.getNodeType() == Node.COMMENT_NODE
            || previousSibling.getNodeType() == Node.TEXT_NODE)) {
        // we really only care about comments.
        if (previousSibling.getNodeType() == Node.COMMENT_NODE) {
            nodesToAdopt.add(previousSibling);
        }
        previousSibling = previousSibling.getPreviousSibling();
    }
    return nodesToAdopt.build().reverse();
}
 
Example 14
Source File: RangeImpl.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Visits the nodes selected by this range when we know
 * a-priori that the start and end containers are not the
 * same, but the start container is an ancestor of the
 * end container. This method is invoked by the generic
 * <code>traverse</code> method.
 *
 * @param endAncestor
 *               The ancestor of the end container that is a direct child
 *               of the start container.
 *
 * @param how    Specifies what type of traversal is being
 *               requested (extract, clone, or delete).
 *               Legal values for this argument are:
 *
 *               <ol>
 *               <li><code>EXTRACT_CONTENTS</code> - will produce
 *               a document fragment containing the range's content.
 *               Partially selected nodes are copied, but fully
 *               selected nodes are moved.
 *
 *               <li><code>CLONE_CONTENTS</code> - will leave the
 *               context tree of the range undisturbed, but sill
 *               produced cloned content in a document fragment
 *
 *               <li><code>DELETE_CONTENTS</code> - will delete from
 *               the context tree of the range, all fully selected
 *               nodes.
 *               </ol>
 *
 * @return Returns a document fragment containing any
 *         copied or extracted nodes.  If the <code>how</code>
 *         parameter was <code>DELETE_CONTENTS</code>, the
 *         return value is null.
 */
private DocumentFragment
    traverseCommonStartContainer( Node endAncestor, int how )
{
    DocumentFragment frag = null;
    if ( how!=DELETE_CONTENTS)
        frag = fDocument.createDocumentFragment();
    Node n = traverseRightBoundary( endAncestor, how );
    if ( frag!=null )
        frag.appendChild( n );

    int endIdx = indexOf( endAncestor, fStartContainer );
    int cnt = endIdx - fStartOffset;
    if ( cnt <=0 )
    {
        // Collapse to just before the endAncestor, which
        // is partially selected.
        if ( how != CLONE_CONTENTS )
        {
            setEndBefore( endAncestor );
            collapse( false );
        }
        return frag;
    }

    n = endAncestor.getPreviousSibling();
    while( cnt > 0 )
    {
        Node sibling = n.getPreviousSibling();
        Node xferNode = traverseFullySelected( n, how );
        if ( frag!=null )
            frag.insertBefore( xferNode, frag.getFirstChild() );
        --cnt;
        n = sibling;
    }
    // Collapse to just before the endAncestor, which
    // is partially selected.
    if ( how != CLONE_CONTENTS )
    {
        setEndBefore( endAncestor );
        collapse( false );
    }
    return frag;
}
 
Example 15
Source File: CajaTreeBuilder.java    From caja with Apache License 2.0 4 votes vote down vote up
@Override
protected void elementPopped(String ns, String name, Node node) {
  boolean removed = unpoppedElements.remove(node);
  if (DEBUG) {
    System.err.println("popped " + ns + " : " + name + ", node=" + node
                       + " @ " + endTok.pos);
  }
  if (needsDebugData) {
    name = Html5ElementStack.canonicalElementName(name);
    FilePosition endPos;
    if (startTok.type == HtmlTokenType.TAGBEGIN
        // A start <select> tag inside a select element is treated as a close
        // select tag.  Don't ask -- there's just no good reason.
        // http://www.whatwg.org/specs/web-apps/current-work/#in-select
        //    If the insertion mode is "in select"
        //    A start tag whose tag name is "select"
        //      Parse error. Act as if the token had been an end tag
        //      with the tag name "select" instead.
        && (isEndTag(startTok.text) || "select".equals(name))
        && tagCloses(tagName(startTok.text), name)) {
      endPos = endTok.pos;
    } else {
      // Implied ending.
      endPos = FilePosition.startOf(startTok.pos);
    }
    FilePosition startPos = Nodes.getFilePositionFor(node);
    if (startPos.source().equals(InputSource.UNKNOWN)) {
      Node first = node.getFirstChild();
      if (first != null) {
        startPos = Nodes.getFilePositionFor(first);
      }
    }
    FilePosition lastPos = startPos;
    Node last;
    for (last = node.getLastChild(); last != null;
         last = last.getPreviousSibling()) {
      if (last.getNodeType() != Node.TEXT_NODE
          || !isWhitespace(last.getNodeValue())) {
        break;
      }
    }
    if (last != null) {
      lastPos = Nodes.getFilePositionFor(last);
    }
    if (DEBUG) {
      System.err.println("startPos=" + startPos + ", lastPos=" + lastPos
           + ", removed=" + removed);
    }
    if (endPos.endCharInFile() >= lastPos.endCharInFile()
        && (removed || lastPos.endCharInFile() > startPos.endCharInFile())) {
      Nodes.setFilePositionFor(node, FilePosition.span(startPos, endPos));
    }
  }
}
 
Example 16
Source File: TextImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * If any EntityReference to be removed has descendants that are not
 * EntityReference, Text, or CDATASection nodes, the replaceWholeText method
 * must fail before performing any modification of the document, raising a
 * DOMException with the code NO_MODIFICATION_ALLOWED_ERR. Traverse previous
 * siblings of the node to be replaced. If a previous sibling is an
 * EntityReference node, get it's last child. If the last child was a Text
 * or CDATASection node and its previous siblings are neither a replaceable
 * EntityReference or Text or CDATASection nodes, return false. IF the last
 * child was neither Text nor CDATASection nor a replaceable EntityReference
 * Node, then return true. If the last child was a Text or CDATASection node
 * any its previous sibling was not or was an EntityReference that did not
 * contain only Text or CDATASection nodes, return false. Check this
 * recursively for EntityReference nodes.
 *
 * @param node
 * @return true - can replace text false - can't replace exception must be
 *         raised
 */
private boolean canModifyPrev(Node node) {
    boolean textLastChild = false;

    Node prev = node.getPreviousSibling();

    while (prev != null) {

        short type = prev.getNodeType();

        if (type == Node.ENTITY_REFERENCE_NODE) {
            //If the previous sibling was entityreference
            //check if its content is replaceable
            Node lastChild = prev.getLastChild();

            //if the entity reference has no children
            //return false
            if (lastChild == null) {
                return false;
            }

            //The replacement text of the entity reference should
            //be either only text,cadatsections or replaceable entity
            //reference nodes or the last child should be neither of these
            while (lastChild != null) {
                short lType = lastChild.getNodeType();

                if (lType == Node.TEXT_NODE
                        || lType == Node.CDATA_SECTION_NODE) {
                    textLastChild = true;
                } else if (lType == Node.ENTITY_REFERENCE_NODE) {
                    if (!canModifyPrev(lastChild)) {
                        return false;
                    } else {
                        //If the EntityReference child contains
                        //only text, or non-text or ends with a
                        //non-text node.
                        textLastChild = true;
                    }
                } else {
                    //If the last child was replaceable and others are not
                    //Text or CDataSection or replaceable EntityRef nodes
                    //return false.
                    if (textLastChild) {
                        return false;
                    } else {
                        return true;
                    }
                }
                lastChild = lastChild.getPreviousSibling();
            }
        } else if (type == Node.TEXT_NODE
                || type == Node.CDATA_SECTION_NODE) {
            //If the previous sibling was text or cdatasection move to next
        } else {
            //If the previous sibling was anything but text or
            //cdatasection or an entity reference, stop search and
            //return true
            return true;
        }

        prev = prev.getPreviousSibling();
    }

    return true;
}
 
Example 17
Source File: DOMUtils.java    From jdk8u_jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns the last child element of the specified node, or null if there
 * is no such element.
 *
 * @param node the node
 * @return the last child element of the specified node, or null if there
 *    is no such element
 * @throws NullPointerException if <code>node == null</code>
 */
public static Element getLastChildElement(Node node) {
    Node child = node.getLastChild();
    while (child != null && child.getNodeType() != Node.ELEMENT_NODE) {
        child = child.getPreviousSibling();
    }
    return (Element)child;
}
 
Example 18
Source File: RangeImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Traverses the "right boundary" of this range and
 * operates on each "boundary node" according to the
 * <code>how</code> parameter.  It is a-priori assumed
 * by this method that the right boundary does
 * not contain the range's start container.
 * <p>
 * A "right boundary" is best visualized by thinking
 * of a sample tree:<pre>
 *                 A
 *                /|\
 *               / | \
 *              /  |  \
 *             B   C   D
 *            /|\     /|\
 *           E F G   H I J
 * </pre>
 * Imagine first a range that begins between the
 * "E" and "F" nodes and ends between the
 * "I" and "J" nodes.  The start container is
 * "B" and the end container is "D".  Given this setup,
 * the following applies:
 * <p>
 * Partially Selected Nodes: B, D<br>
 * Fully Selected Nodes: F, G, C, H, I
 * <p>
 * The "right boundary" is the highest subtree node
 * that contains the ending container.  The root of
 * this subtree is always partially selected.
 * <p>
 * In this example, the nodes that are traversed
 * as "right boundary" nodes are: H, I, and D.
 *
 * @param root   The node that is the root of the "right boundary" subtree.
 *
 * @param how    Specifies what type of traversal is being
 *               requested (extract, clone, or delete).
 *               Legal values for this argument are:
 *
 *               <ol>
 *               <li><code>EXTRACT_CONTENTS</code> - will produce
 *               a node containing the boundaries content.
 *               Partially selected nodes are copied, but fully
 *               selected nodes are moved.
 *
 *               <li><code>CLONE_CONTENTS</code> - will leave the
 *               context tree of the range undisturbed, but will
 *               produced cloned content.
 *
 *               <li><code>DELETE_CONTENTS</code> - will delete from
 *               the context tree of the range, all fully selected
 *               nodes within the boundary.
 *               </ol>
 *
 * @return Returns a node that is the result of visiting nodes.
 *         If the traversal operation is
 *         <code>DELETE_CONTENTS</code> the return value is null.
 */
private Node traverseRightBoundary( Node root, int how )
{
    Node next = getSelectedNode( fEndContainer, fEndOffset-1 );
    boolean isFullySelected = ( next!=fEndContainer );

    if ( next==root )
        return traverseNode( next, isFullySelected, false, how );

    Node parent = next.getParentNode();
    Node clonedParent = traverseNode( parent, false, false, how );

    while( parent!=null )
    {
        while( next!=null )
        {
            Node prevSibling = next.getPreviousSibling();
            Node clonedChild =
                traverseNode( next, isFullySelected, false, how );
            if ( how!=DELETE_CONTENTS )
            {
                clonedParent.insertBefore(
                    clonedChild,
                    clonedParent.getFirstChild()
                );
            }
            isFullySelected = true;
            next = prevSibling;
        }
        if ( parent==root )
            return clonedParent;

        next = parent.getPreviousSibling();
        parent = parent.getParentNode();
        Node clonedGrandParent = traverseNode( parent, false, false, how );
        if ( how!=DELETE_CONTENTS )
            clonedGrandParent.appendChild( clonedParent );
        clonedParent = clonedGrandParent;

    }

    // should never occur
    return null;
}
 
Example 19
Source File: XMLUtil.java    From seleniumtestsframework with Apache License 2.0 2 votes vote down vote up
/**
 * Gets Node Index value for the XPath expression<br>
 * <p/>
 * e.g. <root><a><b>ritesh</b><b>trivedi</b></a></root> calling
 * <p/>
 * getXPathNodeIndex for Node with value
 * <p/>
 * trivedi would return 2
 */

public static int getXPathNodeIndex(Node node, boolean ignoreWhitespace)

{

    int nodeIndex = 0;


    if (node == null)

    {

        return -1;

        //throw new IllegalArgumentException("Node argument for getXPathNodeIndex cannot be null");

    }


    Node prevNode = node;


    //log("getXPathNodeIndex info next few lines");            

    //log("Current node:");

    //printNode(node);


    while ((prevNode = prevNode.getPreviousSibling()) != null)

    {

        //log("previous node");

        //printNode(prevNode);

        if (nodesEqual(node, prevNode, ignoreWhitespace))

            nodeIndex++;

    }


    // If similar children are found, ONLY then increase

    // the nodeIndex by 1 since XPath exprn starts at 1 and not 0

    if (nodeIndex > 0)

        nodeIndex++;


    if (nodeIndex == 0)

    {

        Node nextNode = node;

        boolean found = false;

        while (((nextNode = nextNode.getNextSibling()) != null) && (!found))

        {

            //log("Next node");

            //printNode(nextNode);

            if (nodesEqual(node, nextNode, ignoreWhitespace))

            {

                nodeIndex++;

                found = true;

            }

            //node = prevNode;

        }

    }


    return nodeIndex;

}
 
Example 20
Source File: RangeImpl.java    From openjdk-8-source with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Traverses the "right boundary" of this range and
 * operates on each "boundary node" according to the
 * <code>how</code> parameter.  It is a-priori assumed
 * by this method that the right boundary does
 * not contain the range's start container.
 * <p>
 * A "right boundary" is best visualized by thinking
 * of a sample tree:<pre>
 *                 A
 *                /|\
 *               / | \
 *              /  |  \
 *             B   C   D
 *            /|\     /|\
 *           E F G   H I J
 * </pre>
 * Imagine first a range that begins between the
 * "E" and "F" nodes and ends between the
 * "I" and "J" nodes.  The start container is
 * "B" and the end container is "D".  Given this setup,
 * the following applies:
 * <p>
 * Partially Selected Nodes: B, D<br>
 * Fully Selected Nodes: F, G, C, H, I
 * <p>
 * The "right boundary" is the highest subtree node
 * that contains the ending container.  The root of
 * this subtree is always partially selected.
 * <p>
 * In this example, the nodes that are traversed
 * as "right boundary" nodes are: H, I, and D.
 *
 * @param root   The node that is the root of the "right boundary" subtree.
 *
 * @param how    Specifies what type of traversal is being
 *               requested (extract, clone, or delete).
 *               Legal values for this argument are:
 *
 *               <ol>
 *               <li><code>EXTRACT_CONTENTS</code> - will produce
 *               a node containing the boundaries content.
 *               Partially selected nodes are copied, but fully
 *               selected nodes are moved.
 *
 *               <li><code>CLONE_CONTENTS</code> - will leave the
 *               context tree of the range undisturbed, but will
 *               produced cloned content.
 *
 *               <li><code>DELETE_CONTENTS</code> - will delete from
 *               the context tree of the range, all fully selected
 *               nodes within the boundary.
 *               </ol>
 *
 * @return Returns a node that is the result of visiting nodes.
 *         If the traversal operation is
 *         <code>DELETE_CONTENTS</code> the return value is null.
 */
private Node traverseRightBoundary( Node root, int how )
{
    Node next = getSelectedNode( fEndContainer, fEndOffset-1 );
    boolean isFullySelected = ( next!=fEndContainer );

    if ( next==root )
        return traverseNode( next, isFullySelected, false, how );

    Node parent = next.getParentNode();
    Node clonedParent = traverseNode( parent, false, false, how );

    while( parent!=null )
    {
        while( next!=null )
        {
            Node prevSibling = next.getPreviousSibling();
            Node clonedChild =
                traverseNode( next, isFullySelected, false, how );
            if ( how!=DELETE_CONTENTS )
            {
                clonedParent.insertBefore(
                    clonedChild,
                    clonedParent.getFirstChild()
                );
            }
            isFullySelected = true;
            next = prevSibling;
        }
        if ( parent==root )
            return clonedParent;

        next = parent.getPreviousSibling();
        parent = parent.getParentNode();
        Node clonedGrandParent = traverseNode( parent, false, false, how );
        if ( how!=DELETE_CONTENTS )
            clonedGrandParent.appendChild( clonedParent );
        clonedParent = clonedGrandParent;

    }

    // should never occur
    return null;
}