You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 10:11:44 UTC

[sling-org-apache-sling-scripting-sightly-js-provider] 03/11: SLING-5334 - Improve Sightly script resolution for components using inheritance

This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.scripting.sightly.js.provider-1.0.12
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-js-provider.git

commit 9089b5b55bec37ece3e67d66f058617a8d3e54e9
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Fri Nov 27 11:30:49 2015 +0000

    SLING-5334 - Improve Sightly script resolution for components using inheritance
    
    * implemented script resolution fallback to take into account the current executing
    script's path besides component inheritance
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/scripting/sightly/js-use-provider@1716841 13f79535-47bb-0310-9956-ffa450edef68
---
 .../scripting/sightly/js/impl/JsUseProvider.java   |  5 +---
 .../sling/scripting/sightly/js/impl/Utils.java     | 34 ++++++++++------------
 2 files changed, 17 insertions(+), 22 deletions(-)

diff --git a/src/main/java/org/apache/sling/scripting/sightly/js/impl/JsUseProvider.java b/src/main/java/org/apache/sling/scripting/sightly/js/impl/JsUseProvider.java
index 2e11221..99ee0fa 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/js/impl/JsUseProvider.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/js/impl/JsUseProvider.java
@@ -85,10 +85,7 @@ public class JsUseProvider implements UseProvider {
         try {
             environment = new JsEnvironment(jsEngine);
             environment.initialize();
-            String callerPath = scriptHelper.getScript().getScriptResource().getPath();
-            ResourceResolver adminResolver = renderContext.getScriptResourceResolver();
-            Resource caller = adminResolver.getResource(callerPath);
-            Resource scriptResource = Utils.getScriptResource(caller, identifier, globalBindings);
+            Resource scriptResource = Utils.getScriptResource(scriptHelper.getScript().getScriptResource(), identifier, globalBindings);
             globalBindings.put(ScriptEngine.FILENAME, scriptResource.getPath());
             proxyAsyncScriptableFactory.registerProxies(globalBindings);
             AsyncContainer asyncContainer = environment.runResource(scriptResource, globalBindings, arguments);
diff --git a/src/main/java/org/apache/sling/scripting/sightly/js/impl/Utils.java b/src/main/java/org/apache/sling/scripting/sightly/js/impl/Utils.java
index 48d06e0..41a775c 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/js/impl/Utils.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/js/impl/Utils.java
@@ -1,20 +1,18 @@
 /*******************************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
  *
- *   http://www.apache.org/licenses/LICENSE-2.0
+ *     http://www.apache.org/licenses/LICENSE-2.0
  *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
  ******************************************************************************/
 package org.apache.sling.scripting.sightly.js.impl;
 
@@ -51,9 +49,9 @@ public class Utils {
 
     public static Resource getScriptResource(Resource caller, String path, Bindings bindings) {
         Resource scriptResource = caller.getChild(path);
-        Resource componentCaller = ResourceResolution.getResourceForRequest(caller.getResourceResolver(), (SlingHttpServletRequest) bindings.get
-            (SlingBindings.REQUEST));
         if (scriptResource == null) {
+            Resource componentCaller = ResourceResolution
+                    .getResourceForRequest(caller.getResourceResolver(), (SlingHttpServletRequest) bindings.get(SlingBindings.REQUEST));
             if (isResourceOverlay(caller, componentCaller)) {
                 scriptResource = ResourceResolution.getResourceFromSearchPath(componentCaller, path);
             } else {
@@ -67,8 +65,8 @@ public class Utils {
     }
 
     /**
-     * Using the inheritance chain created with the help of {@code sling:resourceSuperType} this method checks if {@code resourceB}
-     * inherits from {@code resourceA}. In case {@code resourceA} is a {@code nt:file}, its parent will be used for the inheritance check.
+     * Using the inheritance chain created with the help of {@code sling:resourceSuperType} this method checks if {@code resourceB} inherits
+     * from {@code resourceA}. In case {@code resourceA} is a {@code nt:file}, its parent will be used for the inheritance check.
      *
      * @param resourceA the base resource
      * @param resourceB the potentially overlaid resource

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