sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject svn commit: r1732839 - in /sling/trunk/bundles/scripting/sightly: engine/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/frontend/ engine/src/main/java/org/apache/sling/scripting/sightly/impl/filter/ testing/ testing/src/main/provisioning/
Date Mon, 29 Feb 2016 09:38:54 GMT
Author: radu
Date: Mon Feb 29 09:38:53 2016
New Revision: 1732839

URL: http://svn.apache.org/viewvc?rev=1732839&view=rev
Log:
SLING-5568 - Sightly filters don't remove their specific options from the expression during
processing

* expression transformation in ExpressionWrapper uses now the filters processed expression
* all filters remove their options from the processed expression

Modified:
    sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/frontend/ExpressionWrapper.java
    sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/filter/FilterComponent.java
    sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/filter/FormatFilter.java
    sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/filter/I18nFilter.java
    sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/filter/JoinFilter.java
    sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/filter/URIManipulationFilter.java
    sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/filter/XSSFilter.java
    sling/trunk/bundles/scripting/sightly/testing/pom.xml
    sling/trunk/bundles/scripting/sightly/testing/src/main/provisioning/model.txt

Modified: sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/frontend/ExpressionWrapper.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/frontend/ExpressionWrapper.java?rev=1732839&r1=1732838&r2=1732839&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/frontend/ExpressionWrapper.java
(original)
+++ sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/frontend/ExpressionWrapper.java
Mon Feb 29 09:38:53 2016
@@ -56,8 +56,9 @@ public class ExpressionWrapper {
                 nodes.add(new StringConstant(fragment.getText()));
             } else {
                 Expression expression = fragment.getExpression();
-                nodes.add(adjustToContext(expression, markupContext, expressionContext).getRoot());
-                options.putAll(expression.getOptions());
+                Expression transformed = adjustToContext(expression, markupContext, expressionContext);
+                nodes.add(transformed.getRoot());
+                options.putAll(transformed.getOptions());
             }
         }
         ExpressionNode root = join(nodes);

Modified: sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/filter/FilterComponent.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/filter/FilterComponent.java?rev=1732839&r1=1732838&r2=1732839&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/filter/FilterComponent.java
(original)
+++ sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/filter/FilterComponent.java
Mon Feb 29 09:38:53 2016
@@ -16,13 +16,16 @@
  * specific language governing permissions and limitations
  * under the License.
  ******************************************************************************/
-
 package org.apache.sling.scripting.sightly.impl.filter;
 
 import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.Map;
 
 import org.apache.felix.scr.annotations.Activate;
 import org.apache.sling.commons.osgi.PropertiesUtil;
+import org.apache.sling.scripting.sightly.impl.compiler.expression.Expression;
+import org.apache.sling.scripting.sightly.impl.compiler.expression.ExpressionNode;
 import org.osgi.service.component.ComponentContext;
 
 /**
@@ -45,7 +48,7 @@ public abstract class FilterComponent im
         if (this.priority < o.priority()) {
             return -1;
         } else if (this.priority == o.priority()) {
-            return  0;
+            return 0;
         }
         return 1;
     }
@@ -55,4 +58,21 @@ public abstract class FilterComponent im
         Dictionary properties = componentContext.getProperties();
         priority = PropertiesUtil.toInteger(properties.get(PRIORITY), DEFAULT_PRIORITY);
     }
+
+    /**
+     * Collects the options passed in the {@code options} array into a new map while removing
them from the original expression.
+     * @param expression the expression providing the options to be processed
+     * @param options the options of interest for the {@link Filter}
+     * @return a map with the retrieved options; the map can be empty if none of the options
were found
+     */
+    protected Map<String, ExpressionNode> getFilterOptions(Expression expression, String...
options) {
+        Map<String, ExpressionNode> collector = new HashMap<String, ExpressionNode>();
+        for (String option : options) {
+            ExpressionNode optionNode = expression.removeOption(option);
+            if (optionNode != null) {
+                collector.put(option, optionNode);
+            }
+        }
+        return collector;
+    }
 }

