Search in sources :

Example 1 with Engine

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;
}
Also used : JexlEngine(org.apache.commons.jexl3.JexlEngine) JexlBuilder(org.apache.commons.jexl3.JexlBuilder)

Example 2 with 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;
}
Also used : Transformer(org.jxls.transform.Transformer) JexlEngine(org.apache.commons.jexl3.JexlEngine) HashMap(java.util.HashMap) JexlExpressionEvaluatorNoThreadLocal(org.jxls.expression.JexlExpressionEvaluatorNoThreadLocal) TransformationConfig(org.jxls.transform.TransformationConfig) JexlBuilder(org.apache.commons.jexl3.JexlBuilder) TransformerChecker(org.jxls.JxlsTester.TransformerChecker)

Example 3 with Engine

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);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) Resource(org.apache.sling.api.resource.Resource) URL(java.net.URL) JexlException(org.apache.commons.jexl3.JexlException) ScriptException(javax.script.ScriptException)

Example 4 with Engine

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);
}
Also used : File(java.io.File) URL(java.net.URL) Engine(org.apache.commons.jexl3.internal.Engine) Test(org.junit.Test)

Example 5 with Engine

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]);
}
Also used : Engine(org.apache.commons.jexl3.internal.Engine) Test(org.junit.Test)

Aggregations

JexlEngine (org.apache.commons.jexl3.JexlEngine)8 JexlException (org.apache.commons.jexl3.JexlException)5 Engine (org.apache.commons.jexl3.internal.Engine)5 Test (org.junit.Test)5 JexlBuilder (org.apache.commons.jexl3.JexlBuilder)4 JexlScript (org.apache.commons.jexl3.JexlScript)3 JxltEngine (org.apache.commons.jexl3.JxltEngine)3 BigDecimal (java.math.BigDecimal)2 URL (java.net.URL)2 HashMap (java.util.HashMap)2 JexlOptions (org.apache.commons.jexl3.JexlOptions)2 TransformerChecker (org.jxls.JxlsTester.TransformerChecker)2 TransformationConfig (org.jxls.transform.TransformationConfig)2 Transformer (org.jxls.transform.Transformer)2 File (java.io.File)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 Map (java.util.Map)1 Callable (java.util.concurrent.Callable)1 CancellationException (java.util.concurrent.CancellationException)1