Mercurial > dive4elements > river
changeset 4741:f6d0ad25f1ee
Merged
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Wed, 02 Jan 2013 15:42:22 +0100 |
parents | fb135e1dfa35 (diff) 5014a84c0c7d (current diff) |
children | ce6b9945bf8e |
files | |
diffstat | 1 files changed, 43 insertions(+), 30 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/Builder.java Wed Jan 02 15:24:18 2013 +0100 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/Builder.java Wed Jan 02 15:42:22 2013 +0100 @@ -1,34 +1,36 @@ package de.intevation.flys.artifacts.datacage.templating; -import java.util.regex.Pattern; -import java.util.regex.Matcher; - -import java.util.ArrayList; -import java.util.List; -import java.util.HashMap; -import java.util.Map; -import java.util.Deque; -import java.util.ArrayDeque; - -import org.w3c.dom.Document; -import org.w3c.dom.NodeList; -import org.w3c.dom.Node; -import org.w3c.dom.Element; - -import javax.xml.xpath.XPath; -import javax.xml.xpath.XPathFactory; -import javax.xml.xpath.XPathExpressionException; -import javax.xml.xpath.XPathConstants; - -import java.sql.SQLException; -import java.sql.Connection; - import de.intevation.artifacts.common.utils.XMLUtils; import de.intevation.flys.utils.Pair; +import java.sql.Connection; +import java.sql.SQLException; + +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.Deque; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import javax.xml.namespace.QName; + +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathFactory; + import org.apache.log4j.Logger; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + public class Builder { @@ -82,7 +84,6 @@ } } // class NamedConnection - public class BuildHelper { protected Node output; @@ -402,7 +403,7 @@ } } - protected Object evaluateXPath(String expr) { + protected Object evaluateXPath(String expr, QName returnType) { if (log.isDebugEnabled()) { log.debug("evaluate: '" + expr + "'"); @@ -412,17 +413,17 @@ XPath xpath = XPATH_FACTORY.newXPath(); xpath.setXPathVariableResolver(frames); xpath.setXPathFunctionResolver(FunctionResolver.FUNCTIONS); - return xpath.evaluate(expr, EVAL_DOCUMENT, XPathConstants.BOOLEAN); + return xpath.evaluate(expr, EVAL_DOCUMENT, returnType); } - catch (XPathExpressionException xfce) { - log.error("expression: " + expr, xfce); + catch (XPathExpressionException xpee) { + log.error("expression: " + expr, xpee); } return null; } protected Boolean evaluateXPathToBoolean(String expr) { - Object result = evaluateXPath(expr); + Object result = evaluateXPath(expr, XPathConstants.BOOLEAN); return result instanceof Boolean ? (Boolean)result @@ -442,16 +443,20 @@ } } + protected void variable(Element current) { String varName = expand(current.getAttribute("name")); String expr = current.getAttribute("expr"); + String type = current.getAttribute("type"); if (varName.length() == 0 || expr.length() == 0) { log.error("dc:variable 'name' or 'expr' empty."); } else { - frames.put(varName.toUpperCase(), evaluateXPath(expr)); + frames.put( + varName.toUpperCase(), + evaluateXPath(expr, typeToQName(type))); } } @@ -563,6 +568,14 @@ compileStatements(); } + protected static QName typeToQName(String type) { + if ("number" .equals(type)) return XPathConstants.NUMBER; + if ("bool" .equals(type)) return XPathConstants.BOOLEAN; + if ("node" .equals(type)) return XPathConstants.NODE; + if ("nodeset".equals(type)) return XPathConstants.NODESET; + return XPathConstants.STRING; + } + /** Handle <dc:statement> elements. */ protected void compileStatements() {