Modified: sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/filter/FormatFilter.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/filter/FormatFilter.java?rev=1732839&r1=1732838&r2=1732839&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/filter/FormatFilter.java
(original)
+++ sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/filter/FormatFilter.java
Mon Feb 29 09:38:53 2016
@@ -31,7 +31,6 @@ import org.apache.sling.scripting.sightl
 import org.apache.sling.scripting.sightly.impl.compiler.expression.Expression;
 import org.apache.sling.scripting.sightly.impl.compiler.expression.ExpressionNode;
 import org.apache.sling.scripting.sightly.impl.compiler.expression.node.RuntimeCall;
-import org.apache.sling.scripting.sightly.impl.engine.runtime.RenderContextImpl;
 import org.apache.sling.scripting.sightly.impl.utils.RenderUtils;
 import org.apache.sling.scripting.sightly.render.RenderContext;
 
@@ -58,9 +57,8 @@ public class FormatFilter extends Filter
                 == ExpressionContext.PLUGIN_DATA_SLY_TEMPLATE || expressionContext == ExpressionContext.PLUGIN_DATA_SLY_CALL)
{
             return expression;
         }
-        ExpressionNode argNode = expression.getOption(FORMAT_OPTION);
-        ExpressionNode formattedNode = new RuntimeCall(FORMAT_FUNCTION, expression.getRoot(),
argNode);
-        return expression.withNode(formattedNode).withRemovedOptions(FORMAT_OPTION);
+        ExpressionNode translation = new RuntimeCall(FORMAT_FUNCTION, expression.getRoot(),
expression.removeOption(FORMAT_OPTION));
+        return expression.withNode(translation);
     }
 
     @Override

Modified: sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/filter/I18nFilter.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/filter/I18nFilter.java?rev=1732839&r1=1732838&r2=1732839&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/filter/I18nFilter.java
(original)
+++ sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/filter/I18nFilter.java
Mon Feb 29 09:38:53 2016
@@ -47,7 +47,9 @@ public class I18nFilter extends FilterCo
                 == ExpressionContext.PLUGIN_DATA_SLY_TEMPLATE || expressionContext == ExpressionContext.PLUGIN_DATA_SLY_CALL)
{
             return expression;
         }
-        ExpressionNode translation = new RuntimeCall(FUNCTION, expression.getRoot(), new
MapLiteral(expression.getOptions()));
-        return expression.withNode(translation).withRemovedOptions(HINT_OPTION, LOCALE_OPTION);
+        ExpressionNode translation = new RuntimeCall(FUNCTION, expression.getRoot(), new
MapLiteral(getFilterOptions(expression,
+                HINT_OPTION, LOCALE_OPTION)));
+        expression.removeOption(I18N_OPTION);
+        return expression.withNode(translation);
     }
 }

Modified: sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/filter/JoinFilter.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/filter/JoinFilter.java?rev=1732839&r1=1732838&r2=1732839&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/filter/JoinFilter.java
(original)
+++ sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/filter/JoinFilter.java
Mon Feb 29 09:38:53 2016
@@ -19,7 +19,6 @@
 
 package org.apache.sling.scripting.sightly.impl.filter;
 
-import java.util.Arrays;
 import java.util.Collection;
 import java.util.Iterator;
 
@@ -31,6 +30,7 @@ import org.apache.sling.scripting.sightl
 import org.apache.sling.scripting.sightly.extension.RuntimeExtension;
 import org.apache.sling.scripting.sightly.impl.compiler.expression.Expression;
 import org.apache.sling.scripting.sightly.impl.compiler.expression.ExpressionNode;
+import org.apache.sling.scripting.sightly.impl.compiler.expression.node.MapLiteral;
 import org.apache.sling.scripting.sightly.impl.compiler.expression.node.RuntimeCall;
 import org.apache.sling.scripting.sightly.impl.utils.RenderUtils;
 import org.apache.sling.scripting.sightly.render.RenderContext;
