Java Code Examples for org.w3c.dom.Node.cloneNode()

The following are Jave code examples for showing how to use cloneNode() of the org.w3c.dom.Node class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: incubator-netbeans   File: XMLUtil.java   View Source Code Vote up 8 votes
/**
 * Convert an XML fragment from one namespace to another.
 * 
 * @param from element to translate
 * @param namespace namespace to be translated to
 * @return
 * 
 * @since 8.4
 */
public static Element translateXML(Element from, String namespace) {
    Element to = from.getOwnerDocument().createElementNS(namespace, from.getLocalName());
    NodeList nl = from.getChildNodes();
    int length = nl.getLength();
    for (int i = 0; i < length; i++) {
        Node node = nl.item(i);
        Node newNode;
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            newNode = translateXML((Element) node, namespace);
        } else {
            newNode = node.cloneNode(true);
        }
        to.appendChild(newNode);
    }
    NamedNodeMap m = from.getAttributes();
    for (int i = 0; i < m.getLength(); i++) {
        Node attr = m.item(i);
        to.setAttribute(attr.getNodeName(), attr.getNodeValue());
    }
    return to;
}
 
Example 2
Project: convertigo-engine   File: XMLCopyStep.java   View Source Code Vote up 6 votes
static protected void createCopy(Step step, Document doc, Element stepNode) throws EngineException {
	NodeList list = step.getContextValues();
	if (list != null) {
		int len = list.getLength();
		for (int i=0; i<len;i++) {
			Node node = list.item(i);
			if (node != null) {
				boolean shouldImport = !node.getOwnerDocument().equals(doc);
				Node child = shouldImport ? doc.importNode(node, true):node.cloneNode(true);
				if (child.getNodeType() == Node.ELEMENT_NODE) {
					stepNode.appendChild((Element) child);
				} else if (child.getNodeType() == Node.ATTRIBUTE_NODE) {
					stepNode.setAttribute(child.getNodeName(),child.getNodeValue());
				}
			}
		}
	}
}
 
Example 3
Project: Tarski   File: mxCodec.java   View Source Code Vote up 6 votes
/**
 * Decodes the given XML node. The optional "into" argument specifies an existing object to be
 * used. If no object is given, then a new instance is created using the constructor from the
 * codec.
 * 
 * The function returns the passed in object or the new instance if no object was given.
 * 
 * @param node XML node to be decoded.
 * @param into Optional object to be decodec into.
 * @return Returns an object that represents the given node.
 */
public Object decode(Node node, Object into) {
  Object obj = null;

  if (node != null && node.getNodeType() == Node.ELEMENT_NODE) {
    mxObjectCodec codec = mxCodecRegistry.getCodec(node.getNodeName());

    try {
      if (codec != null) {
        obj = codec.decode(this, node, into);
      } else {
        obj = node.cloneNode(true);
        ((Element) obj).removeAttribute("as");
      }
    } catch (Exception e) {
      System.err.println("Cannot decode " + node.getNodeName() + ": " + e.getMessage());
      e.printStackTrace();
    }
  }

  return obj;
}
 
Example 4
Project: openjdk-jdk10   File: NodeTest.java   View Source Code Vote up 6 votes
@Test
public void testImportNode() throws Exception {
    Document document = createDOMWithNS("Node02.xml");
    Document otherDocument = createDOMWithNS("ElementSample01.xml");

    NodeList otherNodeList = otherDocument.getElementsByTagName("body");
    Node importedNode = otherNodeList.item(0);
    Node clone = importedNode.cloneNode(true);

    Node retNode = document.importNode(importedNode, true);
    assertTrue(clone.isEqualNode(importedNode)); //verify importedNode is not changed
    assertNotEquals(retNode, importedNode);
    assertTrue(importedNode.isEqualNode(retNode));

    retNode = document.importNode(importedNode, false);
    assertTrue(clone.isEqualNode(importedNode)); //verify importedNode is not changed
    assertEquals(retNode.getNodeName(), importedNode.getNodeName());
    assertFalse(importedNode.isEqualNode(retNode));
}
 
Example 5
Project: incubator-netbeans   File: XMLUtil.java   View Source Code Vote up 5 votes
/**
 * Copy elements from one document to another attaching at the specified element
 * and translating the namespace.
 *
 * @param from copy the children of this element (exclusive)
 * @param to where to attach the copied elements
 * @param newNamespace destination namespace
 * 
 * @since 8.4
 */
