summaryrefslogtreecommitdiff
path: root/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/utils/XPathUtils.java
diff options
context:
space:
mode:
authorThomas <thomas.lenz@egiz.gv.at>2019-12-05 09:52:48 +0100
committerThomas <thomas.lenz@egiz.gv.at>2019-12-05 09:52:48 +0100
commit3fada6cef21c9b16467177d866df778203b51b4d (patch)
tree8fe8ed37b6ee9fe35a1e035ceba6c68808328415 /eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/utils/XPathUtils.java
parent95b21a826e5d81fdeabcf4673a9e87047edaec9d (diff)
downloadEAAF-Components-3fada6cef21c9b16467177d866df778203b51b4d.tar.gz
EAAF-Components-3fada6cef21c9b16467177d866df778203b51b4d.tar.bz2
EAAF-Components-3fada6cef21c9b16467177d866df778203b51b4d.zip
some code code-style modifications
active code-quality checks!
Diffstat (limited to 'eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/utils/XPathUtils.java')
-rw-r--r--eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/utils/XPathUtils.java347
1 files changed, 192 insertions, 155 deletions
diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/utils/XPathUtils.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/utils/XPathUtils.java
index d6745c78..3adbe3f5 100644
--- a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/utils/XPathUtils.java
+++ b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/utils/XPathUtils.java
@@ -17,14 +17,11 @@
* works that you distribute must include a readable copy of the "NOTICE" text file.
*/
-
-
package at.gv.egiz.eaaf.core.impl.utils;
import java.util.List;
import java.util.Map;
-import at.gv.egiz.eaaf.core.api.data.XMLNamespaceConstants;
-import at.gv.egiz.eaaf.core.exceptions.XPathException;
+
import org.jaxen.JaxenException;
import org.jaxen.NamespaceContext;
import org.jaxen.Navigator;
@@ -37,6 +34,9 @@ import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.traversal.NodeIterator;
+import at.gv.egiz.eaaf.core.api.data.XmlNamespaceConstants;
+import at.gv.egiz.eaaf.core.exceptions.XPathException;
+
/**
* Utility methods to evaluate XPath expressions on DOM nodes.
*
@@ -46,7 +46,8 @@ import org.w3c.dom.traversal.NodeIterator;
public class XPathUtils {
/**
- * The XPath expression selecting all nodes under a given root (including the root node itself).
+ * The XPath expression selecting all nodes under a given root (including the
+ * root node itself).
*/
public static final String ALL_NODES_XPATH = "(.//. | .//@* | .//namespace::*)";
@@ -57,49 +58,50 @@ public class XPathUtils {
static {
final SimpleNamespaceContext ctx = new SimpleNamespaceContext();
- ctx.addNamespace(XMLNamespaceConstants.MOA_PREFIX, XMLNamespaceConstants.MOA_NS_URI);
- ctx.addNamespace(XMLNamespaceConstants.MOA_CONFIG_PREFIX,
- XMLNamespaceConstants.MOA_CONFIG_NS_URI);
- ctx.addNamespace(XMLNamespaceConstants.MOA_ID_CONFIG_PREFIX,
- XMLNamespaceConstants.MOA_ID_CONFIG_NS_URI);
- ctx.addNamespace(XMLNamespaceConstants.SL10_PREFIX, XMLNamespaceConstants.SL10_NS_URI);
- ctx.addNamespace(XMLNamespaceConstants.SL11_PREFIX, XMLNamespaceConstants.SL11_NS_URI);
- ctx.addNamespace(XMLNamespaceConstants.SL12_PREFIX, XMLNamespaceConstants.SL12_NS_URI);
- ctx.addNamespace(XMLNamespaceConstants.ECDSA_PREFIX, XMLNamespaceConstants.ECDSA_NS_URI);
- ctx.addNamespace(XMLNamespaceConstants.PD_PREFIX, XMLNamespaceConstants.PD_NS_URI);
- ctx.addNamespace(XMLNamespaceConstants.SAML_PREFIX, XMLNamespaceConstants.SAML_NS_URI);
- ctx.addNamespace(XMLNamespaceConstants.SAMLP_PREFIX, XMLNamespaceConstants.SAMLP_NS_URI);
- ctx.addNamespace(XMLNamespaceConstants.DSIG_PREFIX, XMLNamespaceConstants.DSIG_NS_URI);
- ctx.addNamespace(XMLNamespaceConstants.XSLT_PREFIX, XMLNamespaceConstants.XSLT_NS_URI);
- ctx.addNamespace(XMLNamespaceConstants.XSI_PREFIX, XMLNamespaceConstants.XSI_NS_URI);
- ctx.addNamespace(XMLNamespaceConstants.DSIG_FILTER2_PREFIX,
- XMLNamespaceConstants.DSIG_FILTER2_NS_URI);
- ctx.addNamespace(XMLNamespaceConstants.DSIG_EC_PREFIX, XMLNamespaceConstants.DSIG_EC_NS_URI);
- ctx.addNamespace(XMLNamespaceConstants.MD_PREFIX, XMLNamespaceConstants.MD_NS_URI);
- ctx.addNamespace(XMLNamespaceConstants.MDP_PREFIX, XMLNamespaceConstants.MDP_NS_URI);
- ctx.addNamespace(XMLNamespaceConstants.MVV_PREFIX, XMLNamespaceConstants.MVV_NS_URI);
- ctx.addNamespace(XMLNamespaceConstants.STB_PREFIX, XMLNamespaceConstants.STB_NS_URI);
- ctx.addNamespace(XMLNamespaceConstants.WRR_PREFIX, XMLNamespaceConstants.WRR_NS_URI);
- ctx.addNamespace(XMLNamespaceConstants.STORK_PREFIX, XMLNamespaceConstants.STORK_NS_URI);
- ctx.addNamespace(XMLNamespaceConstants.STORKP_PREFIX, XMLNamespaceConstants.STORKP_NS_URI);
- ctx.addNamespace(XMLNamespaceConstants.SAML2_PREFIX, XMLNamespaceConstants.SAML2_NS_URI);
- ctx.addNamespace(XMLNamespaceConstants.SAML2P_PREFIX, XMLNamespaceConstants.SAML2P_NS_URI);
- ctx.addNamespace(XMLNamespaceConstants.XENC_PREFIX, XMLNamespaceConstants.XENC_NS_URI);
- ctx.addNamespace(XMLNamespaceConstants.XADES_1_1_1_NS_PREFIX,
- XMLNamespaceConstants.XADES_1_1_1_NS_URI);
+ ctx.addNamespace(XmlNamespaceConstants.MOA_PREFIX, XmlNamespaceConstants.MOA_NS_URI);
+ ctx.addNamespace(XmlNamespaceConstants.MOA_CONFIG_PREFIX,
+ XmlNamespaceConstants.MOA_CONFIG_NS_URI);
+ ctx.addNamespace(XmlNamespaceConstants.MOA_ID_CONFIG_PREFIX,
+ XmlNamespaceConstants.MOA_ID_CONFIG_NS_URI);
+ ctx.addNamespace(XmlNamespaceConstants.SL10_PREFIX, XmlNamespaceConstants.SL10_NS_URI);
+ ctx.addNamespace(XmlNamespaceConstants.SL11_PREFIX, XmlNamespaceConstants.SL11_NS_URI);
+ ctx.addNamespace(XmlNamespaceConstants.SL12_PREFIX, XmlNamespaceConstants.SL12_NS_URI);
+ ctx.addNamespace(XmlNamespaceConstants.ECDSA_PREFIX, XmlNamespaceConstants.ECDSA_NS_URI);
+ ctx.addNamespace(XmlNamespaceConstants.PD_PREFIX, XmlNamespaceConstants.PD_NS_URI);
+ ctx.addNamespace(XmlNamespaceConstants.SAML_PREFIX, XmlNamespaceConstants.SAML_NS_URI);
+ ctx.addNamespace(XmlNamespaceConstants.SAMLP_PREFIX, XmlNamespaceConstants.SAMLP_NS_URI);
+ ctx.addNamespace(XmlNamespaceConstants.DSIG_PREFIX, XmlNamespaceConstants.DSIG_NS_URI);
+ ctx.addNamespace(XmlNamespaceConstants.XSLT_PREFIX, XmlNamespaceConstants.XSLT_NS_URI);
+ ctx.addNamespace(XmlNamespaceConstants.XSI_PREFIX, XmlNamespaceConstants.XSI_NS_URI);
+ ctx.addNamespace(XmlNamespaceConstants.DSIG_FILTER2_PREFIX,
+ XmlNamespaceConstants.DSIG_FILTER2_NS_URI);
+ ctx.addNamespace(XmlNamespaceConstants.DSIG_EC_PREFIX, XmlNamespaceConstants.DSIG_EC_NS_URI);
+ ctx.addNamespace(XmlNamespaceConstants.MD_PREFIX, XmlNamespaceConstants.MD_NS_URI);
+ ctx.addNamespace(XmlNamespaceConstants.MDP_PREFIX, XmlNamespaceConstants.MDP_NS_URI);
+ ctx.addNamespace(XmlNamespaceConstants.MVV_PREFIX, XmlNamespaceConstants.MVV_NS_URI);
+ ctx.addNamespace(XmlNamespaceConstants.STB_PREFIX, XmlNamespaceConstants.STB_NS_URI);
+ ctx.addNamespace(XmlNamespaceConstants.WRR_PREFIX, XmlNamespaceConstants.WRR_NS_URI);
+ ctx.addNamespace(XmlNamespaceConstants.STORK_PREFIX, XmlNamespaceConstants.STORK_NS_URI);
+ ctx.addNamespace(XmlNamespaceConstants.STORKP_PREFIX, XmlNamespaceConstants.STORKP_NS_URI);
+ ctx.addNamespace(XmlNamespaceConstants.SAML2_PREFIX, XmlNamespaceConstants.SAML2_NS_URI);
+ ctx.addNamespace(XmlNamespaceConstants.SAML2P_PREFIX, XmlNamespaceConstants.SAML2P_NS_URI);
+ ctx.addNamespace(XmlNamespaceConstants.XENC_PREFIX, XmlNamespaceConstants.XENC_NS_URI);
+ ctx.addNamespace(XmlNamespaceConstants.XADES_1_1_1_NS_PREFIX,
+ XmlNamespaceConstants.XADES_1_1_1_NS_URI);
NS_CONTEXT = ctx;
}
/**
- * Return a <code>NodeIterator</code> over the nodes matching the XPath expression.
+ * Return a <code>NodeIterator</code> over the nodes matching the XPath
+ * expression.
*
- *<p>
- * All namespace URIs and prefixes declared in the <code>Constants</code> interface are used for
- * resolving namespaces.
- *</p>
+ * <p>
+ * All namespace URIs and prefixes declared in the <code>Constants</code>
+ * interface are used for resolving namespaces.
+ * </p>
*
* @param contextNode The root node from which to evaluate the XPath expression.
- * @param exp The XPath expression to evaluate.
+ * @param exp The XPath expression to evaluate.
* @return An iterator over the resulting nodes.
* @throws XPathException An error occurred evaluating the XPath expression.
*/
@@ -110,12 +112,14 @@ public class XPathUtils {
}
/**
- * Return a <code>NodeIterator</code> over the nodes matching the XPath expression.
+ * Return a <code>NodeIterator</code> over the nodes matching the XPath
+ * expression.
*
- * @param contextNode The root node from which to evaluate the XPath expression.
- * @param namespaceElement An element from which to build the namespace mapping for evaluating the
- * XPath expression
- * @param exp The XPath expression to evaluate.
+ * @param contextNode The root node from which to evaluate the XPath
+ * expression.
+ * @param namespaceElement An element from which to build the namespace mapping
+ * for evaluating the XPath expression
+ * @param exp The XPath expression to evaluate.
* @return An iterator over the resulting nodes.
* @throws XPathException An error occurred evaluating the XPath expression.
*/
@@ -134,12 +138,15 @@ public class XPathUtils {
}
/**
- * Return a <code>NodeIterator</code> over the nodes matching the XPath expression.
+ * Return a <code>NodeIterator</code> over the nodes matching the XPath
+ * expression.
*
- * @param contextNode The root node from which to evaluate the XPath expression.
- * @param namespaceMapping A namespace prefix to namespace URI mapping (<code>String</code> to
- * <code>String</code>) for evaluating the XPath expression.
- * @param exp The XPath expression to evaluate.
+ * @param contextNode The root node from which to evaluate the XPath
+ * expression.
+ * @param namespaceMapping A namespace prefix to namespace URI mapping
+ * (<code>String</code> to <code>String</code>) for
+ * evaluating the XPath expression.
+ * @param exp The XPath expression to evaluate.
* @return An iterator over the resulting nodes.
* @throws XPathException An error occurred evaluating the XPath expression.
*/
@@ -152,12 +159,14 @@ public class XPathUtils {
}
/**
- * Return a <code>NodeIterator</code> over the nodes matching the XPath expression.
+ * Return a <code>NodeIterator</code> over the nodes matching the XPath
+ * expression.
*
* @param contextNode The root node from which to evaluate the XPath expression.
- * @param nsContext The <code>NamespaceContext</code> for resolving namespace prefixes to
- * namespace URIs for evaluating the XPath expression.
- * @param exp The XPath expression to evaluate.
+ * @param nsContext The <code>NamespaceContext</code> for resolving namespace
+ * prefixes to namespace URIs for evaluating the XPath
+ * expression.
+ * @param exp The XPath expression to evaluate.
* @return An iterator over the resulting nodes.
* @throws XPathException An error occurred evaluating the XPath expression.
*/
@@ -179,13 +188,15 @@ public class XPathUtils {
}
/**
- * Return a <code>NodeList</code> of all the nodes matching the XPath expression.
- *<p>
- * All namespace URIs and prefixes declared in the <code>Constants</code> interface are used for
- * resolving namespaces.
- *</p>
+ * Return a <code>NodeList</code> of all the nodes matching the XPath
+ * expression.
+ * <p>
+ * All namespace URIs and prefixes declared in the <code>Constants</code>
+ * interface are used for resolving namespaces.
+ * </p>
+ *
* @param contextNode The root node from which to evaluate the XPath expression.
- * @param exp The XPath expression to evaluate.
+ * @param exp The XPath expression to evaluate.
* @return A <code>NodeList</code> containing the matching nodes.
* @throws XPathException An error occurred evaluating the XPath expression.
*/
@@ -196,12 +207,14 @@ public class XPathUtils {
}
/**
- * Return a <code>NodeList</code> of all the nodes matching the XPath expression.
+ * Return a <code>NodeList</code> of all the nodes matching the XPath
+ * expression.
*
- * @param contextNode The root node from which to evaluate the XPath expression.
- * @param namespaceElement An element from which to build the namespace mapping for evaluating the
- * XPath expression
- * @param exp The XPath expression to evaluate.
+ * @param contextNode The root node from which to evaluate the XPath
+ * expression.
+ * @param namespaceElement An element from which to build the namespace mapping
+ * for evaluating the XPath expression
+ * @param exp The XPath expression to evaluate.
* @return A <code>NodeList</code> containing the matching nodes.
* @throws XPathException An error occurred evaluating the XPath expression.
*/
@@ -221,12 +234,15 @@ public class XPathUtils {
}
/**
- * Return a <code>NodeList</code> of all the nodes matching the XPath expression.
+ * Return a <code>NodeList</code> of all the nodes matching the XPath
+ * expression.
*
- * @param contextNode The root node from which to evaluate the XPath expression.
- * @param namespaceMapping A namespace prefix to namespace URI mapping (<code>String</code> to
- * <code>String</code>) for evaluating the XPath expression.
- * @param exp The XPath expression to evaluate.
+ * @param contextNode The root node from which to evaluate the XPath
+ * expression.
+ * @param namespaceMapping A namespace prefix to namespace URI mapping
+ * (<code>String</code> to <code>String</code>) for
+ * evaluating the XPath expression.
+ * @param exp The XPath expression to evaluate.
* @return A <code>NodeList</code> containing the matching nodes.
* @throws XPathException An error occurred evaluating the XPath expression.
*/
@@ -239,12 +255,14 @@ public class XPathUtils {
}
/**
- * Return a <code>NodeList</code> of all the nodes matching the XPath expression.
+ * Return a <code>NodeList</code> of all the nodes matching the XPath
+ * expression.
*
* @param contextNode The root node from which to evaluate the XPath expression.
- * @param nsContext The <code>NamespaceContext</code> for resolving namespace prefixes to
- * namespace URIs for evaluating the XPath expression.
- * @param exp The XPath expression to evaluate.
+ * @param nsContext The <code>NamespaceContext</code> for resolving namespace
+ * prefixes to namespace URIs for evaluating the XPath
+ * expression.
+ * @param exp The XPath expression to evaluate.
* @return A <code>NodeList</code> containing the matching nodes.
* @throws XPathException An error occurred evaluating the XPath expression.
*/
@@ -265,14 +283,15 @@ public class XPathUtils {
/**
* Select the first node matching an XPath expression.
- *<p>
- * All namespace URIs and prefixes declared in the <code>Constants</code> interface are used for
- * resolving namespaces.
- *</p>
+ * <p>
+ * All namespace URIs and prefixes declared in the <code>Constants</code>
+ * interface are used for resolving namespaces.
+ * </p>
+ *
* @param contextNode The root node from which to evaluate the XPath expression.
- * @param exp The XPath expression to evaluate.
- * @return Node The first node matching the XPath expression, or <code>null</code>, if no node
- * matched.
+ * @param exp The XPath expression to evaluate.
+ * @return Node The first node matching the XPath expression, or
+ * <code>null</code>, if no node matched.
* @throws XPathException An error occurred evaluating the XPath expression.
*/
public static Node selectSingleNode(final Node contextNode, final String exp)
@@ -284,12 +303,13 @@ public class XPathUtils {
/**
* Select the first node matching an XPath expression.
*
- * @param contextNode The root node from which to evaluate the XPath expression.
- * @param namespaceElement An element from which to build the namespace mapping for evaluating the
- * XPath expression
- * @param exp The XPath expression to evaluate.
- * @return Node The first node matching the XPath expression, or <code>null</code>, if no node
- * matched.
+ * @param contextNode The root node from which to evaluate the XPath
+ * expression.
+ * @param namespaceElement An element from which to build the namespace mapping
+ * for evaluating the XPath expression
+ * @param exp The XPath expression to evaluate.
+ * @return Node The first node matching the XPath expression, or
+ * <code>null</code>, if no node matched.
* @throws XPathException An error occurred evaluating the XPath expression.
*/
public static Node selectSingleNode(final Node contextNode, final Element namespaceElement,
@@ -309,12 +329,14 @@ public class XPathUtils {
/**
* Select the first node matching an XPath expression.
*
- * @param contextNode The root node from which to evaluate the XPath expression.
- * @param namespaceMapping A namespace prefix to namespace URI mapping (<code>String</code> to
- * <code>String</code>) for evaluating the XPath expression.
- * @param exp The XPath expression to evaluate.
- * @return Node The first node matching the XPath expression, or <code>null</code>, if no node
- * matched.
+ * @param contextNode The root node from which to evaluate the XPath
+ * expression.
+ * @param namespaceMapping A namespace prefix to namespace URI mapping
+ * (<code>String</code> to <code>String</code>) for
+ * evaluating the XPath expression.
+ * @param exp The XPath expression to evaluate.
+ * @return Node The first node matching the XPath expression, or
+ * <code>null</code>, if no node matched.
* @throws XPathException An error occurred evaluating the XPath expression.
*/
public static Node selectSingleNode(final Node contextNode, final Map namespaceMapping,
@@ -329,11 +351,12 @@ public class XPathUtils {
* Select the first node matching an XPath expression.
*
* @param contextNode The root node from which to evaluate the XPath expression.
- * @param nsContext The <code>NamespaceContext</code> for resolving namespace prefixes to
- * namespace URIs for evaluating the XPath expression.
- * @param exp The XPath expression to evaluate.
- * @return Node The first node matching the XPath expression, or <code>null</code>, if no node
- * matched.
+ * @param nsContext The <code>NamespaceContext</code> for resolving namespace
+ * prefixes to namespace URIs for evaluating the XPath
+ * expression.
+ * @param exp The XPath expression to evaluate.
+ * @return Node The first node matching the XPath expression, or
+ * <code>null</code>, if no node matched.
* @throws XPathException An error occurred evaluating the XPath expression.
*/
public static Node selectSingleNode(final Node contextNode, final NamespaceContext nsContext,
@@ -351,14 +374,16 @@ public class XPathUtils {
}
/**
- * Return the value of a DOM element whose location is given by an XPath expression.
+ * Return the value of a DOM element whose location is given by an XPath
+ * expression.
*
- * @param root The root element from which to evaluate the XPath.
- * @param xpath The XPath expression pointing to the element whose value to return.
- * @param def The default value to return, if no element can be found using the given
- * <code>xpath</code>.
- * @return The element value, if it can be located using the <code>xpath</code>. Otherwise,
- * <code>def</code> is returned.
+ * @param root The root element from which to evaluate the XPath.
+ * @param xpath The XPath expression pointing to the element whose value to
+ * return.
+ * @param def The default value to return, if no element can be found using
+ * the given <code>xpath</code>.
+ * @return The element value, if it can be located using the <code>xpath</code>.
+ * Otherwise, <code>def</code> is returned.
*/
public static String getElementValue(final Element root, final String xpath, final String def) {
@@ -367,14 +392,16 @@ public class XPathUtils {
}
/**
- * Return the value of a DOM attribute whose location is given by an XPath expression.
+ * Return the value of a DOM attribute whose location is given by an XPath
+ * expression.
*
- * @param root The root element from which to evaluate the XPath.
- * @param xpath The XPath expression pointing to the attribute whose value to return.
- * @param def The default value to return, if no attribute can be found using the given
- * <code>xpath</code>.
- * @return The element value, if it can be located using the <code>xpath</code>. Otherwise,
- * <code>def</code> is returned.
+ * @param root The root element from which to evaluate the XPath.
+ * @param xpath The XPath expression pointing to the attribute whose value to
+ * return.
+ * @param def The default value to return, if no attribute can be found using
+ * the given <code>xpath</code>.
+ * @return The element value, if it can be located using the <code>xpath</code>.
+ * Otherwise, <code>def</code> is returned.
*/
public static String getAttributeValue(final Element root, final String xpath, final String def) {
@@ -383,31 +410,36 @@ public class XPathUtils {
}
/**
- * Returns the namespace prefix used within <code>XPathUtils</code> for referring to the namespace
- * of the specified (Security Layer command) element.
- *<p>
- * This namespace prefix can be used in various XPath expression evaluation methods within
- * <code> XPathUtils</code> without explicitely binding it to the particular namespace.
- *</p>
+ * Returns the namespace prefix used within <code>XPathUtils</code> for
+ * referring to the namespace of the specified (Security Layer command) element.
+ * <p>
+ * This namespace prefix can be used in various XPath expression evaluation
+ * methods within <code> XPathUtils</code> without explicitely binding it to the
+ * particular namespace.
+ * </p>
+ *
* @param contextElement The (Security Layer command) element.
*
- * @return the namespace prefix used within <code>XPathUtils</code> for referring to the namespace
- * of the specified (Security Layer command) element.
+ * @return the namespace prefix used within <code>XPathUtils</code> for
+ * 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.
- * @link Constants#SL10_NS_URI, @link Constants#SL11_NS_URI, @link Constants#SL12_NS_URI).
+ * throws XpathException If the specified element has a namespace other
+ * than the ones known by this implementation as valid Security Layer
+ * namespaces (cf.
+ * @link Constants#SL10_NS_URI, @link Constants#SL11_NS_URI, @link
+ * Constants#SL12_NS_URI).
*/
public static String getSlPrefix(final Element contextElement) throws XPathException {
final String sLNamespace = contextElement.getNamespaceURI();
String slPrefix = null;
- if (sLNamespace.equals(XMLNamespaceConstants.SL10_NS_URI)) {
- slPrefix = XMLNamespaceConstants.SL10_PREFIX;
- } else if (sLNamespace.equals(XMLNamespaceConstants.SL12_NS_URI)) {
- slPrefix = XMLNamespaceConstants.SL12_PREFIX;
- } else if (sLNamespace.equals(XMLNamespaceConstants.SL11_NS_URI)) {
- slPrefix = XMLNamespaceConstants.SL11_PREFIX;
+ if (sLNamespace.equals(XmlNamespaceConstants.SL10_NS_URI)) {
+ slPrefix = XmlNamespaceConstants.SL10_PREFIX;
+ } else if (sLNamespace.equals(XmlNamespaceConstants.SL12_NS_URI)) {
+ slPrefix = XmlNamespaceConstants.SL12_PREFIX;
+ } else if (sLNamespace.equals(XmlNamespaceConstants.SL11_NS_URI)) {
+ slPrefix = XmlNamespaceConstants.SL11_PREFIX;
} else {
throw new XPathException("XPath operation FAILED. Reason: ");
}
@@ -415,36 +447,38 @@ public class XPathUtils {
return slPrefix;
}
-
/**
- * 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 the <code>xmlns:sl10</code>, <code>sl11</code> or <code>sl</code> attribute of the
- * context element.
- *<p>
+ * 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 the
+ * <code>xmlns:sl10</code>, <code>sl11</code> or <code>sl</code> attribute of
+ * the context element.
+ * <p>
* The returned prefix is needed for evaluating XPATH expressions.
- *</p>
- * @param contextElement The element to get a prefix for the Securitylayer namespace, that is used
- * within the corresponding document.
+ * </p>
+ *
+ * @param contextElement The element to get a prefix for the Securitylayer
+ * namespace, that is used within the corresponding
+ * document.
*
- * @return The string <code>sl10</code>, <code>sl11</code> or <code>sl</code>, depending on the
- * SecurityLayer namespace of the contextElement.
+ * @return The string <code>sl10</code>, <code>sl11</code> or <code>sl</code>,
+ * depending on the SecurityLayer namespace of the contextElement.
*
- * throws XPathException If no (vlalid) SecurityLayer namespace prefix or namespace is
- * defined.
+ * throws XPathException If no (vlalid) SecurityLayer namespace prefix
+ * or namespace is defined.
*/
public static String getSlPrefixFromNoRoot(final Element contextElement) throws XPathException {
- String slPrefix = checkSLnsDeclaration(contextElement, XMLNamespaceConstants.SL10_PREFIX,
- XMLNamespaceConstants.SL10_NS_URI);
+ String slPrefix = checkSLnsDeclaration(contextElement, XmlNamespaceConstants.SL10_PREFIX,
+ XmlNamespaceConstants.SL10_NS_URI);
if (slPrefix == null) {
- slPrefix = checkSLnsDeclaration(contextElement, XMLNamespaceConstants.SL11_PREFIX,
- XMLNamespaceConstants.SL11_NS_URI);
+ slPrefix = checkSLnsDeclaration(contextElement, XmlNamespaceConstants.SL11_PREFIX,
+ XmlNamespaceConstants.SL11_NS_URI);
}
if (slPrefix == null) {
- slPrefix = checkSLnsDeclaration(contextElement, XMLNamespaceConstants.SL12_PREFIX,
- XMLNamespaceConstants.SL12_NS_URI);
+ slPrefix = checkSLnsDeclaration(contextElement, XmlNamespaceConstants.SL12_PREFIX,
+ XmlNamespaceConstants.SL12_NS_URI);
}
return slPrefix;
@@ -452,15 +486,18 @@ public class XPathUtils {
}
/**
- * Checks if the context element has an attribute <code>xmlns:slPrefix</code> and if the prefix of
- * that attribute corresponds with a valid SecurityLayer namespace.
+ * Checks if the context element has an attribute <code>xmlns:slPrefix</code>
+ * and if the prefix of that attribute corresponds with a valid SecurityLayer
+ * namespace.
*
* @param contextElement The element to be checked.
- * @param slPrefix The prefix which should be checked. Must be a valid SecurityLayer namespace
- * prefix.
- * @param slNameSpace The SecurityLayer namespace that corresponds to the specified prefix.
+ * @param slPrefix The prefix which should be checked. Must be a valid
+ * SecurityLayer namespace prefix.
+ * @param slNameSpace The SecurityLayer namespace that corresponds to the
+ * specified prefix.
*
- * @return The valid SecurityLayer prefix or <code>null</code> if this prefix is not used.
+ * @return The valid SecurityLayer prefix or <code>null</code> if this prefix is
+ * not used.
* @throws XPathException In case of an error
*/
private static String checkSLnsDeclaration(final Element contextElement, final String slPrefix,