Search in sources :

Example 1 with Pipeline

use of org.apache.sling.scripting.xproc.xpl.api.Pipeline in project sling by apache.

the class XProcScriptEngine method eval.

public Object eval(Reader reader, ScriptContext scriptContext) throws ScriptException {
    Bindings bindings = scriptContext.getBindings(ScriptContext.ENGINE_SCOPE);
    SlingScriptHelper helper = (SlingScriptHelper) bindings.get(SlingBindings.SLING);
    if (helper == null) {
        throw new ScriptException("SlingScriptHelper missing from bindings");
    }
    String scriptName = helper.getScript().getScriptResource().getPath();
    try {
        XplBuilder xplBuilder = new XplBuilder();
        Pipeline xpl = (Pipeline) xplBuilder.build(reader);
        xpl.getEnv().setSling(helper);
        xpl.eval();
    } catch (Throwable t) {
        log.error("Failure running XProc script.", t);
        final ScriptException se = new ScriptException("Failure running XProc script " + scriptName);
        se.initCause(t);
        throw se;
    }
    return null;
}
Also used : ScriptException(javax.script.ScriptException) SlingScriptHelper(org.apache.sling.api.scripting.SlingScriptHelper) Bindings(javax.script.Bindings) SlingBindings(org.apache.sling.api.scripting.SlingBindings) XplBuilder(org.apache.sling.scripting.xproc.xpl.XplBuilder) Pipeline(org.apache.sling.scripting.xproc.xpl.api.Pipeline)

Aggregations

Bindings (javax.script.Bindings)1 ScriptException (javax.script.ScriptException)1 SlingBindings (org.apache.sling.api.scripting.SlingBindings)1 SlingScriptHelper (org.apache.sling.api.scripting.SlingScriptHelper)1 XplBuilder (org.apache.sling.scripting.xproc.xpl.XplBuilder)1 Pipeline (org.apache.sling.scripting.xproc.xpl.api.Pipeline)1