use of org.apache.commons.jexl3.JexlOptions in project commons-jexl by apache.
the class TemplateInterpreter method visit.
@Override
protected Object visit(final ASTJexlScript script, final Object data) {
if (script instanceof ASTJexlLambda && !((ASTJexlLambda) script).isTopLevel()) {
return new Closure(this, (ASTJexlLambda) script) {
@Override
protected Interpreter createInterpreter(final JexlContext context, final Frame local) {
final JexlOptions opts = jexl.evalOptions(script, context);
final TemplateInterpreter.Arguments targs = new TemplateInterpreter.Arguments(jexl).context(context).options(opts).frame(local).expressions(exprs).writer(writer);
return new TemplateInterpreter(targs);
}
};
}
// otherwise...
final int numChildren = script.jjtGetNumChildren();
Object result = null;
for (int i = 0; i < numChildren; i++) {
final JexlNode child = script.jjtGetChild(i);
result = child.jjtAccept(this, data);
cancelCheck(child);
}
return result;
}
use of org.apache.commons.jexl3.JexlOptions in project commons-jexl by apache.
the class TemplateScript method evaluate.
@Override
public void evaluate(final JexlContext context, final Writer writer, final Object... args) {
final Engine jexl = jxlt.getEngine();
final JexlOptions options = jexl.evalOptions(script, context);
final Frame frame = script.createFrame(args);
final TemplateInterpreter.Arguments targs = new TemplateInterpreter.Arguments(jexl).context(context).options(options).frame(frame).expressions(exprs).writer(writer);
final Interpreter interpreter = new TemplateInterpreter(targs);
interpreter.interpret(script);
}
use of org.apache.commons.jexl3.JexlOptions in project commons-jexl by apache.
the class TemplateScript method prepare.
@Override
public TemplateScript prepare(final JexlContext context) {
final Engine jexl = jxlt.getEngine();
final JexlOptions options = jexl.evalOptions(script, context);
final Frame frame = script.createFrame((Object[]) null);
final TemplateInterpreter.Arguments targs = new TemplateInterpreter.Arguments(jxlt.getEngine()).context(context).options(options).frame(frame);
final Interpreter interpreter = new TemplateInterpreter(targs);
final TemplateExpression[] immediates = new TemplateExpression[exprs.length];
for (int e = 0; e < exprs.length; ++e) {
try {
immediates[e] = exprs[e].prepare(interpreter);
} catch (final JexlException xjexl) {
final JexlException xuel = TemplateEngine.createException(xjexl.getInfo(), "prepare", exprs[e], xjexl);
if (jexl.isSilent()) {
if (jexl.logger.isWarnEnabled()) {
jexl.logger.warn(xuel.getMessage(), xuel.getCause());
}
return null;
}
throw xuel;
}
}
return new TemplateScript(jxlt, prefix, source, script, immediates);
}
use of org.apache.commons.jexl3.JexlOptions in project commons-jexl by apache.
the class LexicalTest method testInternalLexicalFeatures.
@Test
public void testInternalLexicalFeatures() throws Exception {
final String str = "42";
final JexlFeatures f = new JexlFeatures();
f.lexical(true);
f.lexicalShade(true);
final JexlEngine jexl = new JexlBuilder().features(f).create();
final JexlScript e = jexl.createScript(str);
final VarContext vars = new VarContext();
final JexlOptions opts = vars.getEngineOptions();
// so we can see the effect of features on options
opts.setSharedInstance(true);
final Script script = (Script) e;
final JexlFeatures features = script.getFeatures();
Assert.assertTrue(features.isLexical());
Assert.assertTrue(features.isLexicalShade());
final Object result = e.execute(vars);
Assert.assertEquals(42, result);
Assert.assertTrue(opts.isLexical());
Assert.assertTrue(opts.isLexicalShade());
}
use of org.apache.commons.jexl3.JexlOptions in project commons-jexl by apache.
the class Engine method evalOptions.
/**
* Obsolete version of options evaluation.
* @param opts the obsolete instance of options
* @return the newer class of options
*/
private JexlOptions evalOptions(final JexlEngine.Options opts) {
// This condition and block for compatibility between 3.1 and 3.2
final JexlOptions jexlo = options.copy();
final JexlEngine jexl = this;
jexlo.setCancellable(option(opts.isCancellable(), jexl.isCancellable()));
jexlo.setSilent(option(opts.isSilent(), jexl.isSilent()));
jexlo.setStrict(option(opts.isStrict(), jexl.isStrict()));
final JexlArithmetic jexla = jexl.getArithmetic();
jexlo.setStrictArithmetic(option(opts.isStrictArithmetic(), jexla.isStrict()));
jexlo.setMathContext(opts.getArithmeticMathContext());
jexlo.setMathScale(opts.getArithmeticMathScale());
return jexlo;
}
Aggregations