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);
}
}
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");
}
Aggregations