You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ra...@apache.org on 2018/03/19 12:36:28 UTC

[sling-org-apache-sling-scripting-sightly] branch bugfix/support-selectors-with-comma updated (b40fbe9 -> 7353d60)

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

radu pushed a change to branch bugfix/support-selectors-with-comma
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly.git.


    omit b40fbe9  SLING-7516 support comma in selectors for data-sly-resource
     add afd82b9  SLING-7523 - Java Use object with trailing whitespace in the package declaration freezes the SightlyJavaCompilerService
     add ad3c9b1  SLING-7523 - Java Use object with trailing whitespace in the package declaration freezes the SightlyJavaCompilerService
     add cb6ca70  [maven-release-plugin] prepare release org.apache.sling.scripting.sightly-1.0.50-1.3.1
     add ddb5ce6  [maven-release-plugin] prepare for next development iteration
     add e97d983  SLING-7523 - Java Use object with trailing whitespace in the package declaration freezes the SightlyJavaCompilerService
     add 72bebd0  [maven-release-plugin] prepare release org.apache.sling.scripting.sightly-1.0.52-1.3.1
     add 3b50f91  [maven-release-plugin] prepare for next development iteration
     new 46739cf  SLING-7516 support comma in selectors for data-sly-resource
     new 7353d60  SLING-7516 - ResourceRuntimeExtension: Selectors containing a comma are not treated correctly

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (b40fbe9)
            \
             N -- N -- N   refs/heads/bugfix/support-selectors-with-comma (7353d60)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 pom.xml                                            |   6 +-
 .../impl/engine/SightlyJavaCompilerService.java    |   4 +-
 .../engine/extension/ResourceRuntimeExtension.java |  13 +-
 .../impl/engine/extension/use/JavaUseProvider.java |   4 +-
 .../scripting/sightly/impl/utils/Patterns.java     |  45 +++++++
 .../scripting/sightly/impl/utils/PatternsTest.java | 146 +++++++++++++++++++++
 6 files changed, 205 insertions(+), 13 deletions(-)
 create mode 100644 src/main/java/org/apache/sling/scripting/sightly/impl/utils/Patterns.java
 create mode 100644 src/test/java/org/apache/sling/scripting/sightly/impl/utils/PatternsTest.java

-- 
To stop receiving notification emails like this one, please contact
radu@apache.org.

[sling-org-apache-sling-scripting-sightly] 02/02: SLING-7516 - ResourceRuntimeExtension: Selectors containing a comma are not treated correctly

Posted by ra...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

radu pushed a commit to branch bugfix/support-selectors-with-comma
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly.git

commit 7353d6025bc08b0c20006b8838a87651b434fe21
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Mon Mar 19 13:35:44 2018 +0100

    SLING-7516 - ResourceRuntimeExtension: Selectors containing a comma are not treated correctly
    
    * corrected RequestDispatcherOptions overrides
---
 .../impl/engine/extension/ResourceRuntimeExtension.java     | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/ResourceRuntimeExtension.java b/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/ResourceRuntimeExtension.java
index c46365b..924f9ea 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/ResourceRuntimeExtension.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/ResourceRuntimeExtension.java
@@ -119,19 +119,19 @@ public class ResourceRuntimeExtension implements RuntimeExtension {
             selectors.addAll(Arrays.asList(request.getRequestPathInfo().getSelectors()));
         }
         requestDispatcherOptions.setAddSelectors(getSelectorString(selectors));