public static void copyDocument(Element from, Element to, String newNamespace) {
    Document doc = to.getOwnerDocument();
    NodeList nl = from.getChildNodes();
    int length = nl.getLength();
    for (int i = 0; i < length; i++) {
        Node node = nl.item(i);
        Node newNode = null;
        if (Node.ELEMENT_NODE == node.getNodeType()) {
            Element oldElement = (Element) node;
            newNode = doc.createElementNS(newNamespace, oldElement.getTagName());
            NamedNodeMap m = oldElement.getAttributes();
            Element newElement = (Element) newNode;
            for (int index = 0; index < m.getLength(); index++) {
                Node attr = m.item(index);
                newElement.setAttribute(attr.getNodeName(), attr.getNodeValue());
            }
            copyDocument(oldElement, newElement, newNamespace);
        } else {
            newNode = node.cloneNode(true);
            newNode = to.getOwnerDocument().importNode(newNode, true);
        }
        if (newNode != null) {
            to.appendChild(newNode);
        }
    }
}
 
Example 6
Project: alvisnlp   File: DOMParamConverter.java   View Source Code Vote up 5 votes
@Override
protected DocumentFragment convertXML(Element xmlValue) throws ConverterException {
	Document doc = xmlValue.getOwnerDocument();
	DocumentFragment result = doc.createDocumentFragment();
	for (Node child : XMLUtils.childrenNodes(xmlValue)) {
		Node clone = child.cloneNode(true);
		result.appendChild(clone);
	}
	return result;
}
 
Example 7
Project: convertigo-engine   File: Sequence.java   View Source Code Vote up 5 votes
private static Node cloneNodeWithUserData(Node node, boolean recurse) {
	if (node != null) {
		Object node_output = node.getUserData(Step.NODE_USERDATA_OUTPUT);

		Node clonedNode = node.cloneNode(false);
		clonedNode.setUserData(Step.NODE_USERDATA_OUTPUT, node_output, null);
		
		if (node.getNodeType() == Node.ELEMENT_NODE) {
			// attributes
			NamedNodeMap attributeMap = clonedNode.getAttributes();
			for (int i=0; i< attributeMap.getLength(); i++) {
				Node clonedAttribute = attributeMap.item(i);
				String attr_name = clonedAttribute.getNodeName();
				Object attr_output = ((Element)node).getAttributeNode(attr_name).getUserData(Step.NODE_USERDATA_OUTPUT);
				clonedAttribute.setUserData(Step.NODE_USERDATA_OUTPUT, attr_output, null);
			}
			
			// recurse on element child nodes only
			if (recurse && node.hasChildNodes()) {
				NodeList list = node.getChildNodes();
				for (int i=0; i<list.getLength(); i++) {
					Node clonedChild = cloneNodeWithUserData(list.item(i), recurse);
					if (clonedChild != null) {
						clonedNode.appendChild(clonedChild);
					}
				}
			}
		}
		
		return clonedNode;
	}
	return null;
}
 
Example 8
Project: TrabalhoFinalEDA2   File: mxCodec.java   View Source Code Vote up 5 votes
/**
 * Decodes the given XML node. The optional "into" argument specifies an
 * existing object to be used. If no object is given, then a new
 * instance is created using the constructor from the codec.
 * 
 * The function returns the passed in object or the new instance if no
 * object was given.
 * 
 * @param node XML node to be decoded.
 * @param into Optional object to be decodec into.
 * @return Returns an object that represents the given node.
 */
public Object decode(Node node, Object into)
{
	Object obj = null;

	if (node != null && node.getNodeType() == Node.ELEMENT_NODE)
	{
		mxObjectCodec codec = mxCodecRegistry.getCodec(node.getNodeName());

		try
		{
			if (codec != null)
			{
				obj = codec.decode(this, node, into);
			}
			else
			{
				obj = node.cloneNode(true);
				((Element) obj).removeAttribute("as");
			}
		}
		catch (Exception e)
		{
			System.err.println("Cannot decode " + node.getNodeName() + ": "
					+ e.getMessage());
			e.printStackTrace();
		}
	}

	return obj;
}
 
