aboutsummaryrefslogtreecommitdiff
path: root/moaSig/common/src/main/java/at/gv/egovernment/moaspss/util/XPathUtils.java
diff options
context:
space:
mode:
Diffstat (limited to 'moaSig/common/src/main/java/at/gv/egovernment/moaspss/util/XPathUtils.java')
-rw-r--r--moaSig/common/src/main/java/at/gv/egovernment/moaspss/util/XPathUtils.java477
1 files changed, 235 insertions, 242 deletions
diff --git a/moaSig/common/src/main/java/at/gv/egovernment/moaspss/util/XPathUtils.java b/moaSig/common/src/main/java/at/gv/egovernment/moaspss/util/XPathUtils.java
index 2604c20..3bc3bb9 100644
--- a/moaSig/common/src/main/java/at/gv/egovernment/moaspss/util/XPathUtils.java
+++ b/moaSig/common/src/main/java/at/gv/egovernment/moaspss/util/XPathUtils.java
@@ -21,28 +21,26 @@
* that you distribute must include a readable copy of the "NOTICE" text file.
*/
-
package at.gv.egovernment.moaspss.util;
import java.util.List;
import java.util.Map;
-import org.w3c.dom.Attr;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.w3c.dom.traversal.NodeIterator;
-
import org.jaxen.JaxenException;
import org.jaxen.NamespaceContext;
import org.jaxen.Navigator;
import org.jaxen.SimpleNamespaceContext;
import org.jaxen.dom.DOMXPath;
import org.jaxen.dom.DocumentNavigator;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.traversal.NodeIterator;
/**
* Utility methods to evaluate XPath expressions on DOM nodes.
- *
+ *
* @author Patrick Peck
* @version $Id$
*/
@@ -53,16 +51,16 @@ public class XPathUtils {
* root node itself).
*/
public static final String ALL_NODES_XPATH =
- "(.//. | .//@* | .//namespace::*)";
+ "(.//. | .//@* | .//namespace::*)";
/** The <code>DocumentNavigator</code> to use for navigating the document. */
private static Navigator documentNavigator =
- DocumentNavigator.getInstance();
+ DocumentNavigator.getInstance();
/** The default namespace prefix to namespace URI mappings. */
private static NamespaceContext NS_CONTEXT;
static {
- SimpleNamespaceContext ctx = new SimpleNamespaceContext();
+ final SimpleNamespaceContext ctx = new SimpleNamespaceContext();
ctx.addNamespace(Constants.MOA_PREFIX, Constants.MOA_NS_URI);
ctx.addNamespace(Constants.MOA_CONFIG_PREFIX, Constants.MOA_CONFIG_NS_URI);
ctx.addNamespace(Constants.MOA_ID_CONFIG_PREFIX, Constants.MOA_ID_CONFIG_NS_URI);
@@ -95,18 +93,17 @@ public class XPathUtils {
/**
* Return a <code>NodeIterator</code> over the nodes matching the XPath
* expression.
- *
+ *
* All namespace URIs and prefixes declared in the <code>Constants</code>
* interface are used for resolving namespaces.
- *
- * @param contextNode The root node from which to evaluate the XPath
- * expression.
- * @param exp The XPath expression to evaluate.
+ *
+ * @param contextNode The root node from which to evaluate 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.
*/
public static NodeIterator selectNodeIterator(Node contextNode, String exp)
- throws XPathException {
+ throws XPathException {
return selectNodeIterator(contextNode, NS_CONTEXT, exp);
}
@@ -114,28 +111,28 @@ public class XPathUtils {
/**
* 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.
*/
public static NodeIterator selectNodeIterator(
- Node contextNode,
- Element namespaceElement,
- String exp)
- throws XPathException {
+ Node contextNode,
+ Element namespaceElement,
+ String exp)
+ throws XPathException {
try {
- SimpleNamespaceContext ctx = new SimpleNamespaceContext();
+ final SimpleNamespaceContext ctx = new SimpleNamespaceContext();
ctx.addElementNamespaces(documentNavigator, namespaceElement);
return selectNodeIterator(contextNode, ctx, exp);
- } catch (JaxenException e) {
- MessageProvider msg = MessageProvider.getInstance();
- String message = msg.getMessage("xpath.00", new Object[] { exp });
+ } catch (final JaxenException e) {
+ final MessageProvider msg = MessageProvider.getInstance();
+ final String message = msg.getMessage("xpath.00", new Object[] { exp });
throw new XPathException(message, e);
}
}
@@ -143,23 +140,23 @@ public class XPathUtils {
/**
* 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 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.
+ * (<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.
*/
public static NodeIterator selectNodeIterator(
- Node contextNode,
- Map namespaceMapping,
- String exp)
- throws XPathException {
+ Node contextNode,
+ Map namespaceMapping,
+ String exp)
+ throws XPathException {
- SimpleNamespaceContext ctx = new SimpleNamespaceContext(namespaceMapping);
+ final SimpleNamespaceContext ctx = new SimpleNamespaceContext(namespaceMapping);
return selectNodeIterator(contextNode, ctx, exp);
}
@@ -167,31 +164,31 @@ public class XPathUtils {
/**
* 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 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 An iterator over the resulting nodes.
* @throws XPathException An error occurred evaluating the XPath expression.
*/
private static NodeIterator selectNodeIterator(
- Node contextNode,
- NamespaceContext nsContext,
- String exp)
- throws XPathException {
+ Node contextNode,
+ NamespaceContext nsContext,
+ String exp)
+ throws XPathException {
try {
- DOMXPath xpath = new DOMXPath(exp);
+ final DOMXPath xpath = new DOMXPath(exp);
List nodes;
xpath.setNamespaceContext(nsContext);
nodes = xpath.selectNodes(contextNode);
return new NodeIteratorAdapter(nodes.listIterator());
- } catch (JaxenException e) {
- MessageProvider msg = MessageProvider.getInstance();
- String message = msg.getMessage("xpath.00", new Object[] { exp });
+ } catch (final JaxenException e) {
+ final MessageProvider msg = MessageProvider.getInstance();
+ final String message = msg.getMessage("xpath.00", new Object[] { exp });
throw new XPathException(message, e);
}
}
@@ -199,18 +196,17 @@ public class XPathUtils {
/**
* Return a <code>NodeList</code> of all the nodes matching the XPath
* expression.
- *
+ *
* All namespace URIs and prefixes declared in the <code>Constants</code>
* interface are used for resolving namespaces.
- *
- * @param contextNode The root node from which to evaluate the XPath
- * expression.
- * @param exp The XPath expression to evaluate.
+ *
+ * @param contextNode The root node from which to evaluate 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.
*/
public static NodeList selectNodeList(Node contextNode, String exp)
- throws XPathException {
+ throws XPathException {
return selectNodeList(contextNode, NS_CONTEXT, exp);
}
@@ -218,29 +214,29 @@ public class XPathUtils {
/**
* 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.
*/
public static NodeList selectNodeList(
- Node contextNode,
- Element namespaceElement,
- String exp)
- throws XPathException {
+ Node contextNode,
+ Element namespaceElement,
+ String exp)
+ throws XPathException {
try {
- SimpleNamespaceContext ctx = new SimpleNamespaceContext();
+ final SimpleNamespaceContext ctx = new SimpleNamespaceContext();
ctx.addElementNamespaces(documentNavigator, namespaceElement);
return selectNodeList(contextNode, ctx, exp);
- } catch (JaxenException e) {
- MessageProvider msg = MessageProvider.getInstance();
- String message = msg.getMessage("xpath.00", new Object[] { exp });
+ } catch (final JaxenException e) {
+ final MessageProvider msg = MessageProvider.getInstance();
+ final String message = msg.getMessage("xpath.00", new Object[] { exp });
throw new XPathException(message, e);
}
}
@@ -248,23 +244,23 @@ public class XPathUtils {
/**
* 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 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.
+ * (<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.
*/
public static NodeList selectNodeList(
- Node contextNode,
- Map namespaceMapping,
- String exp)
- throws XPathException {
+ Node contextNode,
+ Map namespaceMapping,
+ String exp)
+ throws XPathException {
- SimpleNamespaceContext ctx = new SimpleNamespaceContext(namespaceMapping);
+ final SimpleNamespaceContext ctx = new SimpleNamespaceContext(namespaceMapping);
return selectNodeList(contextNode, ctx, exp);
}
@@ -272,133 +268,132 @@ public class XPathUtils {
/**
* 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 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 A <code>NodeList</code> containing the matching nodes.
* @throws XPathException An error occurred evaluating the XPath expression.
*/
private static NodeList selectNodeList(
- Node contextNode,
- NamespaceContext nsContext,
- String exp)
- throws XPathException {
+ Node contextNode,
+ NamespaceContext nsContext,
+ String exp)
+ throws XPathException {
try {
- DOMXPath xpath = new DOMXPath(exp);
+ final DOMXPath xpath = new DOMXPath(exp);
List nodes;
xpath.setNamespaceContext(nsContext);
nodes = xpath.selectNodes(contextNode);
return new NodeListAdapter(nodes);
- } catch (JaxenException e) {
- MessageProvider msg = MessageProvider.getInstance();
- String message = msg.getMessage("xpath.00", new Object[] { exp });
+ } catch (final JaxenException e) {
+ final MessageProvider msg = MessageProvider.getInstance();
+ final String message = msg.getMessage("xpath.00", new Object[] { exp });
throw new XPathException(message, e);
}
}
/**
* Select the first node matching an XPath expression.
- *
+ *
* All namespace URIs and prefixes declared in the <code>Constants</code>
* interface are used for resolving namespaces.
- *
- * @param contextNode The root node from which to evaluate the XPath
- * expression.
- * @param exp The XPath expression to evaluate.
+ *
+ * @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.
+ * <code>null</code>, if no node matched.
* @throws XPathException An error occurred evaluating the XPath expression.
*/
public static Node selectSingleNode(Node contextNode, String exp)
- throws XPathException {
+ throws XPathException {
return selectSingleNode(contextNode, NS_CONTEXT, exp);
}
/**
* 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.
+ *
+ * @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.
+ * <code>null</code>, if no node matched.
* @throws XPathException An error occurred evaluating the XPath expression.
*/
public static Node selectSingleNode(
- Node contextNode,
- Element namespaceElement,
- String exp)
- throws XPathException {
+ Node contextNode,
+ Element namespaceElement,
+ String exp)
+ throws XPathException {
try {
- SimpleNamespaceContext ctx = new SimpleNamespaceContext();
+ final SimpleNamespaceContext ctx = new SimpleNamespaceContext();
ctx.addElementNamespaces(documentNavigator, namespaceElement);
return selectSingleNode(contextNode, ctx, exp);
- } catch (JaxenException e) {
- MessageProvider msg = MessageProvider.getInstance();
- String message = msg.getMessage("xpath.00", new Object[] { exp });
+ } catch (final JaxenException e) {
+ final MessageProvider msg = MessageProvider.getInstance();
+ final String message = msg.getMessage("xpath.00", new Object[] { exp });
throw new XPathException(message, e);
}
}
/**
* Select the first node matching an XPath expression.
- *
- * @param contextNode The root node from which to evaluate 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.
+ * (<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.
+ * <code>null</code>, if no node matched.
* @throws XPathException An error occurred evaluating the XPath expression.
*/
public static Node selectSingleNode(
- Node contextNode,
- Map namespaceMapping,
- String exp)
- throws XPathException {
+ Node contextNode,
+ Map namespaceMapping,
+ String exp)
+ throws XPathException {
- SimpleNamespaceContext ctx = new SimpleNamespaceContext(namespaceMapping);
+ final SimpleNamespaceContext ctx = new SimpleNamespaceContext(namespaceMapping);
return selectSingleNode(contextNode, ctx, exp);
}
/**
* 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.
+ *
+ * @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.
+ * <code>null</code>, if no node matched.
* @throws XPathException An error occurred evaluating the XPath expression.
*/
public static Node selectSingleNode(
- Node contextNode,
- NamespaceContext nsContext,
- String exp)
- throws XPathException {
+ Node contextNode,
+ NamespaceContext nsContext,
+ String exp)
+ throws XPathException {
try {
- DOMXPath xpath = new DOMXPath(exp);
+ final DOMXPath xpath = new DOMXPath(exp);
xpath.setNamespaceContext(nsContext);
return (Node) xpath.selectSingleNode(contextNode);
- } catch (JaxenException e) {
- MessageProvider msg = MessageProvider.getInstance();
- String message = msg.getMessage("xpath.00", new Object[] { exp });
+ } catch (final JaxenException e) {
+ final MessageProvider msg = MessageProvider.getInstance();
+ final String message = msg.getMessage("xpath.00", new Object[] { exp });
throw new XPathException(message, e);
}
}
@@ -406,140 +401,137 @@ public class XPathUtils {
/**
* 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(
- Element root,
- String xpath,
- String def) {
+ Element root,
+ String xpath,
+ String def) {
- Element elem = (Element) XPathUtils.selectSingleNode(root, xpath);
+ final Element elem = (Element) XPathUtils.selectSingleNode(root, xpath);
return elem != null ? DOMUtils.getText(elem) : def;
}
/**
* 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 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.
+ * 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(
- Element root,
- String xpath,
- String def) {
+ Element root,
+ String xpath,
+ String def) {
- Attr attr = (Attr) XPathUtils.selectSingleNode(root, xpath);
+ final Attr attr = (Attr) XPathUtils.selectSingleNode(root, xpath);
return attr != null ? attr.getValue() : def;
}
-
+
/**
- * Returns the namespace prefix used within <code>XPathUtils</code> for referring to
- * the namespace of the specified (Security Layer command) element.
+ * Returns the namespace prefix used within <code>XPathUtils</code> for
+ * referring to the namespace of the specified (Security Layer command) element.
+ *
+ * This namespace prefix can be used in various XPath expression evaluation
+ * methods within <code> XPathUtils</code> without explicitely binding it to the
+ * particular namespace.
+ *
+ * @param contextElement The (Security Layer command) element.
*
- * This namespace prefix can be used in various XPath expression evaluation methods
- * within <code> XPathUtils</code> without explicitely binding it to the particular
- * namespace.
- *
- * @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.
- *
- * 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).
+ * @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).
*/
- public static String getSlPrefix (Element contextElement) throws XPathException
- {
- String sLNamespace = contextElement.getNamespaceURI();
+ public static String getSlPrefix(Element contextElement) throws XPathException {
+ final String sLNamespace = contextElement.getNamespaceURI();
String sLPrefix = null;
- if (sLNamespace.equals(Constants.SL10_NS_URI))
- {
+ if (sLNamespace.equals(Constants.SL10_NS_URI)) {
sLPrefix = Constants.SL10_PREFIX;
- }
- else if (sLNamespace.equals(Constants.SL12_NS_URI))
- {
+ } else if (sLNamespace.equals(Constants.SL12_NS_URI)) {
sLPrefix = Constants.SL12_PREFIX;
- }
- else if (sLNamespace.equals(Constants.SL11_NS_URI))
- {
+ } else if (sLNamespace.equals(Constants.SL11_NS_URI)) {
sLPrefix = Constants.SL11_PREFIX;
- }
- else
- {
- MessageProvider msg = MessageProvider.getInstance();
- String message = msg.getMessage("xpath.00", new Object[] { "Ung�ltiger Security Layer Namespace: \"" + sLNamespace + "\"."});
+ } else {
+ final MessageProvider msg = MessageProvider.getInstance();
+ final String message = msg.getMessage("xpath.00", new Object[] {
+ "Ung�ltiger Security Layer Namespace: \"" + sLNamespace + "\"." });
throw new XPathException(message, null);
}
-
+
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.
- *
+ * 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.
+ *
* The returned prefix is needed for evaluating XPATH expressions.
+ *
+ * @param contextElement The element to get a prefix for the Securitylayer
+ * namespace, that is used within the corresponding
+ * document.
*
- * @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.
- *
- * throws XPathException If no (vlalid) SecurityLayer namespace prefix or namespace
- * is defined.
+ * @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.
*/
- public static String getSlPrefixFromNoRoot (Element contextElement) throws XPathException {
-
+ public static String getSlPrefixFromNoRoot(Element contextElement) throws XPathException {
+
String slPrefix = checkSLnsDeclaration(contextElement, Constants.SL10_PREFIX, Constants.SL10_NS_URI);
if (slPrefix == null) {
slPrefix = checkSLnsDeclaration(contextElement, Constants.SL11_PREFIX, Constants.SL11_NS_URI);
}
if (slPrefix == null) {
slPrefix = checkSLnsDeclaration(contextElement, Constants.SL12_PREFIX, Constants.SL12_NS_URI);
- }
-
+ }
+
return slPrefix;
-
+
}
-
+
/**
- * 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 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.
- *
- * @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
*/
private static String checkSLnsDeclaration(Element contextElement, String slPrefix, String slNameSpace)
- throws XPathException
- {
- String nsAtt = "xmlns:" + slPrefix;
- String nameSpace = contextElement.getAttribute(nsAtt);
+ throws XPathException {
+ final String nsAtt = "xmlns:" + slPrefix;
+ final String nameSpace = contextElement.getAttribute(nsAtt);
if (nameSpace == "") {
return null;
} else {
@@ -547,8 +539,9 @@ public class XPathUtils {
if (nameSpace.equals(slNameSpace)) {
return slPrefix;
} else {
- MessageProvider msg = MessageProvider.getInstance();
- String message = msg.getMessage("xpath.00", new Object[] { "Ung�ltiger SecurityLayer Namespace: \"" + nameSpace + "\"."});
+ final MessageProvider msg = MessageProvider.getInstance();
+ final String message = msg.getMessage("xpath.00", new Object[] {
+ "Ung�ltiger SecurityLayer Namespace: \"" + nameSpace + "\"." });
throw new XPathException(message, null);
}
}