Package eu.europa.esig.dss.xml.utils
Class DomUtils
java.lang.Object
eu.europa.esig.dss.xml.utils.DomUtils
-
Method Summary
Modifier and TypeMethodDescriptionstatic Element
addElement
(Document document, Element parentDom, DSSNamespace namespace, DSSElement element) This method creates and adds a new XMLElement
static void
addNamespaceAttribute
(Element element, DSSNamespace namespace) Adds a namespace attribute to the elementstatic Element
addTextElement
(Document document, Element parentDom, DSSNamespace namespace, DSSElement element, String value) This method creates and adds a new XMLElement
with text valuestatic void
adoptChildren
(Element parentElement, Node toBeAdopted) Adopts all children of thetoBeAdopted
Node, excluding the Node itself.static DSSNamespace
browseRecursivelyForNamespaceWithUri
(Element element, String uri) This method browses throughelement
looking for a namespace with the targeturi
and returnsDSSNamespace
if foundstatic Document
buildDOM()
Creates the new empty Document.static Document
buildDOM
(byte[] bytes) This method returns theDocument
created based on byte array.static Document
buildDOM
(DSSDocument dssDocument) This method returns theDocument
created based on theDSSDocument
.static Document
buildDOM
(InputStream inputStream) This method returns theDocument
created based on the XML InputStream.static Document
This method returns theDocument
created based on the XML string.static DSSDocument
createDssDocumentFromDomDocument
(Document document, String name) This method creates a new InMemoryDocument with theDocument
content and the given namestatic Element
createElementNS
(Document documentDom, DSSNamespace namespace, DSSElement element) Creates an element with the given namespacestatic XMLGregorianCalendar
Converts a givenDate
to a newXMLGregorianCalendar
.static XPathExpression
createXPathExpression
(String xpathString) This method creates a new instance of XPathExpression with the given xpath expressionstatic Document
excludeComments
(Node node) Returns a Document with excluded comments.getChildrenNames
(Node xmlNode, String xPathString) This method returns the list of children's names for a givenNode
.This method returns stored namespace definitionsstatic Date
This method allows to convert the given text (XML representation of a date) to theDate
.static Element
getElement
(Node xmlNode, String xPathString) Returns the Element corresponding to the XPath query.static Element
getElementById
(Node node, String id) Extract an element from the given documentnode
with the given Id.static String
Gets Id value from the given URI reference Ex.static Node
Returns the Node corresponding to the XPath query.static byte[]
getNodeBytes
(Node node) Returns bytes of the givennode
static NodeList
getNodeList
(Node xmlNode, String xPathString) Returns the NodeList corresponding to the XPath query.static int
getNodesAmount
(Node xmlNode, String xPathString) Returns an amount of found nodes matching thexPathString
static DocumentBuilderFactory
This method returns a new instance of DocumentBuilderFactory with configured security featuresstatic Transformer
This method returns a new instance of Transformer with secured features enabledstatic TransformerFactory
This method returns a new instance of TransformerFactory with secured features enabledstatic String
Returns the String value of the corresponding to the XPath query.static String
Returns case-insensitive xPath expressionstatic String
getXPointerId
(String uri) Method getXPointerId Seeorg.apache.xml.security.utils.resolver.implementations.ResolverXPointer
static boolean
isDOM
(byte[] bytes) This method returns true if the binaries contains aDocument
static boolean
isDOM
(DSSDocument dssDocument) This method returns true if the provided document is a valid XMLDocument
static boolean
isElementReference
(String uri) Returns TRUE if the provideduri
refers to an element in the signaturestatic boolean
isNotEmpty
(Node xmlNode, String xPathString) Returns true if the xpath query contains somethingstatic boolean
isRootXPointer
(String uri) This method checks if the XPointer refers the document root.static boolean
isXPointerQuery
(String uriValue) Indicates if the given URI is an XPointer query.static boolean
registerNamespace
(DSSNamespace namespace) This method allows to register a namespace and associated prefix.static byte[]
serializeNode
(Node xmlNode) This method performs the serialization of the given nodestatic void
setAttributeNS
(Element element, DSSNamespace namespace, DSSAttribute attribute, String value) This method adds an attribute with the namespace and the valuestatic void
setTextNode
(Document document, Element parentDom, String text) This method sets a text node to the given DOM element.static boolean
startsFromHash
(String uri) Returns TRUE if the provideduri
starts from the hash "#" characterstatic boolean
startsWithXmlPreamble
(byte[] byteArray) Checks if the givenbyteArray
content starts with an XML Preamble'<'
Processes values with or without BOM-encoding NOTE: does not check XML-conformity of the whole file call isDOM(byteArray) for a deep checkstatic boolean
startsWithXmlPreamble
(DSSDocument document) Checks if the given document starts with an XML Preamble'<'
Processes values with or without BOM-encoding NOTE: does not check XML-conformity of the whole file call isDOM(DSSDocument) for a deep checkstatic String
toElementReference
(String uri) This method translates the givenString
to a local element reference with the given URI.static void
writeDocumentTo
(Document dom, OutputStream os) This method writes theDocument
content to an outputStreamstatic String
xmlToString
(Node node) This method allows to convert an XMLNode
to aString
.
-
Method Details
-
registerNamespace
This method allows to register a namespace and associated prefix. If the prefix exists already it is replaced.- Parameters:
namespace
- namespace object with the prefix and the URI- Returns:
- true if this map did not already contain the specified element
-
getSecureDocumentBuilderFactory
This method returns a new instance of DocumentBuilderFactory with configured security features- Returns:
- an instance of DocumentBuilderFactory with enabled security features
-
getSecureTransformerFactory
This method returns a new instance of TransformerFactory with secured features enabled- Returns:
- an instance of TransformerFactory with enabled secure features
-
getSecureTransformer
This method returns a new instance of Transformer with secured features enabled- Returns:
- an instance of Transformer with enabled secure features
-
startsWithXmlPreamble
public static boolean startsWithXmlPreamble(byte[] byteArray) Checks if the givenbyteArray
content starts with an XML Preamble'<'
Processes values with or without BOM-encoding NOTE: does not check XML-conformity of the whole file call isDOM(byteArray) for a deep check- Parameters:
byteArray
- byte array to verify- Returns:
- TRUE if the provided byte array starts from xmlPreamble, FALSE otherwise
-
startsWithXmlPreamble
Checks if the given document starts with an XML Preamble'<'
Processes values with or without BOM-encoding NOTE: does not check XML-conformity of the whole file call isDOM(DSSDocument) for a deep check- Parameters:
document
-DSSDocument
to verify- Returns:
- TRUE if the provided document starts from xmlPreamble, FALSE otherwise
-
buildDOM
-
buildDOM
-
buildDOM
-
buildDOM
This method returns theDocument
created based on the XML InputStream.- Parameters:
inputStream
- The inputStream stream representing the dssDocument to be created.- Returns:
- a new
Document
fromInputStream
@
-
buildDOM
This method returns theDocument
created based on theDSSDocument
.- Parameters:
dssDocument
- The DSS representation of the document from which the dssDocument is created.- Returns:
- a new
Document
fromDSSDocument
-
isDOM
public static boolean isDOM(byte[] bytes) This method returns true if the binaries contains aDocument
- Parameters:
bytes
- the binaries to be tested- Returns:
- true if the binaries represent an XML
-
isDOM
This method returns true if the provided document is a valid XMLDocument
- Parameters:
dssDocument
-DSSDocument
to be tested- Returns:
- true if the document is an XML
-
setAttributeNS
public static void setAttributeNS(Element element, DSSNamespace namespace, DSSAttribute attribute, String value) This method adds an attribute with the namespace and the value- Parameters:
element
- the element where the attribute is needednamespace
- the used namespace for the attributeattribute
- the attribute to be addedvalue
- the value for the given attribute
-
addElement
public static Element addElement(Document document, Element parentDom, DSSNamespace namespace, DSSElement element) This method creates and adds a new XMLElement
- Parameters:
document
- root documentparentDom
- parent nodenamespace
- namespace definitionelement
- the type of element name- Returns:
- added element
-
adoptChildren
-
createXPathExpression
This method creates a new instance of XPathExpression with the given xpath expression- Parameters:
xpathString
- XPath query string- Returns:
- an instance of
XPathExpression
for the given xpathString @ if
-
getValue
-
getNodeList
-
getNode
-
getElement
-
isNotEmpty
-
getNodesAmount
-
addTextElement
public static Element addTextElement(Document document, Element parentDom, DSSNamespace namespace, DSSElement element, String value) This method creates and adds a new XMLElement
with text value- Parameters:
document
- root documentparentDom
- parent nodenamespace
- namespaceelement
- element typevalue
- element text node value- Returns:
- added element
-
setTextNode
-
createXMLGregorianCalendar
Converts a givenDate
to a newXMLGregorianCalendar
.- Parameters:
date
- the date to be converted- Returns:
- the new
XMLGregorianCalendar
or null
-
getDate
-
getChildrenNames
-
writeDocumentTo
-
createDssDocumentFromDomDocument
-
xmlToString
-
getCurrentNamespaces
-
getXPathByIdAttribute
-
getId
-
getElementById
Extract an element from the given documentnode
with the given Id. The method is namespace independent. -
startsFromHash
-
isElementReference
-
toElementReference
-
isXPointerQuery
Indicates if the given URI is an XPointer query.- Parameters:
uriValue
- URI to be analysed- Returns:
- true if it is an XPointer query
-
getXPointerId
-
isRootXPointer
-
createElementNS
public static Element createElementNS(Document documentDom, DSSNamespace namespace, DSSElement element) Creates an element with the given namespace- Parameters:
documentDom
-Document
to add the element intonamespace
-DSSNamespace
namespace to be definedelement
-DSSElement
to add- Returns:
- created
Element
with the namespace
-
addNamespaceAttribute
Adds a namespace attribute to the element- Parameters:
element
-Element
to add a namespace tonamespace
-DSSNamespace
to add
-
excludeComments
-
browseRecursivelyForNamespaceWithUri
This method browses throughelement
looking for a namespace with the targeturi
and returnsDSSNamespace
if found- Parameters:
element
-Element
to search for a namespace inuri
-String
URI of the namespace to look for- Returns:
DSSNamespace
if the target namespace has been found, null otherwise
-
serializeNode
This method performs the serialization of the given node- Parameters:
xmlNode
- The node to be serialized.- Returns:
- the serialized bytes
-
getNodeBytes
-