-        requestDispatcherOptions.setReplaceSelectors(" ");
+        requestDispatcherOptions.setReplaceSelectors("");
         if (options.containsKey(OPTION_SELECTORS)) {
             Object selectorsObject = getAndRemoveOption(options, OPTION_SELECTORS);
             selectors.clear();
             addSelectors(selectors, selectorsObject, runtimeObjectModel);
             requestDispatcherOptions.setAddSelectors(getSelectorString(selectors));
-            requestDispatcherOptions.setReplaceSelectors(" ");
+            requestDispatcherOptions.setReplaceSelectors("");
         }
         if (options.containsKey(OPTION_ADD_SELECTORS)) {
             Object selectorsObject = getAndRemoveOption(options, OPTION_ADD_SELECTORS);
             addSelectors(selectors, selectorsObject, runtimeObjectModel);
             requestDispatcherOptions.setAddSelectors(getSelectorString(selectors));
-            requestDispatcherOptions.setReplaceSelectors(" ");
+            requestDispatcherOptions.setReplaceSelectors("");
         }
         if (options.containsKey(OPTION_REMOVE_SELECTORS)) {
             Object selectorsObject = getAndRemoveOption(options, OPTION_REMOVE_SELECTORS);
@@ -153,10 +153,10 @@ public class ResourceRuntimeExtension implements RuntimeExtension {
             }
             String selectorString = getSelectorString(selectors);
             if (StringUtils.isEmpty(selectorString)) {
-                requestDispatcherOptions.setReplaceSelectors(" ");
+                requestDispatcherOptions.setReplaceSelectors("");
             } else {
                 requestDispatcherOptions.setAddSelectors(getSelectorString(selectors));
-                requestDispatcherOptions.setReplaceSelectors(" ");
+                requestDispatcherOptions.setReplaceSelectors("");
             }
         }
         return requestDispatcherOptions;
@@ -228,7 +228,8 @@ public class ResourceRuntimeExtension implements RuntimeExtension {
                 i++;
             }
         }
