use of org.apache.camel.model.language.XPathExpression in project camel by apache.
the class ExpressionClauseSupport method xpath.
/**
* Evaluates an <a href="http://camel.apache.org/xpath.html">XPath
* expression</a> with the specified set of namespace prefixes and URIs
*
* @param text the expression to be evaluated
* @param namespaces the namespace prefix and URIs to use
* @return the builder to continue processing the DSL
*/
public T xpath(String text, Map<String, String> namespaces) {
XPathExpression expression = new XPathExpression(text);
expression.setNamespaces(namespaces);
setExpressionType(expression);
return result;
}
use of org.apache.camel.model.language.XPathExpression in project camel by apache.
the class ExpressionClauseSupport method xpath.
/**
* Evaluates an <a href="http://camel.apache.org/xpath.html">XPath
* expression</a> with the specified result type and set of namespace
* prefixes and URIs on the supplied header name's contents
*
* @param text the expression to be evaluated
* @param resultType the return type expected by the expression
* @param namespaces the namespace prefix and URIs to use
* @param headerName the name of the header to apply the expression to
* @return the builder to continue processing the DSL
*/
public T xpath(String text, Class<?> resultType, Namespaces namespaces, String headerName) {
XPathExpression expression = new XPathExpression(text);
expression.setResultType(resultType);
expression.setNamespaces(namespaces.getNamespaces());
expression.setHeaderName(headerName);
setExpressionType(expression);
return result;
}
use of org.apache.camel.model.language.XPathExpression 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.model.language.XPathExpression in project camel by apache.
the class MockXpathTest method testXpathAssertion.
public void testXpathAssertion() throws Exception {
MockEndpoint result = getMockEndpoint("mock:result");
result.expectedMessageCount(1);
XPathExpression xpath = new XPathExpression("/foo = 'bar'");
xpath.setResultType(Boolean.class);
result.allMessages().body().matches(xpath);
template.sendBody("direct:start", "<foo>bar</foo>");
assertMockEndpointsSatisfied();
}
use of org.apache.camel.model.language.XPathExpression in project camel by apache.
the class SpringDataFormatPartialTest method testPartialMarshal.
@Test
public void testPartialMarshal() throws Exception {
PurchaseOrder bean = new PurchaseOrder();
bean.setName("Beer");
bean.setAmount(23);
bean.setPrice(2.5);
MockEndpoint mock = resolveMandatoryEndpoint("mock:marshal", MockEndpoint.class);
mock.expectedMessageCount(1);
XPathExpression xpath = new XPathExpression("count(//*[namespace-uri() = 'http://example.camel.org/apache' and local-name() = 'po']) = 1");
xpath.setResultType(Boolean.class);
mock.allMessages().body().matches(xpath);
template.sendBody("direct:marshal", bean);
mock.assertIsSatisfied();
//To make sure there is no XML declaration.
assertFalse("There should have no XML declaration.", mock.getExchanges().get(0).getIn().getBody(String.class).startsWith("<?xml version="));
}
Aggregations