use of org.renjin.script.RenjinScriptEngine in project structr by structr.
the class Scripting method evaluateScript.
// ----- private methods -----
private static Object evaluateScript(final ActionContext actionContext, final GraphObject entity, final String engineName, final String script) throws FrameworkException {
final ScriptEngineManager manager = new ScriptEngineManager();
final ScriptEngine engine = manager.getEngineByName(engineName);
if (engine == null) {
throw new RuntimeException(engineName + " script engine could not be initialized. Check class path.");
}
final ScriptContext scriptContext = engine.getContext();
final Bindings bindings = new StructrScriptBindings(actionContext, entity);
if (!(engine instanceof RenjinScriptEngine)) {
scriptContext.setBindings(bindings, ScriptContext.GLOBAL_SCOPE);
}
StringWriter output = new StringWriter();
scriptContext.setWriter(output);
try {
engine.eval(script);
Object extractedValue = output.toString();
return extractedValue;
} catch (final ScriptException e) {
logger.error("Error while processing {} script: {}", engineName, script, e);
}
return null;
}
Aggregations