use of org.apache.camel.builder.xml.XPathBuilder in project camel by apache.
the class XPathLanguage method createPredicate.
public Predicate createPredicate(String expression) {
expression = loadResource(expression);
XPathBuilder builder = XPathBuilder.xpath(expression);
configureBuilder(builder);
return builder;
}
use of org.apache.camel.builder.xml.XPathBuilder in project camel by apache.
the class XPathLanguage method createExpression.
public Expression createExpression(String expression) {
expression = loadResource(expression);
XPathBuilder builder = XPathBuilder.xpath(expression);
configureBuilder(builder);
return builder;
}
use of org.apache.camel.builder.xml.XPathBuilder in project camel by apache.
the class ExpressionNodeHelper method toExpressionDefinition.
/**
* Determines which {@link ExpressionDefinition} describes the given expression best possible.
* <p/>
* This implementation will use types such as {@link SimpleExpression}, {@link XPathExpression} etc.
* if the given expression is detect as such a type.
*
* @param expression the expression
* @return a definition which describes the expression
*/
public static ExpressionDefinition toExpressionDefinition(Expression expression) {
if (expression instanceof SimpleBuilder) {
SimpleBuilder builder = (SimpleBuilder) expression;
// we keep the original expression by using the constructor that accepts an expression
SimpleExpression answer = new SimpleExpression(builder);
answer.setExpression(builder.getText());
answer.setResultType(builder.getResultType());
return answer;
} else if (expression instanceof XPathBuilder) {
XPathBuilder builder = (XPathBuilder) expression;
// we keep the original expression by using the constructor that accepts an expression
XPathExpression answer = new XPathExpression(builder);
answer.setExpression(builder.getText());
answer.setResultType(builder.getResultType());
return answer;
} else if (expression instanceof ValueBuilder) {
// ValueBuilder wraps the actual expression so unwrap
ValueBuilder builder = (ValueBuilder) expression;
expression = builder.getExpression();
}
if (expression instanceof ExpressionDefinition) {
return (ExpressionDefinition) expression;
}
return new ExpressionDefinition(expression);
}
use of org.apache.camel.builder.xml.XPathBuilder in project camel by apache.
the class XQueryPredicateFilterTest method createRouteBuilder.
@Override
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
public void configure() {
XPathBuilder splitter = new XPathBuilder("//records/record");
context.setTracing(true);
from("direct:xpath").split(splitter).filter().xquery("//record[type=2]").to("mock:result");
}
};
}
use of org.apache.camel.builder.xml.XPathBuilder in project camel by apache.
the class XPathTest method testXPathFunctionTokenizeUsingSaxonXPathFactory.
@Test
public void testXPathFunctionTokenizeUsingSaxonXPathFactory() throws Exception {
// START SNIPPET: e1
// create a Saxon factory
XPathFactory fac = new net.sf.saxon.xpath.XPathFactoryImpl();
// create a builder to evaluate the xpath using the saxon factory
XPathBuilder builder = XPathBuilder.xpath("tokenize(/foo/bar, '_')[2]").factory(fac);
// evaluate as a String result
String result = builder.evaluate(context, "<foo><bar>abc_def_ghi</bar></foo>");
assertEquals("def", result);
// END SNIPPET: e1
}
Aggregations