Package eu.europa.esig.dss
Class DomUtils
- java.lang.Object
-
- eu.europa.esig.dss.DomUtils
-
public final class DomUtils extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static intTRANSFORMER_INDENT_NUMBER
-
Method Summary
Modifier and Type Method Description static ElementaddElement(Document document, Element parentDom, String namespace, String name)This method creates and adds a new XMLElementstatic ElementaddTextElement(Document document, Element parentDom, String namespace, String name, String value)This method creates and adds a new XMLElementwith text valuestatic DocumentbuildDOM()Creates the new empty Document.static DocumentbuildDOM(byte[] bytes)This method returns theDocumentcreated based on byte array.static DocumentbuildDOM(DSSDocument dssDocument)This method returns theDocumentcreated based on theDSSDocument.static DocumentbuildDOM(InputStream inputStream)This method returns theDocumentcreated based on the XML inputStream.static DocumentbuildDOM(String xmlString)This method returns theDocumentcreated based on the XML string.static DSSDocumentcreateDssDocumentFromDomDocument(Document document, String name)This method creates a new InMemoryDocument with theDocumentcontent and the given namestatic XMLGregorianCalendarcreateXMLGregorianCalendar(Date date)Converts a givenDateto a newXMLGregorianCalendar.static XPathExpressioncreateXPathExpression(String xpathString)This method creates a new instance of XPathExpression with the given xpath expressionstatic voiddisableFeature(String feature)Disables a feature for the DocumentBuilderFactorystatic voidenableFeature(String feature)Enables a feature for the DocumentBuilderFactorystatic List<String>getChildrenNames(Node xmlNode, String xPathString)This method returns the list of children's names for a givenNode.static Map<String,String>getCurrentNamespaces()This method returns stored namespace definitionsstatic DategetDate(String text)This method allows to convert the given text (XML representation of a date) to theDate.static ElementgetElement(Node xmlNode, String xPathString)Returns the Element corresponding to the XPath query.static StringgetId(String uri)static NodegetNode(Node xmlNode, String xPathString)Returns the Node corresponding to the XPath query.static NodeListgetNodeList(Node xmlNode, String xPathString)Returns the NodeList corresponding to the XPath query.static TransformergetSecureTransformer()This method returns a new instance of Transformer with secured features enabledstatic TransformerFactorygetSecureTransformerFactory()This method returns a new instance of TransformerFactory with secured features enabledstatic StringgetValue(Node xmlNode, String xPathString)Returns the String value of the corresponding to the XPath query.static StringgetXPathByIdAttribute(String uri)Returns case-insensitive xPath expressionstatic booleanisDOM(byte[] bytes)This method returns true if the binaries contains aDocumentstatic booleanisElementReference(String uri)Returns TRUE if the providedurirefers to an element in the signaturestatic booleanisNotEmpty(Node xmlNode, String xPathString)Returns true if the xpath query contains somethingstatic booleanisXPointerQuery(String uriValue)Indicates if the given URI is an XPointer query.static booleanregisterNamespace(String prefix, String namespace)This method allows to register a namespace and associated prefix.static voidsetTextNode(Document document, Element parentDom, String text)This method sets a text node to the given DOM element.static voidwriteDocumentTo(Document dom, OutputStream os)This method writes theDocumentcontent to an outputStreamstatic StringxmlToString(Node node)This method allows to convert an XMLNodeto aString.
-
-
-
Field Detail
-
TRANSFORMER_INDENT_NUMBER
public static final int TRANSFORMER_INDENT_NUMBER
- See Also:
- Constant Field Values
-
-
Method Detail
-
enableFeature
public static void enableFeature(String feature) throws ParserConfigurationException
Enables a feature for the DocumentBuilderFactory- Parameters:
feature-Stringfeature name (URL) to enable- Throws:
ParserConfigurationException
-
disableFeature
public static void disableFeature(String feature) throws ParserConfigurationException
Disables a feature for the DocumentBuilderFactory- Parameters:
feature-Stringfeature name (URL) to disable- Throws:
ParserConfigurationException
-
registerNamespace
public static boolean registerNamespace(String prefix, String namespace)
This method allows to register a namespace and associated prefix. If the prefix exists already it is replaced.- Parameters:
prefix- namespace prefixnamespace- namespace- Returns:
- true if this map did not already contain the specified element
-
getSecureTransformerFactory
public static TransformerFactory getSecureTransformerFactory()
This method returns a new instance of TransformerFactory with secured features enabled- Returns:
- an instance of TransformerFactory with enabled secure features
-
getSecureTransformer
public static Transformer getSecureTransformer()
This method returns a new instance of Transformer with secured features enabled- Returns:
- an instance of Transformer with enabled secure features
-
buildDOM
public static Document buildDOM()
Creates the new empty Document.- Returns:
- a new empty Document
-
buildDOM
public static Document buildDOM(String xmlString)
This method returns theDocumentcreated based on the XML string.- Parameters:
xmlString- The string representing the dssDocument to be created.- Returns:
- a new
Documentwith the xmlString content
-
buildDOM
public static Document buildDOM(byte[] bytes)
This method returns theDocumentcreated based on byte array.- Parameters:
bytes- The bytes array representing the dssDocument to be created.- Returns:
- a new
Documentwith the bytes content
-
buildDOM
public static Document buildDOM(DSSDocument dssDocument)
This method returns theDocumentcreated based on theDSSDocument.- Parameters:
dssDocument- The DSS representation of the document from which the dssDocument is created.- Returns:
- a new
DocumentfromDSSDocument
-
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 is a XML
-
buildDOM
public static Document buildDOM(InputStream inputStream)
This method returns theDocumentcreated based on the XML inputStream.- Parameters:
inputStream- The inputStream stream representing the dssDocument to be created.- Returns:
- a new
DocumentfromInputStream@
-
addElement
public static Element addElement(Document document, Element parentDom, String namespace, String name)
This method creates and adds a new XMLElement- Parameters:
document- root documentparentDom- parent nodenamespace- namespacename- element name- Returns:
- added element
-
createXPathExpression
public static XPathExpression createXPathExpression(String xpathString)
This method creates a new instance of XPathExpression with the given xpath expression- Parameters:
xpathString- XPath query string- Returns:
- an instance of
XPathExpressionfor the given xpathString @ if
-
getValue
public static String getValue(Node xmlNode, String xPathString)
Returns the String value of the corresponding to the XPath query.- Parameters:
xmlNode- The node where the search should be performed.xPathString- XPath query string- Returns:
- string value of the XPath query
-
getNodeList
public static NodeList getNodeList(Node xmlNode, String xPathString)
Returns the NodeList corresponding to the XPath query.- Parameters:
xmlNode- The node where the search should be performed.xPathString- XPath query string- Returns:
- the NodeList corresponding to the XPath query
-
getNode
public static Node getNode(Node xmlNode, String xPathString)
Returns the Node corresponding to the XPath query.- Parameters:
xmlNode- The node where the search should be performed.xPathString- XPath query string- Returns:
- the Node corresponding to the XPath query.
-
getElement
public static Element getElement(Node xmlNode, String xPathString)
Returns the Element corresponding to the XPath query.- Parameters:
xmlNode- The node where the search should be performed.xPathString- XPath query string- Returns:
- the Element corresponding to the XPath query
-
isNotEmpty
public static boolean isNotEmpty(Node xmlNode, String xPathString)
Returns true if the xpath query contains something- Parameters:
xmlNode- the current nodexPathString- the expected child node- Returns:
- true if the current node has any filled child node
-
addTextElement
public static Element addTextElement(Document document, Element parentDom, String namespace, String name, String value)
This method creates and adds a new XMLElementwith text value- Parameters:
document- root documentparentDom- parent nodenamespace- namespacename- element namevalue- element text node value- Returns:
- added element
-
setTextNode
public static void setTextNode(Document document, Element parentDom, String text)
This method sets a text node to the given DOM element.- Parameters:
document- root documentparentDom- parent nodetext- text to be added
-
createXMLGregorianCalendar
public static XMLGregorianCalendar createXMLGregorianCalendar(Date date)
Converts a givenDateto a newXMLGregorianCalendar.- Parameters:
date- the date to be converted- Returns:
- the new
XMLGregorianCalendaror null
-
getDate
public static Date getDate(String text)
This method allows to convert the given text (XML representation of a date) to theDate.- Parameters:
text- the text representing the XML date- Returns:
Dateconverted or null
-
getChildrenNames
public static List<String> getChildrenNames(Node xmlNode, String xPathString)
This method returns the list of children's names for a givenNode.- Parameters:
xmlNode- The node where the search should be performed.xPathString- XPath query string- Returns:
Listof children's names
-
writeDocumentTo
public static void writeDocumentTo(Document dom, OutputStream os)
This method writes theDocumentcontent to an outputStream- Parameters:
dom- theDocumentto be writedos- the OutputStream @ if any error occurred
-
createDssDocumentFromDomDocument
public static DSSDocument createDssDocumentFromDomDocument(Document document, String name)
This method creates a new InMemoryDocument with theDocumentcontent and the given name- Parameters:
document- theDocumentto storename- the ouput filename- Returns:
- a new instance of InMemoryDocument with the XML and the given filename
-
xmlToString
public static String xmlToString(Node node)
This method allows to convert an XMLNodeto aString.- Parameters:
node-Nodeto be converted- Returns:
Stringrepresentation of the node
-
getCurrentNamespaces
public static Map<String,String> getCurrentNamespaces()
This method returns stored namespace definitions- Returns:
- a map with the prefix and the related URI
-
getXPathByIdAttribute
public static String getXPathByIdAttribute(String uri)
Returns case-insensitive xPath expression- Parameters:
uri- to find- Returns:
StringxPath expression
-
isElementReference
public static boolean isElementReference(String uri)
Returns TRUE if the providedurirefers to an element in the signature- Parameters:
uri-Stringto be checked- Returns:
- TRUE if
uriis referred to an element, FALSE otherwise
-
isXPointerQuery
public static boolean isXPointerQuery(String uriValue)
Indicates if the given URI is an XPointer query.- Parameters:
uriValue- URI to be analysed- Returns:
- true if it is an XPointer query
-
-