XML Security, 1.6

com.ibm.xml.enc.dom
Class DOMUtils

java.lang.Object
  extended by com.ibm.xml.enc.dom.DOMUtils

public class DOMUtils
extends java.lang.Object

Useful static DOM utility methods.


Nested Class Summary
(package private) static class DOMUtils.NodeSet
           
 
Method Summary
static void appendChild(org.w3c.dom.Node parent, org.w3c.dom.Node child)
          Checks if child element has same owner document before appending to the parent, and imports it to the parent's document if necessary.
static org.w3c.dom.Element createElement(org.w3c.dom.Document doc, java.lang.String tag, java.lang.String nsURI, java.lang.String prefix)
          Creates an element in the specified namespace, with the specified tag and namespace prefix.
static java.util.Map getAttributes(org.w3c.dom.Node node)
           
static java.lang.String getAttributeValue(org.w3c.dom.Element elem, java.lang.String name)
          Returns the attribute value for the attribute with the specified name.
static java.lang.String getEncryptionPrefix(DOMEncryptContext context)
          Returns the prefix associated with the XML Encryption namespace URI
static org.w3c.dom.Node getFirstChild2(org.w3c.dom.Node node)
          Returns the first child of node.
static org.w3c.dom.Element getFirstChildElement(org.w3c.dom.Node node)
          Returns the first child element of the specified node, or null if there is no such element.
static org.w3c.dom.Element getLastChildElement(org.w3c.dom.Node node)
          Returns the last child element of the specified node, or null if there is no such element.
static org.w3c.dom.Node getNextSibling2(org.w3c.dom.Node node)
           
static org.w3c.dom.Element getNextSiblingElement(org.w3c.dom.Node node)
          Returns the next sibling element of the specified node, or null if there is no such element.
static java.lang.String getNSPrefix(XMLCryptoContext context, java.lang.String nsURI)
          Returns the prefix associated with the specified namespace URI
static org.w3c.dom.Document getOwnerDocument(org.w3c.dom.Node node)
          Returns the owner document of the specified node.
static java.lang.String getSignaturePrefix(XMLCryptoContext context)
          Returns the prefix associated with the XML Signature namespace URI
static java.lang.String getTextContent(org.w3c.dom.Node node)
           
static boolean nodesEqual(org.w3c.dom.Node thisNode, org.w3c.dom.Node otherNode)
          Compares 2 nodes for equality.
static java.util.Set nodeSet(org.w3c.dom.NodeList nl)
          Returns a Set of Nodes, backed by the specified NodeList.
static boolean paramsEqual(java.security.spec.AlgorithmParameterSpec spec1, java.security.spec.AlgorithmParameterSpec spec2)
           
static void removeAllChildren(org.w3c.dom.Node node)
          Removes all children nodes from the specified node.
static void setAttribute(org.w3c.dom.Element elem, java.lang.String name, java.lang.String value)
          Sets an element's attribute (using DOM level 2) with the specified value and namespace prefix.
static void setAttributeID(org.w3c.dom.Element elem, java.lang.String name, java.lang.String value)
          Sets an element's attribute (using DOM level 2) with the specified value and namespace prefix AND registers the ID value with the specified element.
static void writeDoc(org.w3c.dom.Node doc, java.lang.String filename)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getOwnerDocument

public static org.w3c.dom.Document getOwnerDocument(org.w3c.dom.Node node)
Returns the owner document of the specified node.

Parameters:
node - the node
Returns:
the owner document

createElement

public static org.w3c.dom.Element createElement(org.w3c.dom.Document doc,
                                                java.lang.String tag,
                                                java.lang.String nsURI,
                                                java.lang.String prefix)
Creates an element in the specified namespace, with the specified tag and namespace prefix.

Parameters:
doc - the owner document
tag - the tag
nsURI - the namespace URI
prefix - the namespace prefix
Returns:
the newly created element

setAttribute

public static void setAttribute(org.w3c.dom.Element elem,
                                java.lang.String name,
                                java.lang.String value)
Sets an element's attribute (using DOM level 2) with the specified value and namespace prefix.

Parameters:
elem - the element to set the attribute on
name - the name of the attribute
value - the attribute value. If null, no attribute is set.

setAttributeID

public static void setAttributeID(org.w3c.dom.Element elem,
                                  java.lang.String name,
                                  java.lang.String value)
