Class DOMUtils
java.lang.Object
org.apache.jcp.xml.dsig.internal.dom.DOMUtils
Useful static DOM utility methods.
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic 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.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.static String
getAttributeValue
(Element elem, String name) Returns the attribute value for the attribute with the specified name.static Element
getFirstChildElement
(Node node) Returns the first child element of the specified node, or null if there is no such element.static Element
getFirstChildElement
(Node node, String localName) Deprecated.static Element
getFirstChildElement
(Node node, String localName, String namespaceURI) Returns the first child element of the specified node and checks that the local name is equal tolocalName
and the namespace is equal tonamespaceURI
static <N> String
getIdAttributeValue
(Element elem, String name) Returns the attribute value for the attribute with the specified name.static Element
getLastChildElement
(Node node) Returns the last child element of the specified node, or null if there is no such element.static Element
getNextSiblingElement
(Node node) Returns the next sibling element of the specified node, or null if there is no such element.static Element
getNextSiblingElement
(Node node, String localName) Deprecated.static Element
getNextSiblingElement
(Node node, String localName, String namespaceURI) Returns the next sibling element of the specified node and checks that the local name is equal tolocalName
and the namespace is equal tonamespaceURI
static String
getNSPrefix
(XMLCryptoContext context, String nsURI) Returns the prefix associated with the specified namespace URIstatic Document
getOwnerDocument
(Node node) Returns the owner document of the specified node.static String
getQNameString
(String prefix, String localName) Create a QName string from a prefix and local name.static String
getSignaturePrefix
(XMLCryptoContext context) Returns the prefix associated with the XML Signature namespace URIstatic boolean
isNamespace
(Node node) static boolean
nodesEqual
(Node thisNode, Node otherNode) Compares 2 nodes for equality.Returns a Set ofNode
s, backed by the specifiedNodeList
.static boolean
paramsEqual
(AlgorithmParameterSpec spec1, AlgorithmParameterSpec spec2) private static boolean
paramsEqual
(ExcC14NParameterSpec spec1, ExcC14NParameterSpec spec2) private static boolean
paramsEqual
(XPathFilter2ParameterSpec spec1, XPathFilter2ParameterSpec spec2) private static boolean
paramsEqual
(XPathFilterParameterSpec spec1, XPathFilterParameterSpec spec2) private static boolean
paramsEqual
(XSLTTransformParameterSpec spec1, XSLTTransformParameterSpec spec2) static void
removeAllChildren
(Node node) Removes all children nodes from the specified node.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.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.private static Element
verifyElement
(Element elem, String localName) private static Element
verifyElement
(Element elem, String localName, String namespaceURI)
-
Constructor Details
-
DOMUtils
private DOMUtils()
-
-
Method Details
-
getOwnerDocument
Returns the owner document of the specified node.- Parameters:
node
- the node- Returns:
- the owner document
-
getQNameString
Create a QName string from a prefix and local name.- Parameters:
prefix
- The prefix, if any. Can be either null or empty.localName
- The local name.- Returns:
- The string for the qName, for example, "xsd:element".
-
createElement
Creates an element in the specified namespace, with the specified tag and namespace prefix.- Parameters:
doc
- the owner documenttag
- the tagnsURI
- the namespace URIprefix
- the namespace prefix- Returns:
- the newly created element
-
setAttribute
Sets an element's attribute (using DOM level 2) with the specified value and namespace prefix.- Parameters:
elem
- the element to set the attribute onname
- the name of the attributevalue
- the attribute value. If null, no attribute is set.
-
setAttributeID
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 onname
- the name of the attributevalue
- the attribute value. If null, no attribute is set.
-
getFirstChildElement
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:
NullPointerException
- ifnode == null
-
getFirstChildElement
@Deprecated public static Element getFirstChildElement(Node node, String localName) throws MarshalException Deprecated.Returns the first child element of the specified node and checks that the local name is equal tolocalName
.- Parameters:
node
- the node- Returns:
- the first child element of the specified node
- Throws:
NullPointerException
- ifnode == null
MarshalException
- if no such element or the local name is not equal tolocalName
-
getFirstChildElement
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 tolocalName
and the namespace is equal tonamespaceURI
- Parameters:
node
- the node- Returns:
- the first child element of the specified node
- Throws:
NullPointerException
- ifnode == null
MarshalException
- if no such element or the local name is not equal tolocalName
-
verifyElement
- Throws:
MarshalException
-
verifyElement
private static Element verifyElement(Element elem, String localName, String namespaceURI) throws MarshalException - Throws:
MarshalException
-
getLastChildElement
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:
NullPointerException
- ifnode == null
-
getNextSiblingElement
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:
NullPointerException
- ifnode == null
-
getNextSiblingElement
@Deprecated public static Element getNextSiblingElement(Node node, String localName) throws MarshalException Deprecated.Returns the next sibling element of the specified node and checks that the local name is equal tolocalName
.- Parameters:
node
- the node- Returns:
- the next sibling element of the specified node
- Throws:
NullPointerException
- ifnode == null
MarshalException
- if no such element or the local name is not equal tolocalName
-
getNextSiblingElement
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 tolocalName
and the namespace is equal tonamespaceURI
- Parameters:
node
- the node- Returns:
- the next sibling element of the specified node
- Throws:
NullPointerException
- ifnode == null
MarshalException
- if no such element or the local name is not equal tolocalName
-
getAttributeValue
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 attributename
- the name of the attribute- Returns:
- the attribute value (may be null if unspecified)
-
getIdAttributeValue
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 attributename
- the name of the attribute- Returns:
- the attribute value (may be null if unspecified)
-
nodeSet
Returns a Set ofNode
s, backed by the specifiedNodeList
.- Parameters:
nl
- the NodeList- Returns:
- a Set of Nodes
-
getNSPrefix
Returns the prefix associated with the specified namespace URI- Parameters:
context
- contains the namespace mapnsURI
- the namespace URI- Returns:
- the prefix associated with the specified namespace URI, or null if not set
-
getSignaturePrefix
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
Removes all children nodes from the specified node.- Parameters:
node
- the parent node whose children are to be removed
-
nodesEqual
Compares 2 nodes for equality. Implementation is not complete. -
appendChild
Checks if child element has same owner document before appending to the parent, and imports it to the parent's document if necessary. -
paramsEqual
-
paramsEqual
private static boolean paramsEqual(XPathFilter2ParameterSpec spec1, XPathFilter2ParameterSpec spec2) -
paramsEqual
-
paramsEqual
-
paramsEqual
private static boolean paramsEqual(XSLTTransformParameterSpec spec1, XSLTTransformParameterSpec spec2) -
isNamespace
-