APIdia Launch Partner
Top Description Constructors Methods
org.jcp.xml.dsig.internal.dom

public final Class DOMUtils

extends Object
Class Inheritance
Imports
java.security.spec.AlgorithmParameterSpec, java.util.List, javax.xml.XMLConstants, javax.xml.crypto.MarshalException, .XMLCryptoContext, .XMLStructure, javax.xml.crypto.dsig.XMLSignature, javax.xml.crypto.dsig.spec.ExcC14NParameterSpec, .XPathFilter2ParameterSpec, .XPathFilterParameterSpec, .XPathType, .XSLTTransformParameterSpec, org.w3c.dom.Attr, .Document, .Element, .Node

Useful static DOM utility methods.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static void
appendChild(Node parent, 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.

public static Element

Returns:

the newly created element
createElement
(Document
the owner document
doc
,
String
the tag
tag
,
String
the namespace URI
nsURI
,
String
the namespace prefix
prefix
)

Creates an element in the specified namespace, with the specified tag and namespace prefix.

public static String

Returns:

the attribute value (may be null if unspecified)
getAttributeValue
(Element
the element containing the attribute
elem
,
String
the name of the attribute
name
)

Returns the attribute value for the attribute with the specified name.

public static Element

Returns:

the first child element of the specified node, or null if there is no such element
getFirstChildElement
(Node
the node
node
)

Returns the first child element of the specified node, or null if there is no such element.

public static Element

Returns:

the first child element of the specified node
getFirstChildElement
(Node
the node
node
,
String localName, String namespaceURI)

Returns the first child element of the specified node and checks that the local name is equal to localName and the namespace is equal to namespaceURI

public static <N> String

Returns:

the attribute value (may be null if unspecified)
getIdAttributeValue
(Element
the element containing the attribute
elem
,
String
the name of the attribute
name
)

Returns the attribute value for the attribute with the specified name.

public static Element

Returns:

the last child element of the specified node, or null if there is no such element
getLastChildElement
(Node
the node
node
)

Returns the last child element of the specified node, or null if there is no such element.

public static Element

Returns:

the next sibling element of the specified node, or null if there is no such element
getNextSiblingElement
(Node
the node
node
)

Returns the next sibling element of the specified node, or null if there is no such element.

public static Element

Returns:

the next sibling element of the specified node
getNextSiblingElement
(Node
the node
node
,
String localName, String namespaceURI)

Returns the next sibling element of the specified node and checks that the local name is equal to localName and the namespace is equal to namespaceURI

public static String

Returns:

the prefix associated with the specified namespace URI, or null if not set
getNSPrefix
(XMLCryptoContext
contains the namespace map
context
,
String
the namespace URI
nsURI
)

Returns the prefix associated with the specified namespace URI

public static Document

Returns:

the owner document
getOwnerDocument
(Node
the node
node
)

Returns the owner document of the specified node.

public static String

Returns:

The string for the qName, for example, "xsd:element".
getQNameString
(String
The prefix, if any. Can be either null or empty.
prefix
,
String
The local name.
localName
)

Create a QName string from a prefix and local name.

public static String

Returns:

the prefix associated with the specified namespace URI, or null if not set
getSignaturePrefix
(XMLCryptoContext
contains the namespace map
context
)

Returns the prefix associated with the XML Signature namespace URI

public static boolean
public static boolean
nodesEqual(Node thisNode, Node otherNode)

Compares 2 nodes for equality.

public static boolean
private static boolean
private static boolean
private static boolean
private static boolean
public static void
removeAllChildren(Node
the parent node whose children are to be removed
node
)

Removes all children nodes from the specified node.

public static void
setAttribute(Element
the element to set the attribute on
elem
,
String
the name of the attribute
name
,
String
the attribute value. If null, no attribute is set.
value
)

Sets an element's attribute (using DOM level 2) with the specified value and namespace prefix.

public static void
setAttributeID(Element
the element to set the attribute on
elem
,
String
the name of the attribute
name
,
String
the attribute value. If null, no attribute is set.
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.

private static Element
verifyElement(Element elem, String localName, String namespaceURI)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

DOMUtilsback to summary
private DOMUtils()

Method Detail

appendChildback to summary
public static void appendChild(Node parent, 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.

createElementback to summary
public static Element createElement(Document doc, String tag, String nsURI, String prefix)

Creates an element in the specified namespace, with the specified tag and namespace prefix.

Parameters
doc:Document

the owner document

tag:String

the tag

nsURI:String

the namespace URI

prefix:String

the namespace prefix

Returns:Element

the newly created element

getAttributeValueback to summary
public static String getAttributeValue(Element elem, 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:Element

the element containing the attribute

name:String

the name of the attribute

Returns:String

the attribute value (may be null if unspecified)

getFirstChildElementback to summary
public static Element getFirstChildElement(Node node)

Returns the first child element of the specified node, or null if there is no such element.

Parameters
node:Node

the node

Returns:Element

the first child element of the specified node, or null if there is no such element

Exceptions
NullPointerException:
if node == null
getFirstChildElementback to summary
public static Element getFirstChildElement(Node node, String localName, String namespaceURI) throws MarshalException

Returns the first child element of the specified node and checks that the local name is equal to localName and the namespace is equal to namespaceURI

Parameters
node:Node

the node

Returns:Element

the first child element of the specified node

Exceptions
MarshalException:
if no such element or the local name is not equal to localName
NullPointerException:
if node == null
getIdAttributeValueback to summary
public static <N> String getIdAttributeValue(Element elem, 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:Element

the element containing the attribute

name:String

the name of the attribute

Returns:String

the attribute value (may be null if unspecified)

getLastChildElementback to summary
public static Element getLastChildElement(Node node)

Returns the last child element of the specified node, or null if there is no such element.

Parameters
node:Node

the node

Returns:Element

the last child element of the specified node, or null if there is no such element

Exceptions
NullPointerException:
if node == null
getNextSiblingElementback to summary
public static Element getNextSiblingElement(Node node)

Returns the next sibling element of the specified node, or null if there is no such element.

Parameters
node:Node

the node

Returns:Element

the next sibling element of the specified node, or null if there is no such element

Exceptions
NullPointerException:
if node == null
getNextSiblingElementback to summary
public static Element getNextSiblingElement(Node node, String localName, String namespaceURI) throws MarshalException

Returns the next sibling element of the specified node and checks that the local name is equal to localName and the namespace is equal to namespaceURI

Parameters
node:Node

the node

Returns:Element

the next sibling element of the specified node

Exceptions
MarshalException:
if no such element or the local name is not equal to localName
NullPointerException:
if node == null
getNSPrefixback to summary
public static String getNSPrefix(XMLCryptoContext context, String nsURI)

Returns the prefix associated with the specified namespace URI

Parameters
context:XMLCryptoContext

contains the namespace map

nsURI:String

the namespace URI

Returns:String

the prefix associated with the specified namespace URI, or null if not set

getOwnerDocumentback to summary
public static Document getOwnerDocument(Node node)

Returns the owner document of the specified node.

Parameters
node:Node

the node

Returns:Document

the owner document

getQNameStringback to summary
public static String getQNameString(String prefix, String localName)

Create a QName string from a prefix and local name.

Parameters
prefix:String

The prefix, if any. Can be either null or empty.

localName:String

The local name.

Returns:String

The string for the qName, for example, "xsd:element".

getSignaturePrefixback to summary
public static String getSignaturePrefix(XMLCryptoContext context)

Returns the prefix associated with the XML Signature namespace URI

Parameters
context:XMLCryptoContext

contains the namespace map

Returns:String

the prefix associated with the specified namespace URI, or null if not set

isNamespaceback to summary
public static boolean isNamespace(Node node)
nodesEqualback to summary
public static boolean nodesEqual(Node thisNode, Node otherNode)

Compares 2 nodes for equality.

paramsEqualback to summary
public static boolean paramsEqual(AlgorithmParameterSpec spec1, AlgorithmParameterSpec spec2)
paramsEqualback to summary
private static boolean paramsEqual(XPathFilter2ParameterSpec spec1, XPathFilter2ParameterSpec spec2)
paramsEqualback to summary
private static boolean paramsEqual(ExcC14NParameterSpec spec1, ExcC14NParameterSpec spec2)
paramsEqualback to summary
private static boolean paramsEqual(XPathFilterParameterSpec spec1, XPathFilterParameterSpec spec2)
paramsEqualback to summary
private static boolean paramsEqual(XSLTTransformParameterSpec spec1, XSLTTransformParameterSpec spec2)
removeAllChildrenback to summary
public static void removeAllChildren(Node node)

Removes all children nodes from the specified node.

Parameters
node:Node

the parent node whose children are to be removed

setAttributeback to summary
public static void setAttribute(Element elem, String name, String value)

Sets an element's attribute (using DOM level 2) with the specified value and namespace prefix.

Parameters
elem:Element

the element to set the attribute on

name:String

the name of the attribute

value:String

the attribute value. If null, no attribute is set.

setAttributeIDback to summary
public static void setAttributeID(Element elem, String name, 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:Element

the element to set the attribute on

name:String

the name of the attribute

value:String

the attribute value. If null, no attribute is set.

verifyElementback to summary
private static Element verifyElement(Element elem, String localName, String namespaceURI) throws MarshalException