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);
}
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;
}
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;
}
Aggregations