@@ -54,9 +54,8 @@ public class JoinFilter extends FilterCo
                 == ExpressionContext.PLUGIN_DATA_SLY_TEMPLATE || expressionContext == ExpressionContext.PLUGIN_DATA_SLY_CALL)
{
             return expression;
         }
-        ExpressionNode argumentNode = expression.getOption(JOIN_OPTION);
-        ExpressionNode joinResult = new RuntimeCall(JOIN_FUNCTION, expression.getRoot(),
argumentNode);
-        return expression.withNode(joinResult).withRemovedOptions(JOIN_OPTION);
+        ExpressionNode translation = new RuntimeCall(JOIN_FUNCTION, expression.getRoot(),
expression.removeOption(JOIN_OPTION));
+        return expression.withNode(translation);
     }
 
     @Override
@@ -66,11 +65,6 @@ public class JoinFilter extends FilterCo
         }
         Object joinArgument = arguments[0];
         Collection<?> collection = RenderUtils.toCollection(joinArgument);
-        if (joinArgument != null && collection.isEmpty()) {
-            collection = Arrays.asList(new Object[] {
-                joinArgument
-            });
-        }
         String joinString = RenderUtils.toString(arguments[1]);
         return join(collection, joinString);
     }

Modified: sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/filter/URIManipulationFilter.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/filter/URIManipulationFilter.java?rev=1732839&r1=1732838&r2=1732839&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/filter/URIManipulationFilter.java
(original)
+++ sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/filter/URIManipulationFilter.java
Mon Feb 29 09:38:53 2016
@@ -23,7 +23,6 @@ import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
-import java.util.HashMap;
 import java.util.Map;
 import java.util.Set;
 
@@ -39,7 +38,6 @@ import org.apache.sling.scripting.sightl
 import org.apache.sling.scripting.sightly.impl.compiler.expression.node.MapLiteral;
 import org.apache.sling.scripting.sightly.impl.compiler.expression.node.RuntimeCall;
 import org.apache.sling.scripting.sightly.impl.engine.extension.ExtensionUtils;
-import org.apache.sling.scripting.sightly.impl.engine.runtime.RenderContextImpl;
 import org.apache.sling.scripting.sightly.impl.utils.PathInfo;
 import org.apache.sling.scripting.sightly.impl.utils.RenderUtils;
 import org.apache.sling.scripting.sightly.render.RenderContext;
@@ -85,9 +83,9 @@ public class URIManipulationFilter exten
                 .PLUGIN_DATA_SLY_USE && expressionContext
                 != ExpressionContext.PLUGIN_DATA_SLY_TEMPLATE && expressionContext
