bh@5939: /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde bh@5939: * Software engineering by Intevation GmbH bh@5939: * bh@5939: * This file is Free Software under the GNU AGPL (>=v3) bh@5939: * and comes with ABSOLUTELY NO WARRANTY! Check out the bh@5939: * documentation coming with Dive4Elements River for details. bh@5939: */ bh@5939: bh@5939: package org.dive4elements.river.client.server.auth.saml; bh@5939: bh@5939: import javax.xml.namespace.QName; bh@5939: import javax.xml.xpath.XPathConstants; bh@5939: bh@5939: import org.w3c.dom.Node; bh@5939: import org.w3c.dom.NodeList; bh@5939: bh@5939: import org.dive4elements.artifacts.common.utils.XMLUtils; bh@5939: bh@5939: bh@5939: /** bh@5939: * Convenience methods to evaluate XPath queries on SAML documents. The bh@5939: * methods are just front-ends for the {@link XMLUtils.xpath} method. bh@5939: */ bh@5939: public class XPathUtils bh@5939: { bh@5939: /** bh@5939: * Evaluates an XPath query on a given object and returns the result bh@5939: * as a given type, using SamlNamespaceContext as the namespace bh@5939: * context. bh@5939: * @param root The object which is used as the root of the tree to bh@5939: * be searched in. bh@5939: * @param query The XPath query bh@5939: * @param returnType The type of the result. bh@5939: * @return The result of type 'returnType' or null if something bh@5939: * went wrong during XPath evaluation. bh@5939: */ bh@5939: public static final Object xpath(Object root, String query, bh@5939: QName returnType) { bh@5939: return XMLUtils.xpath(root, query, returnType, bh@5939: SamlNamespaceContext.INSTANCE); bh@5939: } bh@5939: bh@5939: bh@5939: /** bh@5939: * Evaluates an XPath query on a given object and returns the result bh@5939: * as a String, using SamlNamespaceContext as the namespace context. bh@5939: * @param root The object which is used as the root of the tree to bh@5939: * be searched in. bh@5939: * @param query The XPath query bh@5939: * @return The result as a String or null if something went wrong bh@5939: * during XPath evaluation. bh@5939: */ bh@5939: public static final String xpathString(Object root, String query) { bh@5939: return (String)xpath(root, query, XPathConstants.STRING); bh@5939: } bh@5939: bh@5939: bh@5939: /** bh@5939: * Evaluates an XPath query on a given object and returns the result bh@5939: * as a Node, using SamlNamespaceContext as the namespace context. bh@5939: * @param root The object which is used as the root of the tree to bh@5939: * be searched in. bh@5939: * @param query The XPath query bh@5939: * @return The result as a Node or null if something went wrong bh@5939: * during XPath evaluation. bh@5939: */ bh@5939: public static final Node xpathNode(Object root, String query) { bh@5939: return (Node)xpath(root, query, XPathConstants.NODE); bh@5939: } bh@5939: bh@5939: bh@5939: /** bh@5939: * Evaluates an XPath query on a given object and returns the result bh@5939: * as a NodeList, using SamlNamespaceContext as the namespace bh@5939: * context. bh@5939: * @param root The object which is used as the root of the tree to bh@5939: * be searched in. bh@5939: * @param query The XPath query bh@5939: * @return The result as a NodeList or null if something bh@5939: * went wrong during XPath evaluation. bh@5939: */ bh@5939: public static final NodeList xpathNodeList(Object root, String query) { bh@5939: return (NodeList)xpath(root, query, XPathConstants.NODESET); bh@5939: } bh@5939: }