Search in sources :

Example 1 with JsEnvironment

use of org.apache.sling.scripting.sightly.js.impl.JsEnvironment in project sling by apache.

the class SlyBindingsValuesProvider method ensureFactoriesLoaded.

private void ensureFactoriesLoaded(Bindings bindings) {
    JsEnvironment jsEnvironment = null;
    ResourceResolver resolver = null;
    try {
        ScriptEngine scriptEngine = obtainEngine();
        if (scriptEngine == null) {
            return;
        }
        jsEnvironment = new JsEnvironment(scriptEngine);
        jsEnvironment.initialize();
        resolver = rrf.getServiceResourceResolver(null);
        factories = new HashMap<>(scriptPaths.size());
        for (Map.Entry<String, String> entry : scriptPaths.entrySet()) {
            factories.put(entry.getKey(), loadFactory(resolver, jsEnvironment, entry.getValue(), bindings));
        }
        qScript = loadQScript(resolver);
    } catch (LoginException e) {
        LOGGER.error("Cannot load HTL Use-API factories.", e);
    } finally {
        if (jsEnvironment != null) {
            jsEnvironment.cleanup();
        }
        if (resolver != null) {
            resolver.close();
        }
    }
}
Also used : JsEnvironment(org.apache.sling.scripting.sightly.js.impl.JsEnvironment) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) LoginException(org.apache.sling.api.resource.LoginException) HashMap(java.util.HashMap) Map(java.util.Map) ScriptEngine(javax.script.ScriptEngine)

Aggregations

HashMap (java.util.HashMap)1 Map (java.util.Map)1 ScriptEngine (javax.script.ScriptEngine)1 LoginException (org.apache.sling.api.resource.LoginException)1 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)1 JsEnvironment (org.apache.sling.scripting.sightly.js.impl.JsEnvironment)1