Search in sources :

Example 11 with Expression

use of org.apache.commons.jexl2.Expression 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)

Aggregations

MapContext (org.apache.commons.jexl2.MapContext)10 JexlContext (org.apache.commons.jexl2.JexlContext)7 Expression (org.apache.commons.jexl2.Expression)6 JexlEngine (org.apache.commons.jexl2.JexlEngine)6 HashMap (java.util.HashMap)3 JexlException (org.apache.commons.jexl2.JexlException)3 Map (java.util.Map)2 InetAddress (java.net.InetAddress)1 LinkedHashMap (java.util.LinkedHashMap)1 ReadonlyContext (org.apache.commons.jexl2.ReadonlyContext)1 CompoundVariable (org.apache.jmeter.engine.util.CompoundVariable)1 JMeterContext (org.apache.jmeter.threads.JMeterContext)1 JMeterVariables (org.apache.jmeter.threads.JMeterVariables)1 DBException (org.jkiss.dbeaver.DBException)1 ParameterMap (org.opennms.core.utils.ParameterMap)1 JmxConnectionManager (org.opennms.netmgt.jmx.connection.JmxConnectionManager)1 JmxServerConnectionException (org.opennms.netmgt.jmx.connection.JmxServerConnectionException)1 JmxServerConnectionWrapper (org.opennms.netmgt.jmx.connection.JmxServerConnectionWrapper)1 DefaultConnectionManager (org.opennms.netmgt.jmx.impl.connection.connectors.DefaultConnectionManager)1 ExpressionException (org.opennms.netmgt.measurements.api.exceptions.ExpressionException)1