Example 9
Project: TrabalhoFinalEDA2   File: mxRootChangeCodec.java   View Source Code Vote up 5 votes
/**
 * Reads the cells into the graph model. All cells are children of the root
 * element in the node.
 */
public Node beforeDecode(mxCodec dec, Node node, Object into)
{
	if (into instanceof mxRootChange)
	{
		mxRootChange change = (mxRootChange) into;

		if (node.getFirstChild() != null
				&& node.getFirstChild().getNodeType() == Node.ELEMENT_NODE)
		{
			// Makes sure the original node isn't modified
			node = node.cloneNode(true);

			Node tmp = node.getFirstChild();
			change.setRoot(dec.decodeCell(tmp, false));

			Node tmp2 = tmp.getNextSibling();
			tmp.getParentNode().removeChild(tmp);
			tmp = tmp2;

			while (tmp != null)
			{
				tmp2 = tmp.getNextSibling();

				if (tmp.getNodeType() == Node.ELEMENT_NODE)
				{
					dec.decodeCell(tmp, true);
				}

				tmp.getParentNode().removeChild(tmp);
				tmp = tmp2;
			}
		}
	}

	return node;
}
 
Example 10
Project: Tarski   File: mxRootChangeCodec.java   View Source Code Vote up 5 votes
/**
 * Reads the cells into the graph model. All cells are children of the root element in the node.
 */
public Node beforeDecode(mxCodec dec, Node node, Object into) {
  if (into instanceof mxRootChange) {
    mxRootChange change = (mxRootChange) into;

    if (node.getFirstChild() != null && node.getFirstChild().getNodeType() == Node.ELEMENT_NODE) {
      // Makes sure the original node isn't modified
      node = node.cloneNode(true);

      Node tmp = node.getFirstChild();
      change.setRoot(dec.decodeCell(tmp, false));

      Node tmp2 = tmp.getNextSibling();
      tmp.getParentNode().removeChild(tmp);
      tmp = tmp2;

      while (tmp != null) {
        tmp2 = tmp.getNextSibling();

        if (tmp.getNodeType() == Node.ELEMENT_NODE) {
          dec.decodeCell(tmp, true);
        }

        tmp.getParentNode().removeChild(tmp);
        tmp = tmp2;
      }
    }
  }

  return node;
}
 
Example 11
Project: openjdk-jdk10   File: NodeTest.java   View Source Code Vote up 5 votes
@Test
public void testCloneNode() throws Exception {
    Document document = createDOMWithNS("Node02.xml");

    NodeList nodeList = document.getElementsByTagName("body");
    Node node = nodeList.item(0);
    Node cloneNode = node.cloneNode(true);

    assertTrue(node.isEqualNode(cloneNode));
    assertNotEquals(node, cloneNode);

    nodeList = document.getElementsByTagName("html");
    Node node2 = nodeList.item(0);
    node2.appendChild(cloneNode);
}
 
Example 12
Project: OpenJSharp   File: AttributeMap.java   View Source Code Vote up 4 votes
private final Node remove(AttrImpl attr, int index,
                          boolean addDefault) {

    CoreDocumentImpl ownerDocument = ownerNode.ownerDocument();
    String name = attr.getNodeName();
    if (attr.isIdAttribute()) {
        ownerDocument.removeIdentifier(attr.getValue());
    }

    if (hasDefaults() && addDefault) {
        // If there's a default, add it instead
        NamedNodeMapImpl defaults =
            ((ElementImpl) ownerNode).getDefaultAttributes();

        Node d;
        if (defaults != null &&
            (d = defaults.getNamedItem(name)) != null &&
            findNamePoint(name, index+1) < 0) {
                NodeImpl clone = (NodeImpl)d.cloneNode(true);
                if (d.getLocalName() !=null){
                        // we must rely on the name to find a default attribute
                        // ("test:attr"), but while copying it from the DOCTYPE
                        // we should not loose namespace URI that was assigned
                        // to the attribute in the instance document.
                        ((AttrNSImpl)clone).namespaceURI = attr.getNamespaceURI();
                }
                clone.ownerNode = ownerNode;
                clone.isOwned(true);
                clone.isSpecified(false);

                nodes.set(index, clone);
                if (attr.isIdAttribute()) {
                    ownerDocument.putIdentifier(clone.getNodeValue(),
                                            (ElementImpl)ownerNode);
                }
        } else {
            nodes.remove(index);
        }
    } else {
        nodes.remove(index);
    }

    //        changed(true);

    // remove reference to owner
    attr.ownerNode = ownerDocument;
    attr.isOwned(false);

    // make sure it won't be mistaken with defaults in case it's
    // reused
    attr.isSpecified(true);
    attr.isIdAttribute(false);

    // notify document
    ownerDocument.removedAttrNode(attr, ownerNode, name);

    return attr;
}
 
