com.novell.nds.dirxml.util
Class DxDOMUtil

java.lang.Object
  extended bycom.novell.nds.dirxml.util.DxDOMUtil

public abstract class DxDOMUtil
extends Object

XdsUtil is a utility class for performing various common and useful DOM operations that are not built into the DOM specification


Field Summary
static String TAG_WILDCARD
          Wildcard value that can be used for and of the ByTagName functions
 
Constructor Summary
DxDOMUtil()
           
 
Method Summary
static Document cloneDocument(Document doc)
          Creates clone of a document NOTE: only clones the tree structure, ie. ignores any document attributes
static Node cloneSubtree(Document targetDoc, Node sourceRoot)
          Clone a subtree, possibly into another document
static boolean copyAttributeNS(Element src, String attrNamespaceURI, String attrLocalName, Element dest)
          Copy an attribute from one element to another, but only if the attribute has a non-empty value
static boolean copyAttributeNS(Element src, String srcAttrNamespaceURI, String srcAttrLocalName, Element dest, String destAttrNamespaceURI, String destAttrQName)
          Copy an attribute from one element to another, with an new attribute name, but only if the attribute has a non-empty value
static Element[] elementArrayListToElementArray(ArrayList arrayList)
          creates an array of Elements from a ArrayList containing only elements
static void ensureDOMImpl(XmlDocument src)
          Conditionally convert the passed document to the DirXML DOM implementation.
static String getAssociationState(Element element)
          Get the first association state found under element from a NodeList
static String getAssociationValue(Element element)
          Get the first association value found under element
static Element[] getChildElements(Node node)
          Get all child elements of a node
static Element[] getChildElementsByTagNameNS(Node node, String namespaceURI, String localName)
          Get the all child elements of a node with a particular tag name
static Element[] getChildElementsByTagNameWithAttrNS(Node node, String namespaceURI, String localName, String attrNamespaceURI, String attrLocalName)
          Get all child element of a node with a particular tag name and a particular non-empty attribute
static Element[] getChildElementsByTagNameWithAttrValueIgnoreCaseNS(Node node, String namespaceURI, String localName, String attrNamespaceURI, String attrLocalName, String attrValue)
          Get all child elements of a node with a particular tag name and a particular attribute/value pair (value is not case sensitive)
static Element[] getChildElementsByTagNameWithAttrValueNS(Node node, String namespaceURI, String localName, String attrNamespaceURI, String attrLocalName, String attrValue)
          Get all child elements of a node with a particular tag name and a particular attribute/value pair (value is case sensitive)
static String getChildText(Node node)
          Get the string value of the concatenation of all the child text nodes
static NodeList getElementsByTagNameNS(Node node, String namespaceURI, String localName)
          Get all descendent elements of a node with a particular tag name
static Element[] getElementsByTagNameWithAttrNS(Node node, String namespaceURI, String localName, String attrNamespaceURI, String attrLocalName)
          Get all descendent elements of an node with a particular tag name and a particular non-empty attribute
static Element[] getElementsByTagNameWithAttrValueNS(Node node, String namespaceURI, String localName, String attrNamespaceURI, String attrLocalName, String attrValue)
          Get all descendent elements of an node with a particular tag name and a particular attribute/value pair (value is case sensitive)
static Element getFirstAncestorElementByTagNameNS(Node node, String namespaceURI, String localName)
          Get the nearest ancestor element of an node with a particular tag name
static Element getFirstAncestorElementByTagNameWithAttrNS(Node node, String namespaceURI, String localName, String attrNamespaceURI, String attrLocalName)
          Get the nearest ancestor element of an node with a particular tag name and a particular non-empty attribute
static Element getFirstChildElement(Node node)
          Get the first child element of a node
static Element getFirstChildElementByTagNameNS(Node node, String namespaceURI, String localName)
          Get the first child element of a node with a particular tag name
static Element getFirstChildElementByTagNameWithAttrValueIgnoreCaseNS(Node node, String namespaceURI, String localName, String attrNamespaceURI, String attrLocalName, String attrValue)
          Get the first child element of a node with a particular tag name and a particular attribute/value pair (value is not case sensitive)
static Element getFirstChildElementByTagNameWithAttrValueNS(Node node, String namespaceURI, String localName, String attrNamespaceURI, String attrLocalName, String attrValue)
          Get the first child element of a node with a particular tag name and a particular attribute/value pair (value is case sensitive)
static Element getFirstElementByTagNameNS(Node node, String namespaceURI, String localName)
          Get first descendent element of an node with a particular tag name
