sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From romb...@apache.org
Subject [sling-org-apache-sling-scripting-java] 28/41: Store script resource resolver in script context, return script resource with request resource resolver.
Date Tue, 07 Nov 2017 10:04:02 GMT
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.scripting.java-1.0.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-java.git

commit 16c4505d5ca470f69cdb56e55a60ff09a0527b9d
Author: Carsten Ziegeler <cziegeler@apache.org>
AuthorDate: Fri Jul 17 11:48:35 2009 +0000

    Store script resource resolver in script context, return script resource with request
resource resolver.
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/contrib/scripting/java@795055
13f79535-47bb-0310-9956-ffa450edef68
---
 .../scripting/java/JavaScriptEngineFactory.java    | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/src/main/java/org/apache/sling/scripting/java/JavaScriptEngineFactory.java b/src/main/java/org/apache/sling/scripting/java/JavaScriptEngineFactory.java
index c0f6e38..698937c 100644
--- a/src/main/java/org/apache/sling/scripting/java/JavaScriptEngineFactory.java
+++ b/src/main/java/org/apache/sling/scripting/java/JavaScriptEngineFactory.java
@@ -30,8 +30,10 @@ import javax.servlet.ServletContext;
 import org.apache.sling.api.SlingException;
 import org.apache.sling.api.SlingIOException;
 import org.apache.sling.api.SlingServletException;
+import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.api.scripting.SlingBindings;
 import org.apache.sling.api.scripting.SlingScript;
+import org.apache.sling.api.scripting.SlingScriptConstants;
 import org.apache.sling.api.scripting.SlingScriptHelper;
 import org.apache.sling.commons.classloader.ClassLoaderWriter;
 import org.apache.sling.commons.classloader.DynamicClassLoaderManager;
@@ -156,16 +158,24 @@ public class JavaScriptEngineFactory extends AbstractScriptEngineFactory
{
 
     /**
      * Call the servlet.
-     * @param scriptHelper
+     * @param binding The bindings for the script invocation
+     * @param scriptHelper The script helper.
+     * @param context The script context.
      * @throws SlingServletException
      * @throws SlingIOException
      */
     @SuppressWarnings("unchecked")
-    private void callServlet(Bindings bindings, SlingScriptHelper scriptHelper) {
-
-        ioProvider.setRequestResourceResolver(scriptHelper.getScript().getScriptResource().getResourceResolver());
+    private void callServlet(final Bindings bindings,
+                             final SlingScriptHelper scriptHelper,
+                             final ScriptContext context) {
+        ResourceResolver resolver = (ResourceResolver) context.getAttribute(SlingScriptConstants.ATTR_SCRIPT_RESOURCE_RESOLVER,
+                ScriptContext.ENGINE_SCOPE);
+        if ( resolver == null ) {
+            resolver = scriptHelper.getScript().getScriptResource().getResourceResolver();
+        }
+        ioProvider.setRequestResourceResolver(resolver);
         try {
-            ServletWrapper servlet = getWrapperAdapter(scriptHelper);
+            final ServletWrapper servlet = getWrapperAdapter(scriptHelper);
             // create a SlingBindings object
             final SlingBindings slingBindings = new SlingBindings();
             slingBindings.putAll(bindings);
@@ -251,7 +261,7 @@ public class JavaScriptEngineFactory extends AbstractScriptEngineFactory
{
             final Bindings props = context.getBindings(ScriptContext.ENGINE_SCOPE);
             final SlingScriptHelper scriptHelper = (SlingScriptHelper) props.get(SLING);
             if (scriptHelper != null) {
-                ((JavaScriptEngineFactory)this.getFactory()).callServlet(props, scriptHelper);
+                ((JavaScriptEngineFactory)this.getFactory()).callServlet(props, scriptHelper,
context);
             }
             return null;
         }

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <commits@sling.apache.org>.

Mime
View raw message