Package at.gv.egovernment.moaspss.util
Class XPathUtils
java.lang.Object
at.gv.egovernment.moaspss.util.XPathUtils
Utility methods to evaluate XPath expressions on DOM nodes.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe XPath expression selecting all nodes under a given root (including the root node itself). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringgetAttributeValue(Element root, String xpath, String def) Return the value of a DOM attribute whose location is given by an XPath expression.static StringgetElementValue(Element root, String xpath, String def) Return the value of a DOM element whose location is given by an XPath expression.static StringgetSlPrefix(Element contextElement) Returns the namespace prefix used withinXPathUtilsfor referring to the namespace of the specified (Security Layer command) element.static StringgetSlPrefixFromNoRoot(Element contextElement) Return the SecurityLayer namespace prefix of the context element.static NodeIteratorselectNodeIterator(Node contextNode, String exp) Return aNodeIteratorover the nodes matching the XPath expression.static NodeIteratorselectNodeIterator(Node contextNode, Map namespaceMapping, String exp) Return aNodeIteratorover the nodes matching the XPath expression.static NodeIteratorselectNodeIterator(Node contextNode, Element namespaceElement, String exp) Return aNodeIteratorover the nodes matching the XPath expression.static NodeListselectNodeList(Node contextNode, String exp) Return aNodeListof all the nodes matching the XPath expression.static NodeListselectNodeList(Node contextNode, Map namespaceMapping, String exp) Return aNodeListof all the nodes matching the XPath expression.static NodeListselectNodeList(Node contextNode, Element namespaceElement, String exp) Return aNodeListof all the nodes matching the XPath expression.static NodeselectSingleNode(Node contextNode, String exp) Select the first node matching an XPath expression.static NodeselectSingleNode(Node contextNode, Map namespaceMapping, String exp) Select the first node matching an XPath expression.static NodeselectSingleNode(Node contextNode, org.jaxen.NamespaceContext nsContext, String exp) Select the first node matching an XPath expression.static NodeselectSingleNode(Node contextNode, Element namespaceElement, String exp) Select the first node matching an XPath expression.
-
Field Details
-
ALL_NODES_XPATH
The XPath expression selecting all nodes under a given root (including the root node itself).- See Also:
-
-
Constructor Details
-
XPathUtils
public XPathUtils()
-
-
Method Details
-
selectNodeIterator
Return aNodeIteratorover the nodes matching the XPath expression. All namespace URIs and prefixes declared in theConstantsinterface are used for resolving namespaces.- Parameters:
contextNode- The root node from which to evaluate the XPath expression.exp- The XPath expression to evaluate.- Returns:
- An iterator over the resulting nodes.
- Throws:
XPathException- An error occurred evaluating the XPath expression.
-
selectNodeIterator
public static NodeIterator selectNodeIterator(Node contextNode, Element namespaceElement, String exp) throws XPathException Return aNodeIteratorover the nodes matching the XPath expression.- Parameters:
contextNode- The root node from which to evaluate the XPath expression.namespaceElement- An element from which to build the namespace mapping for evaluating the XPath expressionexp- The XPath expression to evaluate.- Returns:
- An iterator over the resulting nodes.
- Throws:
XPathException- An error occurred evaluating the XPath expression.
-
selectNodeIterator
public static NodeIterator selectNodeIterator(Node contextNode, Map namespaceMapping, String exp) throws XPathException Return aNodeIteratorover the nodes matching the XPath expression.- Parameters:
contextNode- The root node from which to evaluate the XPath expression.namespaceMapping- A namespace prefix to namespace URI mapping (StringtoString) for evaluating the XPath expression.exp- The XPath expression to evaluate.- Returns:
- An iterator over the resulting nodes.
- Throws:
XPathException- An error occurred evaluating the XPath expression.
-
selectNodeList
Return aNodeListof all the nodes matching the XPath expression. All namespace URIs and prefixes declared in theConstantsinterface are used for resolving namespaces.- Parameters:
contextNode- The root node from which to evaluate the XPath expression.exp- The XPath expression to evaluate.- Returns:
- A
NodeListcontaining the matching nodes. - Throws:
XPathException- An error occurred evaluating the XPath expression.
-
selectNodeList
public static NodeList selectNodeList(Node contextNode, Element namespaceElement, String exp) throws XPathException Return aNodeListof all the nodes matching the XPath expression.- Parameters:
contextNode- The root node from which to evaluate the XPath expression.namespaceElement- An element from which to build the namespace mapping for evaluating the XPath expressionexp- The XPath expression to evaluate.- Returns:
- A
NodeListcontaining the matching nodes. - Throws:
XPathException- An error occurred evaluating the XPath expression.
-
selectNodeList
public static NodeList selectNodeList(Node contextNode, Map namespaceMapping, String exp) throws XPathException Return aNodeListof all the nodes matching the XPath expression.- Parameters:
contextNode- The root node from which to evaluate the XPath expression.namespaceMapping- A namespace prefix to namespace URI mapping (StringtoString) for evaluating the XPath expression.exp- The XPath expression to evaluate.- Returns:
- A
NodeListcontaining the matching nodes. - Throws:
XPathException- An error occurred evaluating the XPath expression.
-
selectSingleNode
Select the first node matching an XPath expression. All namespace URIs and prefixes declared in theConstantsinterface are used for resolving namespaces.- Parameters:
contextNode- The root node from which to evaluate the XPath expression.exp- The XPath expression to evaluate.- Returns:
- Node The first node matching the XPath expression, or
null, if no node matched. - Throws:
XPathException- An error occurred evaluating the XPath expression.
-
selectSingleNode
public static Node selectSingleNode(Node contextNode, Element namespaceElement, String exp) throws XPathException Select the first node matching an XPath expression.- Parameters:
contextNode- The root node from which to evaluate the XPath expression.namespaceElement- An element from which to build the namespace mapping for evaluating the XPath expressionexp- The XPath expression to evaluate.- Returns:
- Node The first node matching the XPath expression, or
null, if no node matched. - Throws:
XPathException- An error occurred evaluating the XPath expression.
-
selectSingleNode
public static Node selectSingleNode(Node contextNode, Map namespaceMapping, String exp) throws XPathException Select the first node matching an XPath expression.- Parameters:
contextNode- The root node from which to evaluate the XPath expression.namespaceMapping- A namespace prefix to namespace URI mapping (StringtoString) for evaluating the XPath expression.exp- The XPath expression to evaluate.- Returns:
- Node The first node matching the XPath expression, or
null, if no node matched. - Throws:
XPathException- An error occurred evaluating the XPath expression.
-
selectSingleNode
public static Node selectSingleNode(Node contextNode, org.jaxen.NamespaceContext nsContext, String exp) throws XPathException Select the first node matching an XPath expression.- Parameters:
contextNode- The root node from which to evaluate the XPath expression.nsContext- TheNamespaceContextfor resolving namespace prefixes to namespace URIs for evaluating the XPath expression.exp- The XPath expression to evaluate.- Returns:
- Node The first node matching the XPath expression, or
null, if no node matched. - Throws:
XPathException- An error occurred evaluating the XPath expression.
-
getElementValue
Return the value of a DOM element whose location is given by an XPath expression.- Parameters:
root- The root element from which to evaluate the XPath.xpath- The XPath expression pointing to the element whose value to return.def- The default value to return, if no element can be found using the givenxpath.- Returns:
- The element value, if it can be located using the
xpath. Otherwise,defis returned.
-
getAttributeValue
Return the value of a DOM attribute whose location is given by an XPath expression.- Parameters:
root- The root element from which to evaluate the XPath.xpath- The XPath expression pointing to the attribute whose value to return.def- The default value to return, if no attribute can be found using the givenxpath.- Returns:
- The element value, if it can be located using the
xpath. Otherwise,defis returned.
-
getSlPrefix
Returns the namespace prefix used withinXPathUtilsfor referring to the namespace of the specified (Security Layer command) element. This namespace prefix can be used in various XPath expression evaluation methods withinXPathUtilswithout explicitely binding it to the particular namespace.- Parameters:
contextElement- The (Security Layer command) element.- Returns:
- the namespace prefix used within
XPathUtilsfor referring to the namespace of the specified (Security Layer command) element. throws XpathException If the specified element has a namespace other than the ones known by this implementation as valid Security Layer namespaces (cf. - Throws:
XPathException
-
getSlPrefixFromNoRoot
Return the SecurityLayer namespace prefix of the context element. If the context element is not the element that lies within the SecurityLayer namespace. The Securitylayer namespace is derived from thexmlns:sl10,sl11orslattribute of the context element. The returned prefix is needed for evaluating XPATH expressions.- Parameters:
contextElement- The element to get a prefix for the Securitylayer namespace, that is used within the corresponding document.- Returns:
- The string
sl10,sl11orsl, depending on the SecurityLayer namespace of the contextElement. throws XPathException If no (vlalid) SecurityLayer namespace prefix or namespace is defined. - Throws:
XPathException
-