Mercurial > dive4elements > framework
comparison artifacts-common/src/main/java/de/intevation/artifacts/common/utils/MapXPathVariableResolver.java @ 323:1d3607ceb9fa
Improved the XMLUtils to support xpath expressions that contain variables.
artifacts/trunk@2540 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 24 Aug 2011 07:44:11 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
322:93a774fe2bb4 | 323:1d3607ceb9fa |
---|---|
1 /* | |
2 * Copyright (c) 2011 by Intevation GmbH | |
3 * | |
4 * This program is free software under the LGPL (>=v2.1) | |
5 * Read the file LGPL.txt coming with the software for details | |
6 * or visit http://www.gnu.org/licenses/ if it does not exist. | |
7 */ | |
8 package de.intevation.artifacts.common.utils; | |
9 | |
10 import java.util.HashMap; | |
11 import java.util.Map; | |
12 | |
13 import javax.xml.namespace.QName; | |
14 import javax.xml.xpath.XPathVariableResolver; | |
15 | |
16 | |
17 /** | |
18 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
19 */ | |
20 public class MapXPathVariableResolver implements XPathVariableResolver { | |
21 | |
22 protected Map<String, String> variables; | |
23 | |
24 | |
25 public MapXPathVariableResolver() { | |
26 this.variables = new HashMap<String, String>(); | |
27 } | |
28 | |
29 | |
30 public MapXPathVariableResolver(Map<String, String> variables) { | |
31 this.variables = variables; | |
32 } | |
33 | |
34 | |
35 public void addVariable(String name, String value) { | |
36 if (name != null && value != null) { | |
37 variables.put(name, value); | |
38 } | |
39 } | |
40 | |
41 | |
42 @Override | |
43 public Object resolveVariable(QName variableName) { | |
44 String key = variableName.getLocalPart(); | |
45 return variables.get(key); | |
46 } | |
47 } | |
48 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |