Milyn-Smooks Version 0.4

org.milyn.dom
Class DomUtils

java.lang.Object
  extended byorg.milyn.dom.DomUtils

public abstract class DomUtils
extends java.lang.Object

W3C DOM utility methods.

Author:
tfennelly

Constructor Summary
DomUtils()
           
 
Method Summary
static void appendList(org.w3c.dom.Node node, java.util.List nodes)
          Append the nodes from the supplied list to the supplied node.
static void copyChildNodes(org.w3c.dom.Node source, org.w3c.dom.Node target)
          Copy child node references from source to target.
static java.util.List copyNodeList(org.w3c.dom.NodeList nodeList)
          Copy the nodes of a NodeList into the supplied list.
static java.lang.String getAttributeValue(org.w3c.dom.Element element, java.lang.String attributeName)
          Get attribute value, returning null if unset.
static boolean getBooleanAttrib(org.w3c.dom.Element element, java.lang.String attribName)
          Get a boolean attribute from the supplied element.
static org.w3c.dom.Element getParentElement(org.w3c.dom.Element child, java.lang.String parentName)
          Get the parent element of the supplied element having the specified tag name.
static void insertBefore(org.w3c.dom.NodeList newNodes, org.w3c.dom.Node refNode)
          Insert the supplied nodes before the supplied reference node (refNode).
static void removeChildren(org.w3c.dom.Node node)
          Remove all child nodes from the supplied node.
static org.w3c.dom.Element renameElement(org.w3c.dom.Element element, java.lang.String replacementElement, boolean keepChildContent, boolean keepAttributes)
          Rename element.
static void replaceNode(org.w3c.dom.NodeList newNodes, org.w3c.dom.Node oldNode)
          Replace one node with a list of nodes.
static void replaceNode(org.w3c.dom.NodeList newNodes, org.w3c.dom.Node oldNode, boolean clone)
          Replace one node with a list of nodes.
static void replaceNode(org.w3c.dom.Node newNode, org.w3c.dom.Node oldNode)
          Replace one node with another node.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DomUtils

public DomUtils()
Method Detail

copyChildNodes

public static void copyChildNodes(org.w3c.dom.Node source,
                                  org.w3c.dom.Node target)
Copy child node references from source to target.

Parameters:
source - Source Node.
target - Target Node.

replaceNode

public static void replaceNode(org.w3c.dom.Node newNode,
                               org.w3c.dom.Node oldNode)
Replace one node with another node.

Parameters:
newNode - New node - added in same location as oldNode.
oldNode - Old node - removed.

insertBefore

public static void insertBefore(org.w3c.dom.NodeList newNodes,
                                org.w3c.dom.Node refNode)
Insert the supplied nodes before the supplied reference node (refNode).

Parameters:
newNodes - Nodes to be inserted.
refNode - Reference node before which the supplied nodes should be inserted.

replaceNode

public static void replaceNode(org.w3c.dom.NodeList newNodes,
                               org.w3c.dom.Node oldNode)
Replace one node with a list of nodes.

Clones the NodeList elements.

Parameters:
newNodes - New nodes - added in same location as oldNode.
oldNode - Old node - removed.

replaceNode

public static void replaceNode(org.w3c.dom.NodeList newNodes,
                               org.w3c.dom.Node oldNode,
                               boolean clone)
Replace one node with a list of nodes.

Parameters:
newNodes - New nodes - added in same location as oldNode.
oldNode - Old node - removed.
clone - Clone Nodelist Nodes.

renameElement

public static org.w3c.dom.Element renameElement(org.w3c.dom.Element element,
                                                java.lang.String replacementElement,
                                                boolean keepChildContent,
                                                boolean keepAttributes)
Rename element.

Parameters:
element - The element to be renamed.
replacementElement - The tag name of the replacement element.
keepChildContent - true if the target element's child content is to be copied to the replacement element, false if not. Default true.
keepAttributes - true if the target element's attributes are to be copied to the replacement element, false if not. Default true.
Returns:
The renamed element.

removeChildren

public static void removeChildren(org.w3c.dom.Node node)
Remove all child nodes from the supplied node.

Parameters:
node - to be "cleared".

copyNodeList

public static java.util.List copyNodeList(org.w3c.dom.NodeList nodeList)
Copy the nodes of a NodeList into the supplied list.

This is not a clone. It's just a copy of the node references.

Allows iteration over the Nodelist using the copy in the knowledge that the list will remain the same length. Using the NodeList can result in problems because elements can get removed from the list while we're iterating over it.

Parameters:
nodeList - Nodelist to copy.
Returns:
List copy.

appendList

public static void appendList(org.w3c.dom.Node node,
                              java.util.List nodes)
Append the nodes from the supplied list to the supplied node.

Parameters:
node - Node to be appended to.
nodes - List of nodes to append.

getBooleanAttrib

public static boolean getBooleanAttrib(org.w3c.dom.Element element,
                                       java.lang.String attribName)
Get a boolean attribute from the supplied element.

Parameters:
element - The element.
attribName - The attribute name.
Returns:
True if the attribute value is "true" (case insensitive), otherwise false.

getParentElement

public static org.w3c.dom.Element getParentElement(org.w3c.dom.Element child,
                                                   java.lang.String parentName)
Get the parent element of the supplied element having the specified tag name.

Parameters:
child - Child element.
parentName - Parent element name.
Returns:
The first parent element of "child" having the tagname "parentName", or null if no such parent element exists.

getAttributeValue

public static java.lang.String getAttributeValue(org.w3c.dom.Element element,
                                                 java.lang.String attributeName)
Get attribute value, returning null if unset.

Some DOM implementations return an empty string for an unset attribute.

Parameters:
element - The DOM element.
attributeName - The attribute to get.
Returns:
The attribute value, or null if unset.

Milyn-Smooks Version 0.4