!= ExpressionContext.PLUGIN_DATA_SLY_CALL &&
                 expressionContext != ExpressionContext.PLUGIN_DATA_SLY_RESOURCE) {
-            Map<String, ExpressionNode> uriOptions = new HashMap<String, ExpressionNode>();
-            collectOptions(expression, uriOptions, SCHEME, DOMAIN, PATH, APPEND_PATH, PREPEND_PATH,
SELECTORS, ADD_SELECTORS,
-                    REMOVE_SELECTORS, EXTENSION, SUFFIX, PREPEND_SUFFIX, APPEND_SUFFIX, FRAGMENT,
QUERY, ADD_QUERY, REMOVE_QUERY);
+            Map<String, ExpressionNode> uriOptions = getFilterOptions(expression, SCHEME,
DOMAIN, PATH, APPEND_PATH, PREPEND_PATH,
+                    SELECTORS, ADD_SELECTORS, REMOVE_SELECTORS, EXTENSION, SUFFIX, PREPEND_SUFFIX,
APPEND_SUFFIX, FRAGMENT, QUERY,
+                    ADD_QUERY, REMOVE_QUERY);
             if (uriOptions.size() > 0) {
                 ExpressionNode translation = new RuntimeCall(URI_MANIPULATION_FUNCTION, expression.getRoot(),
new MapLiteral(uriOptions));
                 return expression.withNode(translation);
@@ -213,15 +211,6 @@ public class URIManipulationFilter exten
         return sb.toString();
     }
 
-    private void collectOptions(Expression expression, Map<String, ExpressionNode>
collector, String... optionNames) {
-        for (String optionName : optionNames) {
-            if (expression.containsOption(optionName)) {
-                collector.put(optionName, expression.getOption(optionName));
-            }
-        }
-        expression.removeOptions(optionNames);
-    }
-
     private void uriAppender(StringBuilder stringBuilder, String option, Map<String, Object>
options, String defaultValue) {
         String value = (String) options.get(option);
         if (StringUtils.isNotEmpty(value)) {

Modified: sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/filter/XSSFilter.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/filter/XSSFilter.java?rev=1732839&r1=1732838&r2=1732839&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/filter/XSSFilter.java
(original)
+++ sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/filter/XSSFilter.java
Mon Feb 29 09:38:53 2016
@@ -18,8 +18,6 @@
  ******************************************************************************/
 package org.apache.sling.scripting.sightly.impl.filter;
 
-import java.util.Map;
-
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Property;
 import org.apache.felix.scr.annotations.Service;
@@ -44,11 +42,9 @@ public class XSSFilter extends FilterCom
                 || expressionContext == ExpressionContext.PLUGIN_DATA_SLY_CALL) {
             return expression;
         }
-        ExpressionNode node = expression.getRoot();
-        Map<String, ExpressionNode> options = expression.getOptions();
-        ExpressionNode context = options.get(Syntax.CONTEXT_OPTION);
+        ExpressionNode context = expression.removeOption(Syntax.CONTEXT_OPTION);
         if (context != null) {
-            return new Expression(new RuntimeCall(FUNCTION_NAME, node, context), options);
+            return expression.withNode(new RuntimeCall(FUNCTION_NAME, expression.getRoot(),
context));
         }
         return expression;
     }

Modified: sling/trunk/bundles/scripting/sightly/testing/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/testing/pom.xml?rev=1732839&r1=1732838&r2=1732839&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/sightly/testing/pom.xml (original)
+++ sling/trunk/bundles/scripting/sightly/testing/pom.xml Mon Feb 29 09:38:53 2016
@@ -149,7 +149,7 @@
             <plugin>
                 <groupId>org.apache.sling</groupId>
                 <artifactId>slingstart-maven-plugin</artifactId>
-                <version>1.2.0</version>
+                <version>1.4.2</version>
                 <extensions>true</extensions>
                 <executions>
                     <execution>
@@ -165,7 +165,7 @@
                         <server>
                             <port>${http.port}</port>
                             <controlPort>${sling.control.port}</controlPort>
-                            <runmode>oak</runmode>
+                            <runmode>oak_tar</runmode>
                             <contextPath>${http.base.path}</contextPath>
                             <debug>${debug.options}</debug>
                         </server>

Modified: sling/trunk/bundles/scripting/sightly/testing/src/main/provisioning/model.txt
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/testing/src/main/provisioning/model.txt?rev=1732839&r1=1732838&r2=1732839&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/sightly/testing/src/main/provisioning/model.txt (original)
+++ sling/trunk/bundles/scripting/sightly/testing/src/main/provisioning/model.txt Mon Feb
29 09:38:53 2016
@@ -19,8 +19,7 @@
 [feature name=sling]
 # Dependencies
 [artifacts]
-  org.apache.sling/org.apache.sling.launchpad/8/slingstart
-  org.apache.sling/org.apache.sling.scripting.javascript/2.0.29-SNAPSHOT
+  org.apache.sling/org.apache.sling.launchpad/9-SNAPSHOT/slingstart
   org.apache.sling/org.apache.sling.scripting.sightly/1.0.15-SNAPSHOT
   org.apache.sling/org.apache.sling.scripting.sightly.js.provider/1.0.11-SNAPSHOT
   org.apache.sling/org.apache.sling.scripting.sightly.models.provider/1.0.1-SNAPSHOT



Mime
View raw message