List of usage examples for javax.xml.xpath XPathFunction XPathFunction
XPathFunction
From source file:org.apache.camel.builder.xml.XPathBuilder.java
public XPathFunction getBodyFunction() { if (bodyFunction == null) { bodyFunction = new XPathFunction() { public Object evaluate(List list) throws XPathFunctionException { if (exchange == null) { return null; }//www . j a v a 2 s . c o m return exchange.get().getIn().getBody(); } }; } return bodyFunction; }
From source file:org.apache.camel.builder.xml.XPathBuilder.java
public XPathFunction getHeaderFunction() { if (headerFunction == null) { headerFunction = new XPathFunction() { public Object evaluate(List list) throws XPathFunctionException { if (exchange != null && !list.isEmpty()) { Object value = list.get(0); if (value != null) { String text = exchange.get().getContext().getTypeConverter().convertTo(String.class, value);/*w ww .ja v a2 s. co m*/ return exchange.get().getIn().getHeader(text); } } return null; } }; } return headerFunction; }
From source file:org.apache.camel.builder.xml.XPathBuilder.java
public XPathFunction getOutBodyFunction() { if (outBodyFunction == null) { outBodyFunction = new XPathFunction() { public Object evaluate(List list) throws XPathFunctionException { if (exchange.get() != null && exchange.get().hasOut()) { return exchange.get().getOut().getBody(); }/*from w w w .ja va 2 s. c o m*/ return null; } }; } return outBodyFunction; }
From source file:org.apache.camel.builder.xml.XPathBuilder.java
public XPathFunction getOutHeaderFunction() { if (outHeaderFunction == null) { outHeaderFunction = new XPathFunction() { public Object evaluate(List list) throws XPathFunctionException { if (exchange.get() != null && !list.isEmpty()) { Object value = list.get(0); if (value != null) { String text = exchange.get().getContext().getTypeConverter().convertTo(String.class, value);// w w w .java2s. c o m return exchange.get().getOut().getHeader(text); } } return null; } }; } return outHeaderFunction; }
From source file:org.apache.camel.builder.xml.XPathBuilder.java
public XPathFunction getPropertiesFunction() { if (propertiesFunction == null) { propertiesFunction = new XPathFunction() { public Object evaluate(List list) throws XPathFunctionException { if (exchange != null && !list.isEmpty()) { Object value = list.get(0); if (value != null) { String text = exchange.get().getContext().getTypeConverter().convertTo(String.class, value);/*from www . jav a2 s . com*/ try { // use the property placeholder resolver to lookup the property for us Object answer = exchange.get().getContext() .resolvePropertyPlaceholders("{{" + text + "}}"); return answer; } catch (Exception e) { throw new XPathFunctionException(e); } } } return null; } }; } return propertiesFunction; }
From source file:org.apache.camel.builder.xml.XPathBuilder.java
public XPathFunction getSimpleFunction() { if (simpleFunction == null) { simpleFunction = new XPathFunction() { public Object evaluate(List list) throws XPathFunctionException { if (exchange != null && !list.isEmpty()) { Object value = list.get(0); if (value != null) { String text = exchange.get().getContext().getTypeConverter().convertTo(String.class, value);// w w w . ja va 2 s. c o m Language simple = exchange.get().getContext().resolveLanguage("simple"); Expression exp = simple.createExpression(text); Object answer = exp.evaluate(exchange.get(), Object.class); return answer; } } return null; } }; } return simpleFunction; }
From source file:org.kuali.rice.kew.rule.xmlrouting.WorkflowFunctionResolver.java
public XPathFunction resolveFunction(QName fname, int arity) { if (fname == null) { throw new NullPointerException("The function name cannot be null."); }/*from w w w. java 2 s. c o m*/ if (fname.equals(new QName("http://nothingfornowwf.com", "ruledata", "wf"))) { if (ruleExtensions == null) { throw new IllegalArgumentException("There are no rule extensions."); } return new XPathFunction() { public Object evaluate(List args) { if (args.size() == 1) { String name = (String) args.get(0); for (RuleExtension ruleExtension : ruleExtensions) { for (Map.Entry<String, String> entry : ruleExtension.getExtensionValuesMap() .entrySet()) { if (entry.getKey().equals(name)) { return entry.getValue(); } } } } return ""; } }; } else if (fname.equals(new QName("http://nothingfornowwf.com", "xstreamsafe", "wf"))) { return new XStreamSafeSearchFunction(rootNode, this.getXpath()); } else if (fname.equals(new QName("http://nothingfornowwf.com", "upper-case", "wf"))) { return new UpperCaseFunction(); } else if (fname.equals(new QName("http://nothingfornowwf.com", "field", "wf"))) { return new XPathFunction() { public Object evaluate(java.util.List args) { if (args.size() == 1) { String name = (String) args.get(0); try { return field(name); } catch (Exception e) { throw new WorkflowRuntimeException("Failed to find field to validate.", e); } } return ""; } }; } else if (fname.equals(new QName("http://nothingfornowwf.com", "empty", "wf"))) { return new XPathFunction() { public Object evaluate(java.util.List args) { return empty(args.get(0)); } }; } else { return null; } }