use of org.apache.commons.jexl3.internal.Engine in project jmeter by apache.
the class Jexl3Function method getJexlEngine.
/**
* Get JexlEngine from ThreadLocal
* @return JexlEngine
*/
private static JexlEngine getJexlEngine() {
JexlEngine engine = threadLocalJexl.get();
if (engine == null) {
engine = new JexlBuilder().cache(512).silent(true).strict(true).debug(false).create();
threadLocalJexl.set(engine);
}
return engine;
}
use of org.apache.commons.jexl3.internal.Engine in project jxls by jxlsteam.
the class Issue166Test method installCustomFunctions_noThreadLocal.
private TransformerChecker installCustomFunctions_noThreadLocal(Context context) {
TransformerChecker tc = new TransformerChecker() {
@Override
public Transformer checkTransformer(Transformer transformer) {
TransformationConfig config = transformer.getTransformationConfig();
evaluator = new JexlExpressionEvaluatorNoThreadLocal();
config.setExpressionEvaluator(evaluator);
Map<String, Object> funcs = new HashMap<>();
funcs.put("cf", new JXLS2CustomFunctions(context));
JexlEngine engine = new JexlBuilder().namespaces(funcs).create();
evaluator.setJexlEngine(engine);
return transformer;
}
};
return tc;
}
use of org.apache.commons.jexl3.internal.Engine in project sling-org-apache-sling-pipes by apache.
the class PipeBindings method addScript.
/**
* add a script file to the engine
* @param resolver resolver with which the file should be read
* @param path path of the script file
*/
public void addScript(ResourceResolver resolver, String path) {
if (!allowAdditionalScripts) {
throw new SecurityException("additional scripts are not allowed per configuration");
}
InputStream is = null;
try {
if (path.startsWith("http")) {
try {
URL remoteScript = new URL(path);
is = remoteScript.openStream();
} catch (Exception e) {
log.error("unable to retrieve remote script", e);
}
} else if (path.startsWith("/")) {
Resource scriptResource = resolver.getResource(path);
if (scriptResource != null) {
is = scriptResource.adaptTo(InputStream.class);
}
}
if (is != null) {
try {
getEngine().eval(new InputStreamReader(is), scriptContext);
} catch (Exception e) {
log.error("Add script: unable to evaluate script {}", path, e);
}
}
} finally {
IOUtils.closeQuietly(is);
}
}
use of org.apache.commons.jexl3.internal.Engine in project commons-jexl by apache.
the class Issues100Test method test5115c.
@Test
public void test5115c() throws Exception {
final URL testUrl = new File(TESTA).toURI().toURL();
final JexlEngine jexl = new Engine();
final JexlScript s = jexl.createScript(testUrl);
}
use of org.apache.commons.jexl3.internal.Engine in project commons-jexl by apache.
the class Issues100Test method test105.
@Test
public void test105() throws Exception {
final JexlContext context = new MapContext();
final JexlExpression selectExp = new Engine().createExpression("[a.propA]");
context.set("a", new A105("a1", "p1"));
Object[] r = (Object[]) selectExp.evaluate(context);
Assert.assertEquals("p1", r[0]);
// selectExp = new Engine().createExpression("[a.propA]");
context.set("a", new A105("a2", "p2"));
r = (Object[]) selectExp.evaluate(context);
Assert.assertEquals("p2", r[0]);
}
Aggregations