comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/meta/Builder.java @ 959:a2b20ed3d3b4

Datacage: Added custom provider for XPath functions. flys-artifacts/trunk@2378 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 20 Jul 2011 16:28:49 +0000
parents e91996b46e3c
children 3ba4f5a88c20
comparison
equal deleted inserted replaced
958:ae198bef4ba0 959:a2b20ed3d3b4
204 if (test.length() == 0) { 204 if (test.length() == 0) {
205 log.warn("no 'test' attribute found for when"); 205 log.warn("no 'test' attribute found for when");
206 continue; 206 continue;
207 } 207 }
208 208
209 try { 209 Boolean result = evaluateXPath(test);
210 XPath xpath = XPATH_FACTORY.newXPath(); 210 if (result != null && result.booleanValue()) {
211 xpath.setXPathVariableResolver(frames); 211 branch = child;
212 Object result = xpath.evaluate( 212 break;
213 test, EVAL_DOCUMENT, XPathConstants.BOOLEAN); 213 }
214 214
215 if (result instanceof Boolean
216 && ((Boolean)result).booleanValue()) {
217 branch = child;
218 break;
219 }
220 }
221 catch (XPathExpressionException xfce) {
222 log.error(xfce);
223 }
224 continue; 215 continue;
225 } 216 }
226 else if ("otherwise".equals(name)) { 217 else if ("otherwise".equals(name)) {
227 branch = child; 218 branch = child;
228 // No break here. 219 // No break here.
233 NodeList subs = branch.getChildNodes(); 224 NodeList subs = branch.getChildNodes();
234 for (int i = 0, N = subs.getLength(); i < N; ++i) { 225 for (int i = 0, N = subs.getLength(); i < N; ++i) {
235 build(parent, subs.item(i)); 226 build(parent, subs.item(i));
236 } 227 }
237 } 228 }
229 }
230
231 protected Boolean evaluateXPath(String expr) {
232 try {
233 XPath xpath = XPATH_FACTORY.newXPath();
234 xpath.setXPathVariableResolver(frames);
235 xpath.setXPathFunctionResolver(FunctionResolver.FUNCTIONS);
236 Object result = xpath.evaluate(
237 expr, EVAL_DOCUMENT, XPathConstants.BOOLEAN);
238
239 return result instanceof Boolean
240 ? (Boolean)result
241 : null;
242 }
243 catch (XPathExpressionException xfce) {
244 log.error(xfce);
245 }
246 return null;
238 } 247 }
239 248
240 protected void convert(Node parent, Element current) { 249 protected void convert(Node parent, Element current) {
241 250
242 String variable = expand(current.getAttribute("var")); 251 String variable = expand(current.getAttribute("var"));

http://dive4elements.wald.intevation.org