Example usage for org.apache.commons.jexl3 MapContext MapContext

List of usage examples for org.apache.commons.jexl3 MapContext MapContext

Introduction

In this page you can find the example usage for org.apache.commons.jexl3 MapContext MapContext.

Prototype

public MapContext(Map<String, Object> vars) 

Source Link

Document

Creates a MapContext wrapping an existing user provided map.

Usage

From source file:com.technophobia.substeps.model.Arguments.java

public static Object evaluateExpression(String expressionWithDelimiters) {

    ParameterSubstitution parameterSubstituionConfig = NewSubstepsExecutionConfig
            .getParameterSubstituionConfig();

    // TODO - check that the expression doesn't contain any of the bad words
    // or and eq ne lt gt le ge div mod not null true false new var return
    // any of those words need to be qutoed or ['  ']
    // http://commons.apache.org/proper/commons-jexl/reference/syntax.html

    // try evaluating this expression against the executionContext

    // TODO check flag to see whether we can evaluate things from the ec

    if (expressionWithDelimiters != null && parameterSubstituionConfig.substituteParameters()
            && expressionWithDelimiters.startsWith(parameterSubstituionConfig.startDelimiter())) {
        String expression = StringUtils.stripStart(
                StringUtils.stripEnd(expressionWithDelimiters, parameterSubstituionConfig.endDelimiter()),
                parameterSubstituionConfig.startDelimiter());

        JexlContext context = new MapContext(ExecutionContext.flatten());

        JexlExpression e = jexl.createExpression(expression);

        return e.evaluate(context);
    } else {// ww w.  j a va 2 s.co  m
        return expressionWithDelimiters;
    }
}

From source file:org.apache.syncope.core.provisioning.java.MailTemplateTest.java

private String evaluate(final String template, final Map<String, Object> jexlVars) {
    StringWriter writer = new StringWriter();
    JexlUtils.newJxltEngine().createTemplate(template).evaluate(new MapContext(jexlVars), writer);
    return writer.toString();
}

From source file:org.everit.expression.jexl.internal.JexlCompiledExpression.java

@Override
public Object eval(final Map<String, Object> vars) {
    return jexlScript.execute(new MapContext(vars));
}