Search in sources :

Example 16 with MapContext

use of org.apache.commons.jexl3.MapContext 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 17 with MapContext

use of org.apache.commons.jexl3.MapContext in project cxf by apache.

the class JexlClaimsMapper method mapClaims.

public ProcessedClaimCollection mapClaims(String sourceRealm, ProcessedClaimCollection sourceClaims, String targetRealm, ClaimsParameters parameters) {
    JexlContext context = new MapContext();
    context.set("sourceClaims", sourceClaims);
    context.set("targetClaims", new ProcessedClaimCollection());
    context.set("sourceRealm", sourceRealm);
    context.set("targetRealm", targetRealm);
    context.set("claimsParameters", parameters);
    Script s = getScript();
    if (s == null) {
        LOG.warning("No claim mapping script defined");
        // TODO Check if null or an exception would be more
        return new ProcessedClaimCollection();
    // appropriate
    }
    return (ProcessedClaimCollection) s.execute(context);
}
Also used : Script(org.apache.commons.jexl2.Script) ProcessedClaimCollection(org.apache.cxf.sts.claims.ProcessedClaimCollection) JexlContext(org.apache.commons.jexl2.JexlContext) MapContext(org.apache.commons.jexl2.MapContext)

Aggregations

MapContext (org.apache.commons.jexl2.MapContext)16 JexlContext (org.apache.commons.jexl2.JexlContext)12 Expression (org.apache.commons.jexl2.Expression)6 JexlEngine (org.apache.commons.jexl2.JexlEngine)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 JexlException (org.apache.commons.jexl2.JexlException)3 ReadonlyContext (org.apache.commons.jexl2.ReadonlyContext)2 CompoundVariable (org.apache.jmeter.engine.util.CompoundVariable)2 JMeterContext (org.apache.jmeter.threads.JMeterContext)2 JMeterVariables (org.apache.jmeter.threads.JMeterVariables)2 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 InetAddress (java.net.InetAddress)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 ColumnConfig (ml.shifu.shifu.container.obj.ColumnConfig)1 Script (org.apache.commons.jexl2.Script)1