static Element getFirstElementByTagNameWithAttrValueNS(Node node, String namespaceURI, String localName, String attrNamespaceURI, String attrLocalName, String attrValue)
          Get the first descendent elements of an node with a particular tag name and a particular attribute/value pair (value is case sensitive)
static Element getFirstValue(Node node, String attrName)
          Get the first value element for a given attribute
static String getNodeText(Node node)
          Get the string value for a node (as defined by XPath)
static Date getTimestamp(Element element)
          Get the timestamp for the element
static int getTimestampEventCount(Element element)
          Get the timestamp event count for the element
static void graftSubtree(Node parent, Node sourceRoot)
          Graft a cloned subtree, possibly into another document
static Node[] nodeListToNodeArray(NodeList list)
          creates an array of nodes from a NodeList
static void removeAllChildren(Node node)
          Remove all the children of a node
static void removeChildElementsByTagNameNS(Node node, String namespaceURI, String localName)
          Remove all child elements of a node with a particular tag name
static Element renameElementNS(Element element, String namespaceURI, String qname)
          Rename an element (actually replaces the element with a new one that has the same attributes and children
static void setNodeText(Node node, String text)
          Set the string value for a node (as defined by XPath)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TAG_WILDCARD

public static final String TAG_WILDCARD
Wildcard value that can be used for and of the ByTagName functions

See Also:
Constant Field Values
Constructor Detail

DxDOMUtil

public DxDOMUtil()
Method Detail

getNodeText

public static String getNodeText(Node node)
Get the string value for a node (as defined by XPath)

Parameters:
node - the node
Returns:
the string value of the node

getChildText

public static String getChildText(Node node)
Get the string value of the concatenation of all the child text nodes

Parameters:
node - the node
Returns:
the string value of the node

setNodeText

public static void setNodeText(Node node,
                               String text)
Set the string value for a node (as defined by XPath)

Parameters:
node - the node
text - the desired text value of the node

getFirstChildElement

public static Element getFirstChildElement(Node node)
Get the first child element of a node

Parameters:
node - the node
Returns:
the first child element, or null if no such element exists

getFirstChildElementByTagNameNS

public static Element getFirstChildElementByTagNameNS(Node node,
                                                      String namespaceURI,
                                                      String localName)
Get the first child element of a node with a particular tag name

Parameters:
node - the node
namespaceURI - the namespace URI
localName - the localName
Returns:
the first matching element or null if no such element exists

getFirstChildElementByTagNameWithAttrValueNS

public static Element getFirstChildElementByTagNameWithAttrValueNS(Node node,
                                                                   String namespaceURI,
                                                                   String localName,
                                                                   String attrNamespaceURI,
                                                                   String attrLocalName,
                                                                   String attrValue)
Get the first child element of a node with a particular tag name and a particular attribute/value pair (value is case sensitive)

Parameters:
node - the node
namespaceURI - the element namespace URI
localName - the element localName
attrNamespaceURI - the attr namespace URI
attrLocalName - the attr localName
attrValue - the attribute value
Returns:
the first matching element or null if no such element exists

getFirstChildElementByTagNameWithAttrValueIgnoreCaseNS

public static Element getFirstChildElementByTagNameWithAttrValueIgnoreCaseNS(Node node,
                                                                             String namespaceURI,
                                                                             String localName,
                                                                             String attrNamespaceURI,
                                                                             String attrLocalName,
                                                                             String attrValue)
Get the first child element of a node with a particular tag name and a particular attribute/value pair (value is not case sensitive)

Parameters:
node - the node
namespaceURI - the element namespace URI
localName - the element localName
attrNamespaceURI - the attr namespace URI
attrLocalName - the attr localName
attrValue - the attribute value
Returns:
the first matching element or null if no such element exists

getChildElements

public static Element[] getChildElements(Node node)
Get all child elements of a node

Parameters:
node - the node
Returns:
array containing the all the child elements of the element, possibly 0 length, but never null

getChildElementsByTagNameNS

public static Element[] getChildElementsByTagNameNS(Node node,
                                                    String namespaceURI,
                                                    String localName)
Get the all child elements of a node with a particular tag name

Parameters:
node - the node
namespaceURI - the namespace URI
localName - the localName
Returns:
array containing the matching elements, possibly 0 length, but never null

getChildElementsByTagNameWithAttrNS

public static Element[] getChildElementsByTagNameWithAttrNS(Node node,
                                                            String namespaceURI,
                                                            String localName,
                                                            String attrNamespaceURI,
                                                            String attrLocalName)
Get all child element of a node with a particular tag name and a particular non-empty attribute

Parameters:
node - the node
namespaceURI - the element namespace URI
localName - the element localName
attrNamespaceURI - the attr namespace URI
attrLocalName - the attr localName
Returns:
array containing the matching elements, possibly 0 length, but never null

getChildElementsByTagNameWithAttrValueNS

public static Element[] getChildElementsByTagNameWithAttrValueNS(Node node,
                                                                 String namespaceURI,
                                                                 String localName,
                                                                 String attrNamespaceURI,
                                                                 String attrLocalName,
                                                                 String attrValue)
Get all child elements of a node with a particular tag name and a particular attribute/value pair (value is case sensitive)

Parameters:
node - the node
namespaceURI - the element namespace URI
localName - the element localName
attrNamespaceURI - the attr namespace URI
attrLocalName - the attr localName
attrValue - the attribute value
Returns:
array containing the matching elements, possibly 0 length, but never null

getChildElementsByTagNameWithAttrValueIgnoreCaseNS

public static Element[] getChildElementsByTagNameWithAttrValueIgnoreCaseNS(Node node,
                                                                           String namespaceURI,
                                                                           String localName,
                                                                           String attrNamespaceURI,
                                                                           String attrLocalName,
                                                                           String attrValue)
Get all child elements of a node with a particular tag name and a particular attribute/value pair (value is not case sensitive)

Parameters:
node - the node
namespaceURI - the element namespace URI
localName - the element localName
attrNamespaceURI - the attr namespace URI
attrLocalName - the attr localName
attrValue - the attribute value
Returns:
array containing the matching elements, possibly 0 length, but never null

getElementsByTagNameNS

public static NodeList getElementsByTagNameNS(Node node,
                                              String namespaceURI,
                                              String localName)
Get all descendent elements of a node with a particular tag name

Parameters:
node - the node
namespaceURI - the element namespace URI
localName - the element localName
Returns:
NodeList containing the matching elements

getElementsByTagNameWithAttrNS

public static Element[] getElementsByTagNameWithAttrNS(Node node,
                                                       String namespaceURI,
                                                       String localName,
                                                       String attrNamespaceURI,
                                                       String attrLocalName)
Get all descendent elements of an node with a particular tag name and a particular non-empty attribute

Parameters:
node - the node
namespaceURI - the element namespace URI
localName - the element localName
attrNamespaceURI - the attr namespace URI
attrLocalName - the attr localName
Returns:
array containing the matching elements, possibly 0 length, but never null

getElementsByTagNameWithAttrValueNS

public static Element[] getElementsByTagNameWithAttrValueNS(Node node,
                                                            String namespaceURI,
                                                            String localName,
                                                            String attrNamespaceURI,
                                                            String attrLocalName,
                                                            String attrValue)
Get all descendent elements of an node with a particular tag name and a particular attribute/value pair (value is case sensitive)

Parameters:
node - the node
namespaceURI - the element namespace URI
localName - the element localName
attrNamespaceURI - the attr namespace URI
attrLocalName - the attr localName
attrValue - the attribute value
Returns:
array containing the matching elements, possibly 0 length, but never null

removeChildElementsByTagNameNS

public static void removeChildElementsByTagNameNS(Node node,
                                                  String namespaceURI,
                                                  String localName)
Remove all child elements of a node with a particular tag name

Parameters:
node - the node
namespaceURI - the element namespace URI
localName - the element localName

getFirstElementByTagNameNS

public static Element getFirstElementByTagNameNS(Node node,
                                                 String namespaceURI,
                                                 String localName)
Get first descendent element of an node with a particular tag name

Parameters:
node - the node
namespaceURI - the element namespace URI
localName - the element localName
Returns:
the first matching element or null if no such element exists

getFirstElementByTagNameWithAttrValueNS

public static Element getFirstElementByTagNameWithAttrValueNS(Node node,
                                                              String namespaceURI,
                                                              String localName,
                                                              String attrNamespaceURI,
                                                              String attrLocalName,
                                                              String attrValue)
Get the first descendent elements of an node with a particular tag name and a particular attribute/value pair (value is case sensitive)

Parameters:
node - the node
namespaceURI - the element namespace URI
localName - the element localName
attrNamespaceURI - the attr namespace URI
attrLocalName - the attr localName
attrValue - the attribute value
Returns:
the first matching element or null if no such element exists

cloneSubtree

public static Node cloneSubtree(Document targetDoc,
                                Node sourceRoot)
Clone a subtree, possibly into another document

Parameters:
targetDoc - target document for the cloned document
sourceRoot - root of subtree to clone
Returns:
root of the cloned subtree, or null if not cloneable

graftSubtree

public static void graftSubtree(Node parent,
                                Node sourceRoot)
Graft a cloned subtree, possibly into another document

Parameters:
parent - target parent
sourceRoot - root of subtree to clone

cloneDocument

public static Document cloneDocument(Document doc)
Creates clone of a document NOTE: only clones the tree structure, ie. ignores any document attributes

Parameters:
doc - document to clone
Returns:
cloned document

renameElementNS

public static Element renameElementNS(Element element,
                                      String namespaceURI,
                                      String qname)
Rename an element (actually replaces the element with a new one that has the same attributes and children

Parameters:
element - element to be renamed
namespaceURI - the new namespace URI
qname - new qname
Returns:
the renamed Element

removeAllChildren

public static void removeAllChildren(Node node)
Remove all the children of a node

Parameters:
node - the node

getFirstAncestorElementByTagNameNS

public static Element getFirstAncestorElementByTagNameNS(Node node,
                                                         String namespaceURI,
                                                         String localName)
Get the nearest ancestor element of an node with a particular tag name

Parameters:
node - the node
namespaceURI - the element namespace URI
localName - the element localName
Returns:
the first matching element or null if no such element exists

getFirstAncestorElementByTagNameWithAttrNS

public static Element getFirstAncestorElementByTagNameWithAttrNS(Node node,
                                                                 String namespaceURI,
                                                                 String localName,
                                                                 String attrNamespaceURI,
                                                                 String attrLocalName)
Get the nearest ancestor element of an node with a particular tag name and a particular non-empty attribute

Parameters:
node - the node
namespaceURI - the element namespace URI
localName - the element localName
attrNamespaceURI - the attr namespace URI
attrLocalName - the attr localName
Returns:
the first matching element or null if no such element exists

nodeListToNodeArray

public static Node[] nodeListToNodeArray(NodeList list)
creates an array of nodes from a NodeList

Parameters:
list - the nodelist
Returns:
array of nodes containing the same members as the nodelist

elementArrayListToElementArray

public static Element[] elementArrayListToElementArray(ArrayList arrayList)
creates an array of Elements from a ArrayList containing only elements

Parameters:
arrayList - the nodelist
Returns:
array of elements containing the same members as the ArrayList

getAssociationValue

public static String getAssociationValue(Element element)
Get the first association value found under element

Parameters:
element - the element
Returns:
association value (possibly empty, but never null

getAssociationState

public static String getAssociationState(Element element)
Get the first association state found under element from a NodeList

Parameters:
element - an element
Returns:
association state (possibly empty, but never null)

getFirstValue

public static Element getFirstValue(Node node,
                                    String attrName)
Get the first value element for a given attribute

Parameters:
node - the node to start at
attrName - the attribute name
Returns:
the first matching value element or null if no such element exists

copyAttributeNS

public static boolean copyAttributeNS(Element src,
                                      String attrNamespaceURI,
                                      String attrLocalName,
                                      Element dest)
Copy an attribute from one element to another, but only if the attribute has a non-empty value

Parameters:
src - source element
attrNamespaceURI - the attr namespace URI
attrLocalName - the attr localName
dest - destination element
Returns:
true if there was an attribute to copy

copyAttributeNS

public static boolean copyAttributeNS(Element src,
                                      String srcAttrNamespaceURI,
                                      String srcAttrLocalName,
                                      Element dest,
                                      String destAttrNamespaceURI,
                                      String destAttrQName)
Copy an attribute from one element to another, with an new attribute name, but only if the attribute has a non-empty value

Parameters:
src - source element
srcAttrNamespaceURI - the src attr namespace URI
srcAttrLocalName - the src attr localName
dest - destination element
destAttrNamespaceURI - the dest attr namespace URI
destAttrQName - the dest attr qName
Returns:
true if there was an attribute to copy

ensureDOMImpl

public static void ensureDOMImpl(XmlDocument src)
Conditionally convert the passed document to the DirXML DOM implementation.

Parameters:
src - document

getTimestamp

public static Date getTimestamp(Element element)
Get the timestamp for the element

Parameters:
element - the element
Returns:
timestamp if available, null otherwise

getTimestampEventCount

public static int getTimestampEventCount(Element element)
Get the timestamp event count for the element

Parameters:
element - the element
Returns:
timestamp event count if available, 0 otherwise