[Dive4elements-commits] [PATCH 07 of 21] Add XPathUtils, helper functions to process SAML with XPath
Wald Commits
scm-commit at wald.intevation.org
Wed May 8 18:08:17 CEST 2013
# HG changeset patch
# User Bernhard Herzog <bh at intevation.de>
# Date 1368028573 -7200
# Node ID 407cff3b03ab38e76e0065b9f9ee3132a8777cbf
# Parent 231a834d4e28dbe65a0f284070b69104d71051f8
Add XPathUtils, helper functions to process SAML with XPath.
diff -r 231a834d4e28 -r 407cff3b03ab gwt-client/src/main/java/org/dive4elements/river/client/server/auth/saml/XPathUtils.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/server/auth/saml/XPathUtils.java Wed May 08 17:56:13 2013 +0200
@@ -0,0 +1,85 @@
+/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
+ * Software engineering by Intevation GmbH
+ *
+ * This file is Free Software under the GNU AGPL (>=v3)
+ * and comes with ABSOLUTELY NO WARRANTY! Check out the
+ * documentation coming with Dive4Elements River for details.
+ */
+
+package org.dive4elements.river.client.server.auth.saml;
+
+import javax.xml.namespace.QName;
+import javax.xml.xpath.XPathConstants;
+
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import org.dive4elements.artifacts.common.utils.XMLUtils;
+
+
+/**
+ * Convenience methods to evaluate XPath queries on SAML documents. The
+ * methods are just front-ends for the {@link XMLUtils.xpath} method.
+ */
+public class XPathUtils
+{
+ /**
+ * Evaluates an XPath query on a given object and returns the result
+ * as a given type, using SamlNamespaceContext as the namespace
+ * context.
+ * @param root The object which is used as the root of the tree to
+ * be searched in.
+ * @param query The XPath query
+ * @param returnType The type of the result.
+ * @return The result of type 'returnType' or null if something
+ * went wrong during XPath evaluation.
+ */
+ public static final Object xpath(Object root, String query,
+ QName returnType) {
+ return XMLUtils.xpath(root, query, returnType,
+ SamlNamespaceContext.INSTANCE);
+ }
+
+
+ /**
+ * Evaluates an XPath query on a given object and returns the result
+ * as a String, using SamlNamespaceContext as the namespace context.
+ * @param root The object which is used as the root of the tree to
+ * be searched in.
+ * @param query The XPath query
+ * @return The result as a String or null if something went wrong
+ * during XPath evaluation.
+ */
+ public static final String xpathString(Object root, String query) {
+ return (String)xpath(root, query, XPathConstants.STRING);
+ }
+
+
+ /**
+ * Evaluates an XPath query on a given object and returns the result
+ * as a Node, using SamlNamespaceContext as the namespace context.
+ * @param root The object which is used as the root of the tree to
+ * be searched in.
+ * @param query The XPath query
+ * @return The result as a Node or null if something went wrong
+ * during XPath evaluation.
+ */
+ public static final Node xpathNode(Object root, String query) {
+ return (Node)xpath(root, query, XPathConstants.NODE);
+ }
+
+
+ /**
+ * Evaluates an XPath query on a given object and returns the result
+ * as a NodeList, using SamlNamespaceContext as the namespace
+ * context.
+ * @param root The object which is used as the root of the tree to
+ * be searched in.
+ * @param query The XPath query
+ * @return The result as a NodeList or null if something
+ * went wrong during XPath evaluation.
+ */
+ public static final NodeList xpathNodeList(Object root, String query) {
+ return (NodeList)xpath(root, query, XPathConstants.NODESET);
+ }
+}
More information about the Dive4elements-commits
mailing list