I’d like to leverage the scripting capability (provided by Java/Sling) in a CQ5 component. In essence, the component’s dialog will provide a TextArea field where the author can write a ECMA script which then will be evaluated by the component for that the result can be displayed on the page containing the component.
For that I can evaluate the scripted input by the author, I create a javax.script.ScriptEngineManager and try to get a ScriptEngineFactory from this manager instance. However, when I call ScriptEngineManager.getEngineFactories(), I get an empty list.
You should get the ScriptEngineManager from the OSGi Service Registry.
From a JSP, something like:
ScriptEngineManager manager = sling.getService(ScriptEngineManager.class);
From a DS component:
private ScriptEngineManager manager;
Works like a charm.
Thanks a lot.