-        return sb.toString();
+        String selectorString = sb.toString();
+        return StringUtils.isNotEmpty(selectorString) ? selectorString : null;
     }
 
     private void includeResource(final Bindings bindings, PrintWriter out, String path, RequestDispatcherOptions requestDispatcherOptions, String resourceType) {

-- 
To stop receiving notification emails like this one, please contact
radu@apache.org.

[sling-org-apache-sling-scripting-sightly] 01/02: SLING-7516 support comma in selectors for data-sly-resource

Posted by ra...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

radu pushed a commit to branch bugfix/support-selectors-with-comma
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly.git

commit 46739cfcfdcd02f51df8dd26a3b418570459cf9a
Author: Konrad Windszus <kw...@apache.org>
AuthorDate: Mon Feb 26 18:58:54 2018 +0100

    SLING-7516 support comma in selectors for data-sly-resource
---
 .../engine/extension/ResourceRuntimeExtension.java | 77 +++++++---------------
 1 file changed, 25 insertions(+), 52 deletions(-)

diff --git a/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/ResourceRuntimeExtension.java b/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/ResourceRuntimeExtension.java
index b40544c..c46365b 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/ResourceRuntimeExtension.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/ResourceRuntimeExtension.java
@@ -82,9 +82,8 @@ public class ResourceRuntimeExtension implements RuntimeExtension {
         PrintWriter printWriter = new PrintWriter(writer);
         if (pathObj instanceof Resource) {
             Resource includedResource = (Resource) pathObj;
-            Map<String, String> dispatcherOptionsMap = handleSelectors(request, new LinkedHashSet<String>(), opts, runtimeObjectModel);
-            String dispatcherOptions = createDispatcherOptions(dispatcherOptionsMap);
-            includeResource(bindings, printWriter, includedResource, dispatcherOptions, resourceType);
+            RequestDispatcherOptions requestDispatcherOptions = handleSelectors(request, new LinkedHashSet<String>(), opts, runtimeObjectModel);
+            includeResource(bindings, printWriter, includedResource, requestDispatcherOptions, resourceType);
         } else {
             String includePath = runtimeObjectModel.toString(pathObj);
             // build path completely
@@ -94,48 +93,45 @@ public class ResourceRuntimeExtension implements RuntimeExtension {
                 Resource includedResource = request.getResourceResolver().getResource(includePath);
                 PathInfo pathInfo;
                 if (includedResource != null) {
-                    Map<String, String> dispatcherOptionsMap =
+                    RequestDispatcherOptions requestDispatcherOptions =
                             handleSelectors(request, new LinkedHashSet<String>(), opts, runtimeObjectModel);
-                    String dispatcherOptions = createDispatcherOptions(dispatcherOptionsMap);
-                    includeResource(bindings, printWriter, includedResource, dispatcherOptions, resourceType);
+                    includeResource(bindings, printWriter, includedResource, requestDispatcherOptions, resourceType);
                 } else {
                     // analyse path and decompose potential selectors from the path
                     pathInfo = new PathInfo(includePath);
-                    Map<String, String> dispatcherOptionsMap = handleSelectors(request, pathInfo.selectors, opts, runtimeObjectModel);
-                    String dispatcherOptions = createDispatcherOptions(dispatcherOptionsMap);
-                    includeResource(bindings, printWriter, pathInfo.path, dispatcherOptions, resourceType);
+                    RequestDispatcherOptions requestDispatcherOptions = handleSelectors(request, pathInfo.selectors, opts, runtimeObjectModel);
+                    includeResource(bindings, printWriter, pathInfo.path, requestDispatcherOptions, resourceType);
                 }
             } else {
                 // use the current resource
-                Map<String, String> dispatcherOptionsMap = handleSelectors(request, new LinkedHashSet<String>(), opts, runtimeObjectModel);
-                String dispatcherOptions = createDispatcherOptions(dispatcherOptionsMap);
-                includeResource(bindings, printWriter, request.getResource(), dispatcherOptions, resourceType);
+                RequestDispatcherOptions requestDispatcherOptions = handleSelectors(request, new LinkedHashSet<String>(), opts, runtimeObjectModel);
+                includeResource(bindings, printWriter, request.getResource(), requestDispatcherOptions, resourceType);
             }
         }
         ExtensionUtils.setRequestAttributes(request, originalAttributes);
         return writer.toString();
     }
 
-    private Map<String, String> handleSelectors(SlingHttpServletRequest request, Set<String> selectors, Map<String, Object> options,
+    private RequestDispatcherOptions handleSelectors(SlingHttpServletRequest request, Set<String> selectors, Map<String, Object> options,
                                                 RuntimeObjectModel runtimeObjectModel) {
+        RequestDispatcherOptions requestDispatcherOptions = new RequestDispatcherOptions();
         if (selectors.isEmpty()) {
             selectors.addAll(Arrays.asList(request.getRequestPathInfo().getSelectors()));
         }
-        Map<String, String> dispatcherOptionsMap = new HashMap<>();
-        dispatcherOptionsMap.put(OPTION_ADD_SELECTORS, getSelectorString(selectors));
-        dispatcherOptionsMap.put(OPTION_REPLACE_SELECTORS, " ");
+        requestDispatcherOptions.setAddSelectors(getSelectorString(selectors));
+        requestDispatcherOptions.setReplaceSelectors(" ");
         if (options.containsKey(OPTION_SELECTORS)) {
             Object selectorsObject = getAndRemoveOption(options, OPTION_SELECTORS);
             selectors.clear();
             addSelectors(selectors, selectorsObject, runtimeObjectModel);
-            dispatcherOptionsMap.put(OPTION_ADD_SELECTORS, getSelectorString(selectors));
-            dispatcherOptionsMap.put(OPTION_REPLACE_SELECTORS, " ");
+            requestDispatcherOptions.setAddSelectors(getSelectorString(selectors));
+            requestDispatcherOptions.setReplaceSelectors(" ");
         }
         if (options.containsKey(OPTION_ADD_SELECTORS)) {
             Object selectorsObject = getAndRemoveOption(options, OPTION_ADD_SELECTORS);
             addSelectors(selectors, selectorsObject, runtimeObjectModel);
-            dispatcherOptionsMap.put(OPTION_ADD_SELECTORS, getSelectorString(selectors));
-            dispatcherOptionsMap.put(OPTION_REPLACE_SELECTORS, " ");
+            requestDispatcherOptions.setAddSelectors(getSelectorString(selectors));
+            requestDispatcherOptions.setReplaceSelectors(" ");
         }
         if (options.containsKey(OPTION_REMOVE_SELECTORS)) {
             Object selectorsObject = getAndRemoveOption(options, OPTION_REMOVE_SELECTORS);
@@ -157,13 +153,13 @@ public class ResourceRuntimeExtension implements RuntimeExtension {
             }
             String selectorString = getSelectorString(selectors);
             if (StringUtils.isEmpty(selectorString)) {
-                dispatcherOptionsMap.put(OPTION_REPLACE_SELECTORS, " ");
+                requestDispatcherOptions.setReplaceSelectors(" ");
             } else {
-                dispatcherOptionsMap.put(OPTION_ADD_SELECTORS, getSelectorString(selectors));
-                dispatcherOptionsMap.put(OPTION_REPLACE_SELECTORS, " ");
+                requestDispatcherOptions.setAddSelectors(getSelectorString(selectors));
+                requestDispatcherOptions.setReplaceSelectors(" ");
             }
         }
-        return dispatcherOptionsMap;
+        return requestDispatcherOptions;
     }
 
     private void addSelectors(Set<String> selectors, Object selectorsObject, RuntimeObjectModel runtimeObjectModel) {
@@ -211,28 +207,6 @@ public class ResourceRuntimeExtension implements RuntimeExtension {
         return ResourceUtil.normalize(finalPath);
     }
 
-    private String createDispatcherOptions(Map<String, String> options) {
-        if (options == null || options.isEmpty()) {
-            return null;
-        }
-        StringBuilder buffer = new StringBuilder();
-        boolean hasPreceding = false;
-        for (Map.Entry<String, String> option : options.entrySet()) {
-            if (hasPreceding) {
-                buffer.append(", ");
-            }
-            String key = option.getKey();
-            buffer.append(key).append("=");
-            String strVal = option.getValue();
-            if (strVal == null) {
-                strVal = "";
-            }
-            buffer.append(strVal);
-            hasPreceding = true;
-        }
-        return buffer.toString();
-    }
-
     private String getOption(String option, Map<String, Object> options, String defaultValue) {
         if (options.containsKey(option)) {
             return (String) options.get(option);
@@ -257,7 +231,7 @@ public class ResourceRuntimeExtension implements RuntimeExtension {
         return sb.toString();
     }
 
-    private void includeResource(final Bindings bindings, PrintWriter out, String path, String dispatcherOptions, String resourceType) {
+    private void includeResource(final Bindings bindings, PrintWriter out, String path, RequestDispatcherOptions requestDispatcherOptions, String resourceType) {
         if (StringUtils.isEmpty(path)) {
             throw new SightlyException("Resource path cannot be empty");
         } else {
@@ -266,21 +240,20 @@ public class ResourceRuntimeExtension implements RuntimeExtension {
             if (ResourceUtil.isNonExistingResource(includeRes)) {
                 includeRes = new SyntheticResource(request.getResourceResolver(), path, resourceType);
             }
-            includeResource(bindings, out, includeRes, dispatcherOptions, resourceType);
+            includeResource(bindings, out, includeRes, requestDispatcherOptions, resourceType);
         }
     }
 
-    private void includeResource(final Bindings bindings, PrintWriter out, Resource includeRes, String dispatcherOptions, String resourceType) {
+    private void includeResource(final Bindings bindings, PrintWriter out, Resource includeRes, RequestDispatcherOptions requestDispatcherOptions, String resourceType) {
         if (includeRes == null) {
             throw new SightlyException("Resource cannot be null");
         } else {
             SlingHttpServletResponse customResponse = new PrintWriterResponseWrapper(out, BindingsUtils.getResponse(bindings));
             SlingHttpServletRequest request = BindingsUtils.getRequest(bindings);
-            RequestDispatcherOptions opts = new RequestDispatcherOptions(dispatcherOptions);
             if (StringUtils.isNotEmpty(resourceType)) {
-                opts.setForceResourceType(resourceType);
+                requestDispatcherOptions.setForceResourceType(resourceType);
             }
-            RequestDispatcher dispatcher = request.getRequestDispatcher(includeRes, opts);
+            RequestDispatcher dispatcher = request.getRequestDispatcher(includeRes, requestDispatcherOptions);
             try {
                 if (dispatcher != null) {
                     dispatcher.include(request, customResponse);

-- 
To stop receiving notification emails like this one, please contact
radu@apache.org.