Search in sources :

Example 1 with NoSuchLanguageException

use of org.apache.camel.NoSuchLanguageException in project camel by apache.

the class OsgiLanguageResolver method resolveLanguage.

public Language resolveLanguage(String name, CamelContext context) {
    // lookup in registry first
    Language lang = ResolverHelper.lookupLanguageInRegistryWithFallback(context, name);
    if (lang != null) {
        return lang;
    }
    lang = getLanguage(name, context);
    if (lang != null) {
        return lang;
    }
    LanguageResolver resolver = getLanguageResolver("default", context);
    if (resolver != null) {
        return resolver.resolveLanguage(name, context);
    }
    throw new NoSuchLanguageException(name);
}
Also used : LanguageResolver(org.apache.camel.spi.LanguageResolver) Language(org.apache.camel.spi.Language) NoSuchLanguageException(org.apache.camel.NoSuchLanguageException)

Example 2 with NoSuchLanguageException

use of org.apache.camel.NoSuchLanguageException in project camel by apache.

the class ExpressionDefinition method createPredicate.

public Predicate createPredicate(CamelContext camelContext) {
    if (predicate == null) {
        if (getExpressionType() != null) {
            predicate = getExpressionType().createPredicate(camelContext);
        } else if (getExpressionValue() != null) {
            predicate = new ExpressionToPredicateAdapter(getExpressionValue());
        } else if (getExpression() != null) {
            ObjectHelper.notNull("language", getLanguage());
            Language language = camelContext.resolveLanguage(getLanguage());
            if (language == null) {
                throw new NoSuchLanguageException(getLanguage());
            }
            String exp = getExpression();
            // should be true by default
            boolean isTrim = getTrim() == null || getTrim();
            // trim if configured to trim
            if (exp != null && isTrim) {
                exp = exp.trim();
            }
            // resolve the expression as it may be an external script from the classpath/file etc
            exp = ResourceHelper.resolveOptionalExternalScript(camelContext, exp);
            predicate = language.createPredicate(exp);
            configurePredicate(camelContext, predicate);
        }
    }
    return predicate;
}
Also used : Language(org.apache.camel.spi.Language) ExpressionToPredicateAdapter(org.apache.camel.util.ExpressionToPredicateAdapter) NoSuchLanguageException(org.apache.camel.NoSuchLanguageException)

Example 3 with NoSuchLanguageException

use of org.apache.camel.NoSuchLanguageException in project camel by apache.

the class ToDynamicDefinition method createExpression.

protected Expression createExpression(RouteContext routeContext) {
    List<Expression> list = new ArrayList<Expression>();
    String[] parts = safeSplitRaw(uri);
    for (String part : parts) {
        // the part may have optional language to use, so you can mix languages
        String value = ObjectHelper.after(part, "language:");
        if (value != null) {
            String before = ObjectHelper.before(value, ":");
            String after = ObjectHelper.after(value, ":");
            if (before != null && after != null) {
                // maybe its a language, must have language: as prefix
                try {
                    Language partLanguage = routeContext.getCamelContext().resolveLanguage(before);
                    if (partLanguage != null) {
                        Expression exp = partLanguage.createExpression(after);
                        list.add(exp);
                        continue;
                    }
                } catch (NoSuchLanguageException e) {
                // ignore
                }
            }
        }
        // fallback and use simple language
        Language lan = routeContext.getCamelContext().resolveLanguage("simple");
        Expression exp = lan.createExpression(part);
        list.add(exp);
    }
    Expression exp;
    if (list.size() == 1) {
        exp = list.get(0);
    } else {
        exp = ExpressionBuilder.concatExpression(list);
    }
    return exp;
}
Also used : Language(org.apache.camel.spi.Language) Expression(org.apache.camel.Expression) ArrayList(java.util.ArrayList) NoSuchLanguageException(org.apache.camel.NoSuchLanguageException)

Aggregations

NoSuchLanguageException (org.apache.camel.NoSuchLanguageException)3 Language (org.apache.camel.spi.Language)3 ArrayList (java.util.ArrayList)1 Expression (org.apache.camel.Expression)1 LanguageResolver (org.apache.camel.spi.LanguageResolver)1 ExpressionToPredicateAdapter (org.apache.camel.util.ExpressionToPredicateAdapter)1