Example 13
Project: OpenJSharp   File: RangeImpl.java   View Source Code Vote up 4 votes
/**
 * Utility method for traversing a single node when
 * we know a-priori that the node if fully
 * selected.
 *
 * @param n      The node to be traversed.
 *
 * @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 simply
 *               return the original node.
 *
 *               <li><code>CLONE_CONTENTS</code> - will leave the
 *               context tree of the range undisturbed, but will
 *               return a cloned node.
 *
 *               <li><code>DELETE_CONTENTS</code> - will delete the
 *               node from it's parent, but will return null.
 *               </ol>
 *
 * @return Returns a node that is the result of visiting the node.
 *         If the traversal operation is
 *         <code>DELETE_CONTENTS</code> the return value is null.
 */
private Node traverseFullySelected( Node n, int how )
{
    switch( how )
    {
    case CLONE_CONTENTS:
        return n.cloneNode( true );
    case EXTRACT_CONTENTS:
        if ( n.getNodeType()==Node.DOCUMENT_TYPE_NODE )
        {
            // TBD: This should be a HIERARCHY_REQUEST_ERR
            throw new DOMException(
                    DOMException.HIERARCHY_REQUEST_ERR,
            DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "HIERARCHY_REQUEST_ERR", null));
        }
        return n;
    case DELETE_CONTENTS:
        n.getParentNode().removeChild(n);
        return null;
    }
    return null;
}
 
Example 14
Project: dpdirect   File: SchemaLoader.java   View Source Code Vote up 4 votes
/**
 * Processes an XSParticle.
 * 
 * @param particle the particle to process.
 * @param contentElem the DOM element to be populated.
 */
protected void processXSParticle(XSParticle particle,
                                 Element contentElem) throws Exception {
   if (null != particle && null != contentElem) {
      XSTerm term = particle.getTerm();
      if (term instanceof XSModelGroup) {
         processXSGroup((XSModelGroup) term, contentElem);
      }
      else if (term instanceof XSElementDeclaration) {
         String termName = term.getName();
         int numOccurs = getOccurances(particle, contentElem);
         if ((0 < numOccurs) || sampleXML) {
            Node currentNode = parseXSObject((XSElementDeclaration) term, contentElem);
            for (int i = 0; i < numOccurs - 1; i++) {
               Node newElem = currentNode.cloneNode(true);
               if (!(currentNode.getParentNode() instanceof Document)) {
                  currentNode.getParentNode().appendChild(newElem);
               }
               NamedNodeMap attributes = newElem.getAttributes();
               for (int j = 0; j < attributes.getLength(); j++) {
                  String attributeValue = getAttributeValue(attributes.item(j).getNodeName(), newElem);
                  if (attributeValue != null) {
                     attributes.item(j).setNodeValue(attributeValue);
                  }
               }
               assignNodeValue(newElem);
            }
         }

      }
      else if (term instanceof XSWildcard) {
         if (soapEnv && xsRootElement.getName().equals("Envelope")
             && getNodeName(contentElem).equals("Body")) {
            // soapEnv == true, and we have traversed down to the 'Body' element.
            // Now change xsRootSchemaElement and build payload.
            XSElementDeclaration newRoot = stripSoapEnv();
            if (null != newRoot){
         	   parseXSObject(newRoot, contentElem);
            }
         }
      }
      else {
         log.warn("Unprocessed term case:" + ((null == term) ? "" : term.getClass().toString()));
      }
   }
}
 
Example 15
Project: TrabalhoFinalEDA2   File: mxChildChangeCodec.java   View Source Code Vote up 4 votes
/**
 * Reads the cells into the graph model. All cells are children of the root
 * element in the node.
 */
