Class XPathUtils

java.lang.Object
eu.europa.esig.dss.xml.utils.xpath.XPathUtils

public final class XPathUtils extends Object
This class contains utility methods for XPath execution, such as NodeList extraction, etc.
  • Method Summary

    Modifier and Type
    Method
    Description
    static List<String>
    getChildrenNames(Node xmlNode, eu.europa.esig.dss.xml.common.xpath.XPathQuery xPathQuery)
    This method returns the list of children's names for a given Node.
    static Element
    getElement(Node xmlNode, eu.europa.esig.dss.xml.common.xpath.XPathQuery xPathQuery)
    Returns the Element corresponding to the XPath query.
    static Element
    getElementById(Node node, eu.europa.esig.dss.xml.common.xpath.XPathQuery xPathQuery, String id)
    Extract an element from the given node according to the xPathQuery with the matching id if any.
    static Element
    Extract an element from the given document node with the given Id.
    This method returns stored namespace definitions map
    static Node
    getNode(Node xmlNode, eu.europa.esig.dss.xml.common.xpath.XPathQuery xPathQuery)
    Returns the Node corresponding to the XPath query.
    static NodeList
    getNodeList(Node xmlNode, eu.europa.esig.dss.xml.common.xpath.XPathQuery xPathQuery)
    Returns the NodeList corresponding to the XPath query.
    static int
    getNodesAmount(Node xmlNode, eu.europa.esig.dss.xml.common.xpath.XPathQuery xPathQuery)
    Returns an amount of found nodes matching the xPathString
    static String
    getValue(Node xmlNode, eu.europa.esig.dss.xml.common.xpath.XPathQuery xPathQuery)
    Returns the String value of the corresponding to the XPath query.
    Gets the XPath Query executor
    static boolean
    registerNamespace(eu.europa.esig.dss.xml.common.definition.DSSNamespace namespace)
    This method allows to register a namespace and associated prefix.
    static void
    Sets the XPathQueryExecutor to be used by the implementation.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • getXPathQueryExecutor

      public static XPathQueryExecutor getXPathQueryExecutor()
      Gets the XPath Query executor
      Returns:
      XPathQueryExecutor
    • setXPathQueryExecutor

      public static void setXPathQueryExecutor(XPathQueryExecutor xPathQueryExecutor)
      Sets the XPathQueryExecutor to be used by the implementation. This method also sets a namespace context to the executor defined within the implementation. Default : Loads implementation accessible through ServiceLoader mechanism.
      Parameters:
      xPathQueryExecutor - XPathQueryExecutor
    • registerNamespace

      public static boolean registerNamespace(eu.europa.esig.dss.xml.common.definition.DSSNamespace namespace)
      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
    • getNamespaceContextMap

      public static NamespaceContextMap getNamespaceContextMap()
      This method returns stored namespace definitions map
      Returns:
      NamespaceContextMap a map with the prefix and the related URI
    • getValue

      public static String getValue(Node xmlNode, eu.europa.esig.dss.xml.common.xpath.XPathQuery xPathQuery)
      Returns the String value of the corresponding to the XPath query.
      Parameters:
      xmlNode - The node where the search should be performed.
      xPathQuery - XPathQuery
      Returns:
      string value of the XPath query
    • getNodeList

      public static NodeList getNodeList(Node xmlNode, eu.europa.esig.dss.xml.common.xpath.XPathQuery xPathQuery)
      Returns the NodeList corresponding to the XPath query.
      Parameters:
      xmlNode - The node where the search should be performed.
      xPathQuery - XPathQuery
      Returns:
      the NodeList corresponding to the XPath query
    • getNode

      public static Node getNode(Node xmlNode, eu.europa.esig.dss.xml.common.xpath.XPathQuery xPathQuery)
      Returns the Node corresponding to the XPath query.
      Parameters:
      xmlNode - The node where the search should be performed.
      xPathQuery - XPathQuery
      Returns:
      the Node corresponding to the XPath query.
    • getElement

      public static Element getElement(Node xmlNode, eu.europa.esig.dss.xml.common.xpath.XPathQuery xPathQuery)
      Returns the Element corresponding to the XPath query.
      Parameters:
      xmlNode - The node where the search should be performed.
      xPathQuery - XPathQuery
      Returns:
      the Element corresponding to the XPath query
    • getNodesAmount

      public static int getNodesAmount(Node xmlNode, eu.europa.esig.dss.xml.common.xpath.XPathQuery xPathQuery)
      Returns an amount of found nodes matching the xPathString
      Parameters:
      xmlNode - the current node
      xPathQuery - XPathQuery
      Returns:
      an amount of returned nodes
    • getChildrenNames

      public static List<String> getChildrenNames(Node xmlNode, eu.europa.esig.dss.xml.common.xpath.XPathQuery xPathQuery)
      This method returns the list of children's names for a given Node.
      Parameters:
      xmlNode - The node where the search should be performed.
      xPathQuery - XPathQuery
      Returns:
      List of children's names
    • getElementById

      public static Element getElementById(Node node, String id)
      Extract an element from the given document node with the given Id. The method is namespace independent.
      Parameters:
      node - Node containing the element with the Id
      id - String id of an element to find
      Returns:
      Element with the given Id, NULL if unique result is not found
    • getElementById

      public static Element getElementById(Node node, eu.europa.esig.dss.xml.common.xpath.XPathQuery xPathQuery, String id)
      Extract an element from the given node according to the xPathQuery with the matching id if any. This method normalizes id safely (ensuring it is not a URI or XPointer value).
      Parameters:
      node - Node containing the element with the Id
      xPathQuery - XPathQuery
      id - String id of an element to find
      Returns:
      Element with the given Id, NULL if unique result is not found