Search in sources :

Example 1 with NashornScriptEngineFactory

use of jdk.nashorn.api.scripting.NashornScriptEngineFactory in project sling by apache.

the class ScriptSandboxServiceImpl method activate.

/**
     *
     * @param context
     */
@Activate
protected void activate(ComponentContext context) {
    try {
        this.slingBabelSource = "//@sourceURL=" + getClass().getCanonicalName() + "\n load( { name : \"" + getClass().getCanonicalName() + "\", script: \"" + StringEscapeUtils.escapeEcmaScript(new String(IOUtils.toByteArray(context.getBundleContext().getBundle().getEntry(this.SLING_BABEL_SOURCE_CODE).openStream()))) + "\"} )";
    } catch (Exception ex) {
        log.error("failed to load babel source", ex);
    }
    String options = "var config = { " + "    presets: [\"es2015\"], " + "    compact: 'true'," + "    plugins: [[\"transform-react-jsx\", { pragma : \"SlingEsx.createElement\"}]] " + //"    \"plugins\": [\"SlingSandbox, [\"transform-react-jsx\", { \"pragma\" : \"SlingEsx.createElement\"}]] \n" +        
    "    }";
    NashornScriptEngineFactory factory = new NashornScriptEngineFactory();
    this.scriptEngine = factory.getScriptEngine();
    try {
        log.info("trying to load babel into the system");
        this.scriptEngine.eval(options);
        this.babelOptions = this.scriptEngine.get("config");
        scriptEngine.eval(slingBabelSource);
        this.babel = this.scriptEngine.get("SlingBabel");
        log.info("Babel loaded");
    } catch (ScriptException ex) {
        log.error("coudlnt load babel options", ex);
    }
}
Also used : NashornScriptEngineFactory(jdk.nashorn.api.scripting.NashornScriptEngineFactory) ScriptException(javax.script.ScriptException) IOException(java.io.IOException) ScriptException(javax.script.ScriptException) Activate(org.apache.felix.scr.annotations.Activate)

Example 2 with NashornScriptEngineFactory

use of jdk.nashorn.api.scripting.NashornScriptEngineFactory in project sling by apache.

the class EsxScriptEngineFactory method activate.

@Activate
protected void activate(ComponentContext context) {
    log.debug("Starting Engine");
    // create one script engine
    NashornScriptEngineFactory factory = new NashornScriptEngineFactory();
    this.nashornScriptEngine = factory.getScriptEngine();
    log.debug("Engine started");
}
Also used : NashornScriptEngineFactory(jdk.nashorn.api.scripting.NashornScriptEngineFactory) Activate(org.apache.felix.scr.annotations.Activate)

Aggregations

NashornScriptEngineFactory (jdk.nashorn.api.scripting.NashornScriptEngineFactory)2 Activate (org.apache.felix.scr.annotations.Activate)2 IOException (java.io.IOException)1 ScriptException (javax.script.ScriptException)1