public Node beforeDecode(mxCodec dec, Node node, Object into)
{
	if (into instanceof mxChildChange)
	{
		mxChildChange change = (mxChildChange) into;

		if (node.getFirstChild() != null
				&& node.getFirstChild().getNodeType() == Node.ELEMENT_NODE)
		{
			// Makes sure the original node isn't modified
			node = node.cloneNode(true);

			Node tmp = node.getFirstChild();
			change.setChild(dec.decodeCell(tmp, false));

			Node tmp2 = tmp.getNextSibling();
			tmp.getParentNode().removeChild(tmp);
			tmp = tmp2;

			while (tmp != null)
			{
				tmp2 = tmp.getNextSibling();

				if (tmp.getNodeType() == Node.ELEMENT_NODE)
				{
					// Ignores all existing cells because those do not need
					// to be re-inserted into the model. Since the encoded
					// version of these cells contains the new parent, this
					// would leave to an inconsistent state on the model
					// (ie. a parent change without a call to
					// parentForCellChanged).
					String id = ((Element) tmp).getAttribute("id");

					if (dec.lookup(id) == null)
					{
						dec.decodeCell(tmp, true);
					}
				}

				tmp.getParentNode().removeChild(tmp);
				tmp = tmp2;
			}
		}
		else
		{
			String childRef = ((Element) node).getAttribute("child");
			change.setChild((mxICell) dec.getObject(childRef));
		}
	}

	return node;
}
 
Example 16
Project: Tarski   File: mxChildChangeCodec.java   View Source Code Vote up 4 votes
/**
 * Reads the cells into the graph model. All cells are children of the root element in the node.
 */
public Node beforeDecode(mxCodec dec, Node node, Object into) {
  if (into instanceof mxChildChange) {
    mxChildChange change = (mxChildChange) into;

    if (node.getFirstChild() != null && node.getFirstChild().getNodeType() == Node.ELEMENT_NODE) {
      // Makes sure the original node isn't modified
      node = node.cloneNode(true);

      Node tmp = node.getFirstChild();
      change.setChild(dec.decodeCell(tmp, false));

      Node tmp2 = tmp.getNextSibling();
      tmp.getParentNode().removeChild(tmp);
      tmp = tmp2;

      while (tmp != null) {
        tmp2 = tmp.getNextSibling();

        if (tmp.getNodeType() == Node.ELEMENT_NODE) {
          // Ignores all existing cells because those do not need
          // to be re-inserted into the model. Since the encoded
          // version of these cells contains the new parent, this
          // would leave to an inconsistent state on the model
          // (ie. a parent change without a call to
          // parentForCellChanged).
          String id = ((Element) tmp).getAttribute("id");

          if (dec.lookup(id) == null) {
            dec.decodeCell(tmp, true);
          }
        }

        tmp.getParentNode().removeChild(tmp);
        tmp = tmp2;
      }
    } else {
      String childRef = ((Element) node).getAttribute("child");
      change.setChild((mxICell) dec.getObject(childRef));
    }
  }

  return node;
}
 
Example 17
Project: openjdk-jdk10   File: AttributeMap.java   View Source Code Vote up 4 votes
private final Node remove(AttrImpl attr, int index,
                          boolean addDefault) {

    CoreDocumentImpl ownerDocument = ownerNode.ownerDocument();
    String name = attr.getNodeName();
    if (attr.isIdAttribute()) {
        ownerDocument.removeIdentifier(attr.getValue());
    }

    if (hasDefaults() && addDefault) {
        // If there's a default, add it instead
        NamedNodeMapImpl defaults =
            ((ElementImpl) ownerNode).getDefaultAttributes();

        Node d;
        if (defaults != null &&
            (d = defaults.getNamedItem(name)) != null &&
            findNamePoint(name, index+1) < 0) {
                NodeImpl clone = (NodeImpl)d.cloneNode(true);
                if (d.getLocalName() !=null){
                        // we must rely on the name to find a default attribute
                        // ("test:attr"), but while copying it from the DOCTYPE
                        // we should not loose namespace URI that was assigned
                        // to the attribute in the instance document.
                        ((AttrNSImpl)clone).namespaceURI = attr.getNamespaceURI();
                }
                clone.ownerNode = ownerNode;
                clone.isOwned(true);
                clone.isSpecified(false);

                nodes.set(index, clone);
                if (attr.isIdAttribute()) {
                    ownerDocument.putIdentifier(clone.getNodeValue(),
                                            (ElementImpl)ownerNode);
                }
        } else {
            nodes.remove(index);
        }
    } else {
        nodes.remove(index);
    }

    //        changed(true);

    // remove reference to owner
    attr.ownerNode = ownerDocument;
    attr.isOwned(false);

    // make sure it won't be mistaken with defaults in case it's
    // reused
    attr.isSpecified(true);
    attr.isIdAttribute(false);

    // notify document
    ownerDocument.removedAttrNode(attr, ownerNode, name);

    return attr;
}
 
