Search in sources :

Example 1 with NamespacePrefix

use of org.apache.camel.language.NamespacePrefix in project camel by apache.

the class XQueryAnnotationExpressionFactory method createExpression.

@Override
public Expression createExpression(CamelContext camelContext, Annotation annotation, LanguageAnnotation languageAnnotation, Class<?> expressionReturnType) {
    String xQuery = getExpressionFromAnnotation(annotation);
    XQueryBuilder builder = XQueryBuilder.xquery(xQuery);
    if (annotation instanceof XQuery) {
        XQuery xQueryAnnotation = (XQuery) annotation;
        builder.setStripsAllWhiteSpace(xQueryAnnotation.stripsAllWhiteSpace());
        if (ObjectHelper.isNotEmpty(xQueryAnnotation.headerName())) {
            builder.setHeaderName(xQueryAnnotation.headerName());
        }
        NamespacePrefix[] namespaces = xQueryAnnotation.namespaces();
        if (namespaces != null) {
            for (NamespacePrefix namespacePrefix : namespaces) {
                builder = builder.namespace(namespacePrefix.prefix(), namespacePrefix.uri());
            }
        }
    }
    if (expressionReturnType.isAssignableFrom(String.class)) {
        builder.setResultsFormat(ResultFormat.String);
    } else if (expressionReturnType.isAssignableFrom(CollectionFn.class)) {
        builder.setResultsFormat(ResultFormat.List);
    } else if (expressionReturnType.isAssignableFrom(Node.class)) {
        builder.setResultsFormat(ResultFormat.DOM);
    } else if (expressionReturnType.isAssignableFrom(byte[].class)) {
        builder.setResultsFormat(ResultFormat.Bytes);
    }
    return builder;
}
Also used : CollectionFn(net.sf.saxon.functions.CollectionFn) NamespacePrefix(org.apache.camel.language.NamespacePrefix)

Example 2 with NamespacePrefix

use of org.apache.camel.language.NamespacePrefix in project camel by apache.

the class XPathAnnotationExpressionFactory method createExpression.

@Override
public Expression createExpression(CamelContext camelContext, Annotation annotation, LanguageAnnotation languageAnnotation, Class<?> expressionReturnType) {
    String xpath = getExpressionFromAnnotation(annotation);
    Class<?> resultType = getResultType(annotation);
    if (resultType.equals(Object.class)) {
        resultType = expressionReturnType;
    }
    XPathBuilder builder = XPathBuilder.xpath(xpath, resultType);
    NamespacePrefix[] namespaces = getExpressionNameSpacePrefix(annotation);
    if (namespaces != null) {
        for (NamespacePrefix namespacePrefix : namespaces) {
            builder = builder.namespace(namespacePrefix.prefix(), namespacePrefix.uri());
        }
    }
    // Set the header name that we want the XPathBuilder to apply the XPath expression to
    String headerName = getHeaderName(annotation);
    if (ObjectHelper.isNotEmpty(headerName)) {
        builder.setHeaderName(headerName);
    }
    return builder;
}
Also used : XPathBuilder(org.apache.camel.builder.xml.XPathBuilder) NamespacePrefix(org.apache.camel.language.NamespacePrefix)

Aggregations

NamespacePrefix (org.apache.camel.language.NamespacePrefix)2 CollectionFn (net.sf.saxon.functions.CollectionFn)1 XPathBuilder (org.apache.camel.builder.xml.XPathBuilder)1