Sets an element's attribute (using DOM level 2) with the specified value and namespace prefix AND registers the ID value with the specified element. This is for resolving same-document ID references.

Parameters:
elem - the element to set the attribute on
name - the name of the attribute
value - the attribute value. If null, no attribute is set.

getFirstChildElement

public static org.w3c.dom.Element getFirstChildElement(org.w3c.dom.Node node)
Returns the first child element of the specified node, or null if there is no such element.

Parameters:
node - the node
Returns:
the first child element of the specified node, or null if there is no such element
Throws:
java.lang.NullPointerException - if node == null

getLastChildElement

public static org.w3c.dom.Element getLastChildElement(org.w3c.dom.Node node)
Returns the last child element of the specified node, or null if there is no such element.

Parameters:
node - the node
Returns:
the last child element of the specified node, or null if there is no such element
Throws:
java.lang.NullPointerException - if node == null

getNextSiblingElement

public static org.w3c.dom.Element getNextSiblingElement(org.w3c.dom.Node node)
Returns the next sibling element of the specified node, or null if there is no such element.

Parameters:
node - the node
Returns:
the next sibling element of the specified node, or null if there is no such element
Throws:
java.lang.NullPointerException - if node == null

getAttributeValue

public static java.lang.String getAttributeValue(org.w3c.dom.Element elem,
                                                 java.lang.String name)
Returns the attribute value for the attribute with the specified name. Returns null if there is no such attribute, or the empty string if the attribute value is empty.

This works around a limitation of the DOM Element.getAttributeNode method, which does not distinguish between an unspecified attribute and an attribute with a value of "" (it returns "" for both cases).

Parameters:
elem - the element containing the attribute
name - the name of the attribute
Returns:
the attribute value (may be null if unspecified)

getAttributes

public static java.util.Map getAttributes(org.w3c.dom.Node node)

nodeSet

public static java.util.Set nodeSet(org.w3c.dom.NodeList nl)
Returns a Set of Nodes, backed by the specified NodeList.

Parameters:
nl - the NodeList
Returns:
a Set of Nodes

getNSPrefix

public static java.lang.String getNSPrefix(XMLCryptoContext context,
                                           java.lang.String nsURI)
Returns the prefix associated with the specified namespace URI

Parameters:
context - contains the namespace map
nsURI - the namespace URI
Returns:
the prefix associated with the specified namespace URI, or null if not set

getEncryptionPrefix

public static java.lang.String getEncryptionPrefix(DOMEncryptContext context)
Returns the prefix associated with the XML Encryption namespace URI

Parameters:
context - contains the namespace map
Returns:
the prefix associated with the specified namespace URI, or null if not set

getSignaturePrefix

public static java.lang.String getSignaturePrefix(XMLCryptoContext context)
Returns the prefix associated with the XML Signature namespace URI

Parameters:
context - contains the namespace map
Returns:
the prefix associated with the specified namespace URI, or null if not set

removeAllChildren

public static void removeAllChildren(org.w3c.dom.Node node)
Removes all children nodes from the specified node.

Parameters:
node - the parent node whose children are to be removed

nodesEqual

public static boolean nodesEqual(org.w3c.dom.Node thisNode,
                                 org.w3c.dom.Node otherNode)
Compares 2 nodes for equality. Implementation is not complete.


appendChild

public static void appendChild(org.w3c.dom.Node parent,
                               org.w3c.dom.Node child)
Checks if child element has same owner document before appending to the parent, and imports it to the parent's document if necessary.


paramsEqual

public static boolean paramsEqual(java.security.spec.AlgorithmParameterSpec spec1,
                                  java.security.spec.AlgorithmParameterSpec spec2)

writeDoc

public static void writeDoc(org.w3c.dom.Node doc,
                            java.lang.String filename)
                     throws java.lang.Exception
Throws:
java.lang.Exception

getFirstChild2

public static org.w3c.dom.Node getFirstChild2(org.w3c.dom.Node node)
Returns the first child of node. This method ignores EntityReference nodes.

See Also:
#getLastChild2

getNextSibling2

public static org.w3c.dom.Node getNextSibling2(org.w3c.dom.Node node)

getTextContent

public static java.lang.String getTextContent(org.w3c.dom.Node node)

XML Security, 1.6

Portions Copyright 2003, 2012 IBM Corporation.
Portions Copyright 2003, 2012 Oracle and/or its affiliates.