Search in sources :

Example 51 with JexlContext

use of org.apache.commons.jexl2.JexlContext in project dhis2-core by dhis2.

the class ExpressionUtils method evaluate.

/**
 * @param expression the expression.
 * @param vars the variables, can be null.
 * @param strict indicates whether to use strict or lenient engine mode.
 * @return the result of the evaluation.
 */
private static Object evaluate(String expression, Map<String, Object> vars, boolean strict) {
    expression = expression.replaceAll(IGNORED_KEYWORDS_REGEX, StringUtils.EMPTY);
    JexlEngine engine = strict ? JEXL_STRICT : JEXL;
    Expression exp = engine.createExpression(expression);
    JexlContext context = vars != null ? new MapContext(vars) : new MapContext();
    return exp.evaluate(context);
}
Also used : JexlEngine(org.apache.commons.jexl2.JexlEngine) Expression(org.apache.commons.jexl2.Expression) JexlContext(org.apache.commons.jexl2.JexlContext) MapContext(org.apache.commons.jexl2.MapContext)

Example 52 with JexlContext

use of org.apache.commons.jexl2.JexlContext in project vorto by eclipse.

the class DataMapperJxpath method matchesPropertyCondition.

private boolean matchesPropertyCondition(Stereotype stereotype, JXPathContext context) {
    if (stereotype.hasAttribute(ATTRIBUTE_CONDITION)) {
        Expression e = jexlEngine.createExpression(normalizeCondition(stereotype.getAttributes().get(ATTRIBUTE_CONDITION)));
        JexlContext jc = new ObjectContext<Object>(jexlEngine, context.getContextBean());
        jc.set("this", context.getContextBean());
        return (boolean) e.evaluate(jc);
    } else {
        return true;
    }
}
Also used : Expression(org.apache.commons.jexl2.Expression) JexlContext(org.apache.commons.jexl2.JexlContext) ObjectContext(org.apache.commons.jexl2.ObjectContext)

Aggregations

JexlContext (org.apache.commons.jexl2.JexlContext)31 Expression (org.apache.commons.jexl2.Expression)25 MapContext (org.apache.commons.jexl2.MapContext)23 JexlContext (org.apache.commons.jexl3.JexlContext)21 JexlEngine (org.apache.commons.jexl2.JexlEngine)20 MapContext (org.apache.commons.jexl3.MapContext)17 Test (org.testng.annotations.Test)13 HashMap (java.util.HashMap)5 Map (java.util.Map)4 ArrayList (java.util.ArrayList)3 JexlException (org.apache.commons.jexl2.JexlException)3 ObjectContext (org.apache.commons.jexl2.ObjectContext)3 IOException (java.io.IOException)2 ReadonlyContext (org.apache.commons.jexl2.ReadonlyContext)2 JexlScript (org.apache.commons.jexl3.JexlScript)2 NumberUtils (org.apache.commons.lang.math.NumberUtils)2 FloatWritable (org.apache.hadoop.io.FloatWritable)2 IntWritable (org.apache.hadoop.io.IntWritable)2 Text (org.apache.hadoop.io.Text)2 VersionMismatchException (org.apache.hadoop.io.VersionMismatchException)2