Search in sources :

Example 1 with XPathBuilder

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;
}
Also used : XPathBuilder(org.apache.camel.builder.xml.XPathBuilder)

Example 2 with XPathBuilder

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;
}
Also used : XPathBuilder(org.apache.camel.builder.xml.XPathBuilder)

Example 3 with XPathBuilder

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);
}
Also used : XPathExpression(org.apache.camel.model.language.XPathExpression) ValueBuilder(org.apache.camel.builder.ValueBuilder) SimpleBuilder(org.apache.camel.builder.SimpleBuilder) XPathBuilder(org.apache.camel.builder.xml.XPathBuilder) ExpressionDefinition(org.apache.camel.model.language.ExpressionDefinition) SimpleExpression(org.apache.camel.model.language.SimpleExpression)

Example 4 with XPathBuilder

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");
        }
    };
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) XPathBuilder(org.apache.camel.builder.xml.XPathBuilder)

Example 5 with XPathBuilder

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
}
Also used : XPathFactoryImpl(net.sf.saxon.xpath.XPathFactoryImpl) XPathFactory(javax.xml.xpath.XPathFactory) XPathBuilder(org.apache.camel.builder.xml.XPathBuilder) Test(org.junit.Test)

Aggregations

XPathBuilder (org.apache.camel.builder.xml.XPathBuilder)14 Test (org.junit.Test)6 XPathFactory (javax.xml.xpath.XPathFactory)3 XPathFactoryImpl (net.sf.saxon.xpath.XPathFactoryImpl)3 InputStream (java.io.InputStream)2 DOMSource (javax.xml.transform.dom.DOMSource)2 SimpleBuilder (org.apache.camel.builder.SimpleBuilder)2 ValueBuilder (org.apache.camel.builder.ValueBuilder)2 ExpressionDefinition (org.apache.camel.model.language.ExpressionDefinition)2 SimpleExpression (org.apache.camel.model.language.SimpleExpression)2 XPathExpression (org.apache.camel.model.language.XPathExpression)2 XMLCipher (org.apache.xml.security.encryption.XMLCipher)2 Document (org.w3c.dom.Document)2 Node (org.w3c.dom.Node)2 NodeList (org.w3c.dom.NodeList)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Expression (org.apache.camel.Expression)1 Predicate (org.apache.camel.Predicate)1 RouteBuilder (org.apache.camel.builder.RouteBuilder)1 NamespacePrefix (org.apache.camel.language.NamespacePrefix)1