Example 18
Project: openjdk-jdk10   File: RangeImpl.java   View Source Code Vote up 4 votes
/**
 * Utility method for traversing a single node when
 * we know a-priori that the node if fully
 * selected.
 *
 * @param n      The node to be traversed.
 *
 * @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 simply
 *               return the original node.
 *
 *               <li><code>CLONE_CONTENTS</code> - will leave the
 *               context tree of the range undisturbed, but will
 *               return a cloned node.
 *
 *               <li><code>DELETE_CONTENTS</code> - will delete the
 *               node from it's parent, but will return null.
 *               </ol>
 *
 * @return Returns a node that is the result of visiting the node.
 *         If the traversal operation is
 *         <code>DELETE_CONTENTS</code> the return value is null.
 */
private Node traverseFullySelected( Node n, int how )
{
    switch( how )
    {
    case CLONE_CONTENTS:
        return n.cloneNode( true );
    case EXTRACT_CONTENTS:
        if ( n.getNodeType()==Node.DOCUMENT_TYPE_NODE )
        {
            // TBD: This should be a HIERARCHY_REQUEST_ERR
            throw new DOMException(
                    DOMException.HIERARCHY_REQUEST_ERR,
            DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "HIERARCHY_REQUEST_ERR", null));
        }
        return n;
    case DELETE_CONTENTS:
        n.getParentNode().removeChild(n);
        return null;
    }
    return null;
}
 
Example 19
Project: OpenJSharp   File: RangeImpl.java   View Source Code Vote up 3 votes
/**
 * Utility method for traversing a single node when
 * we know a-priori that the node if partially
 * selected and is not a text node.
 *
 * @param n      The node to be traversed.
 *
 * @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 simply
 *               return the original node.
 *
 *               <li><code>CLONE_CONTENTS</code> - will leave the
 *               context tree of the range undisturbed, but will
 *               return a cloned node.
 *
 *               <li><code>DELETE_CONTENTS</code> - will delete the
 *               node from it's parent, but will return null.
 *               </ol>
 *
 * @return Returns a node that is the result of visiting the node.
 *         If the traversal operation is
 *         <code>DELETE_CONTENTS</code> the return value is null.
 */
private Node traversePartiallySelected( Node n, int how )
{
    switch( how )
    {
    case DELETE_CONTENTS:
        return null;
    case CLONE_CONTENTS:
    case EXTRACT_CONTENTS:
        return n.cloneNode( false );
    }
    return null;
}
 
Example 20
Project: openjdk-jdk10   File: RangeImpl.java   View Source Code Vote up 3 votes
/**
 * Utility method for traversing a single node when
 * we know a-priori that the node if partially
 * selected and is not a text node.
 *
 * @param n      The node to be traversed.
 *
 * @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 simply
 *               return the original node.
 *
 *               <li><code>CLONE_CONTENTS</code> - will leave the
 *               context tree of the range undisturbed, but will
 *               return a cloned node.
 *
 *               <li><code>DELETE_CONTENTS</code> - will delete the
 *               node from it's parent, but will return null.
 *               </ol>
 *
 * @return Returns a node that is the result of visiting the node.
 *         If the traversal operation is
 *         <code>DELETE_CONTENTS</code> the return value is null.
 */
private Node traversePartiallySelected( Node n, int how )
{
    switch( how )
    {
    case DELETE_CONTENTS:
        return null;
    case CLONE_CONTENTS:
    case EXTRACT_CONTENTS:
        return n.cloneNode( false );
    }
    return null;
}