Mercurial > dive4elements > river
comparison gwt-client/src/main/java/org/dive4elements/river/client/server/auth/saml/XPathUtils.java @ 5939:407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
author | Bernhard Herzog <bh@intevation.de> |
---|---|
date | Wed, 08 May 2013 17:56:13 +0200 |
parents | |
children | 7b0db743f074 |
comparison
equal
deleted
inserted
replaced
5938:231a834d4e28 | 5939:407cff3b03ab |
---|---|
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde | |
2 * Software engineering by Intevation GmbH | |
3 * | |
4 * This file is Free Software under the GNU AGPL (>=v3) | |
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the | |
6 * documentation coming with Dive4Elements River for details. | |
7 */ | |
8 | |
9 package org.dive4elements.river.client.server.auth.saml; | |
10 | |
11 import javax.xml.namespace.QName; | |
12 import javax.xml.xpath.XPathConstants; | |
13 | |
14 import org.w3c.dom.Node; | |
15 import org.w3c.dom.NodeList; | |
16 | |
17 import org.dive4elements.artifacts.common.utils.XMLUtils; | |
18 | |
19 | |
20 /** | |
21 * Convenience methods to evaluate XPath queries on SAML documents. The | |
22 * methods are just front-ends for the {@link XMLUtils.xpath} method. | |
23 */ | |
24 public class XPathUtils | |
25 { | |
26 /** | |
27 * Evaluates an XPath query on a given object and returns the result | |
28 * as a given type, using SamlNamespaceContext as the namespace | |
29 * context. | |
30 * @param root The object which is used as the root of the tree to | |
31 * be searched in. | |
32 * @param query The XPath query | |
33 * @param returnType The type of the result. | |
34 * @return The result of type 'returnType' or null if something | |
35 * went wrong during XPath evaluation. | |
36 */ | |
37 public static final Object xpath(Object root, String query, | |
38 QName returnType) { | |
39 return XMLUtils.xpath(root, query, returnType, | |
40 SamlNamespaceContext.INSTANCE); | |
41 } | |
42 | |
43 | |
44 /** | |
45 * Evaluates an XPath query on a given object and returns the result | |
46 * as a String, using SamlNamespaceContext as the namespace context. | |
47 * @param root The object which is used as the root of the tree to | |
48 * be searched in. | |
49 * @param query The XPath query | |
50 * @return The result as a String or null if something went wrong | |
51 * during XPath evaluation. | |
52 */ | |
53 public static final String xpathString(Object root, String query) { | |
54 return (String)xpath(root, query, XPathConstants.STRING); | |
55 } | |
56 | |
57 | |
58 /** | |
59 * Evaluates an XPath query on a given object and returns the result | |
60 * as a Node, using SamlNamespaceContext as the namespace context. | |
61 * @param root The object which is used as the root of the tree to | |
62 * be searched in. | |
63 * @param query The XPath query | |
64 * @return The result as a Node or null if something went wrong | |
65 * during XPath evaluation. | |
66 */ | |
67 public static final Node xpathNode(Object root, String query) { | |
68 return (Node)xpath(root, query, XPathConstants.NODE); | |
69 } | |
70 | |
71 | |
72 /** | |
73 * Evaluates an XPath query on a given object and returns the result | |
74 * as a NodeList, using SamlNamespaceContext as the namespace | |
75 * context. | |
76 * @param root The object which is used as the root of the tree to | |
77 * be searched in. | |
78 * @param query The XPath query | |
79 * @return The result as a NodeList or null if something | |
80 * went wrong during XPath evaluation. | |
81 */ | |
82 public static final NodeList xpathNodeList(Object root, String query) { | |
83 return (NodeList)xpath(root, query, XPathConstants.NODESET); | |
84 } | |
85 } |