incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jus...@apache.org
Subject svn commit: r1095567 - in /sling/trunk/bundles/servlets/resolver: ./ src/main/java/org/apache/sling/servlets/resolver/internal/ src/main/java/org/apache/sling/servlets/resolver/internal/helper/ src/main/resources/OSGI-INF/metatype/ src/test/java/org/ap...
Date Wed, 20 Apr 2011 23:59:30 GMT
Author: justin
Date: Wed Apr 20 23:59:29 2011
New Revision: 1095567

URL: http://svn.apache.org/viewvc?rev=1095567&view=rev
Log:
SLING-2054 - renaming isHtml to isDefaultExtension and allowing there to be a configurable
list of default extensions, which defaults to html

Modified:
    sling/trunk/bundles/servlets/resolver/pom.xml
    sling/trunk/bundles/servlets/resolver/src/main/java/org/apache/sling/servlets/resolver/internal/SlingServletResolver.java
    sling/trunk/bundles/servlets/resolver/src/main/java/org/apache/sling/servlets/resolver/internal/helper/ResourceCollector.java
    sling/trunk/bundles/servlets/resolver/src/main/resources/OSGI-INF/metatype/metatype.properties
    sling/trunk/bundles/servlets/resolver/src/test/java/org/apache/sling/servlets/resolver/internal/helper/ResourceCollectorTest.java
    sling/trunk/bundles/servlets/resolver/src/test/java/org/apache/sling/servlets/resolver/internal/helper/ScriptSelectionTest.java

Modified: sling/trunk/bundles/servlets/resolver/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/resolver/pom.xml?rev=1095567&r1=1095566&r2=1095567&view=diff
==============================================================================
--- sling/trunk/bundles/servlets/resolver/pom.xml (original)
+++ sling/trunk/bundles/servlets/resolver/pom.xml Wed Apr 20 23:59:29 2011
@@ -105,6 +105,12 @@
             <scope>provided</scope>
         </dependency>
         <dependency>
+            <groupId>commons-lang</groupId>
+            <artifactId>commons-lang</artifactId>
+            <version>2.4</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
             <groupId>org.osgi</groupId>
             <artifactId>org.osgi.core</artifactId>
         </dependency>

Modified: sling/trunk/bundles/servlets/resolver/src/main/java/org/apache/sling/servlets/resolver/internal/SlingServletResolver.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/resolver/src/main/java/org/apache/sling/servlets/resolver/internal/SlingServletResolver.java?rev=1095567&r1=1095566&r2=1095567&view=diff
==============================================================================
--- sling/trunk/bundles/servlets/resolver/src/main/java/org/apache/sling/servlets/resolver/internal/SlingServletResolver.java
(original)
+++ sling/trunk/bundles/servlets/resolver/src/main/java/org/apache/sling/servlets/resolver/internal/SlingServletResolver.java
Wed Apr 20 23:59:29 2011
@@ -158,6 +158,13 @@ public class SlingServletResolver implem
 
     private static final String[] DEFAULT_PATHS = new String[] {"/"};
 
+    /**
+     * @scr.property values="html"
+     */
+    public static final String PROP_DEFAULT_EXTENSIONS = "servletresolver.defaultExtensions";
+    
+    private static final String[] DEFAULT_DEFAULT_EXTENSIONS = new String[] {"html"};
+
     /** @scr.reference */
     private ServletContext servletContext;
 
@@ -218,6 +225,11 @@ public class SlingServletResolver implem
      * The allowed execution paths.
      */
     private String[] executionPaths;
+    
+    /**
+     * The default extensions
+     */
+    private String[] defaultExtensions;
 
     // ---------- ServletResolver interface -----------------------------------
 
@@ -572,7 +584,7 @@ public class SlingServletResolver implem
         }
         if ( servlet == null ) {
             // the resource type is not absolute, so lets go for the deep search
-            final ResourceCollector locationUtil = ResourceCollector.create(request, workspaceName,
this.executionPaths);
+            final ResourceCollector locationUtil = ResourceCollector.create(request, workspaceName,
this.executionPaths, this.defaultExtensions);
             servlet = getServlet(locationUtil, request, resolver);
 
             if (log.isDebugEnabled()) {
@@ -845,6 +857,7 @@ public class SlingServletResolver implem
                 }
             }
         }
+        this.defaultExtensions = OsgiUtil.toStringArray(properties.get(PROP_DEFAULT_EXTENSIONS),
DEFAULT_DEFAULT_EXTENSIONS);
 
         // create cache - if a cache size is configured
         this.cacheSize = OsgiUtil.toInteger(properties.get(PROP_CACHE_SIZE), DEFAULT_CACHE_SIZE);

Modified: sling/trunk/bundles/servlets/resolver/src/main/java/org/apache/sling/servlets/resolver/internal/helper/ResourceCollector.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/resolver/src/main/java/org/apache/sling/servlets/resolver/internal/helper/ResourceCollector.java?rev=1095567&r1=1095566&r2=1095567&view=diff
==============================================================================
--- sling/trunk/bundles/servlets/resolver/src/main/java/org/apache/sling/servlets/resolver/internal/helper/ResourceCollector.java
(original)
+++ sling/trunk/bundles/servlets/resolver/src/main/java/org/apache/sling/servlets/resolver/internal/helper/ResourceCollector.java
Wed Apr 20 23:59:29 2011
@@ -21,6 +21,7 @@ package org.apache.sling.servlets.resolv
 import java.util.Iterator;
 import java.util.Set;
 
+import org.apache.commons.lang.ArrayUtils;
 import org.apache.sling.api.SlingHttpServletRequest;
 import org.apache.sling.api.request.RequestPathInfo;
 import org.apache.sling.api.resource.Resource;
@@ -60,7 +61,7 @@ public class ResourceCollector extends A
     private final boolean isGet;
 
     // request is GET or HEAD and extension is html
-    private final boolean isHtml;
+    private final boolean isDefaultExtension;
 
     private final String suffExt;
 
@@ -84,8 +85,9 @@ public class ResourceCollector extends A
      */
     public static ResourceCollector create(
             final SlingHttpServletRequest request, final String workspaceName,
-            final String[] executionPaths) {
-        return new ResourceCollector(request, workspaceName, executionPaths);
+            final String[] executionPaths, final String[] defaultExtensions) {
+        boolean isDefaultExtension = ArrayUtils.contains(defaultExtensions, request.getRequestPathInfo().getExtension());
+        return new ResourceCollector(request, workspaceName, executionPaths, isDefaultExtension);
     }
 
     /**
@@ -114,7 +116,7 @@ public class ResourceCollector extends A
         this.requestSelectors = new String[0];
         this.numRequestSelectors = 0;
         this.isGet = false;
-        this.isHtml = false;
+        this.isDefaultExtension = false;
 
         this.suffExt = "." + extension;
         this.suffMethod = "." + methodName;
@@ -143,7 +145,8 @@ public class ResourceCollector extends A
      *            is assumed.
      */
     private ResourceCollector(final SlingHttpServletRequest request,
-            final String workspaceName, final String[] executionPaths) {
+            final String workspaceName, final String[] executionPaths,
+            final boolean isDefaultExtension) {
         super(ServletResolverConstants.DEFAULT_SERVLET_NAME,
             request.getResource().getResourceType(),
             request.getResource().getResourceSuperType(), workspaceName,
@@ -156,11 +159,11 @@ public class ResourceCollector extends A
 
         RequestPathInfo requestpaInfo = request.getRequestPathInfo();
 
-        requestSelectors = requestpaInfo.getSelectors();
-        numRequestSelectors = requestSelectors.length;
+        this.requestSelectors = requestpaInfo.getSelectors();
+        this.numRequestSelectors = requestSelectors.length;
 
-        isGet = "GET".equals(methodName) || "HEAD".equals(methodName);
-        isHtml = "html".equals(extension);
+        this.isGet = "GET".equals(methodName) || "HEAD".equals(methodName);
+        this.isDefaultExtension = isDefaultExtension;
 
         // create the hash code once
         final String key = methodName + ':' + baseResourceType + ':'
@@ -292,7 +295,7 @@ public class ResourceCollector extends A
             return true;
         }
 
-        if (isHtml) {
+        if (isDefaultExtension) {
             if (selector != null && matches(scriptName, selector, htmlSuffix)) {
                 addWeightedResource(resources, child, selIdx + 1,
                     WeightedResource.WEIGHT_NONE);
@@ -345,7 +348,7 @@ public class ResourceCollector extends A
         }
         if (super.equals(obj)) {
             final ResourceCollector o = (ResourceCollector) obj;
-            if (isGet == o.isGet && isHtml == o.isHtml
+            if (isGet == o.isGet && isDefaultExtension == o.isDefaultExtension
                 && numRequestSelectors == o.numRequestSelectors
                 && stringEquals(methodName, o.methodName)) {
                 // now compare selectors

Modified: sling/trunk/bundles/servlets/resolver/src/main/resources/OSGI-INF/metatype/metatype.properties
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/resolver/src/main/resources/OSGI-INF/metatype/metatype.properties?rev=1095567&r1=1095566&r2=1095567&view=diff
==============================================================================
--- sling/trunk/bundles/servlets/resolver/src/main/resources/OSGI-INF/metatype/metatype.properties
(original)
+++ sling/trunk/bundles/servlets/resolver/src/main/resources/OSGI-INF/metatype/metatype.properties
Wed Apr 20 23:59:29 2011
@@ -65,4 +65,8 @@ servletresolver.paths.name = Execution P
 servletresolver.paths.description = The paths to search for executable scripts. If no path
is configured \
  this is treated like the default (/ = root) which allows to execute all scripts. By configuring
some \
  paths the execution of scripts can be limited. If a configured value ends with a slash,
the whole sub tree \
- is allowed. Without a slash an exact matching script is allowed.
\ No newline at end of file
+ is allowed. Without a slash an exact matching script is allowed.
+ 
+servletresolver.defaultExtensions.name = Default Extensions
+servletresolver.defaultExtensions.description = The list of extensions for which the default
behavior \
+ will be used. This means that the last path segement of the resource type can be used as
the script name.
\ No newline at end of file

Modified: sling/trunk/bundles/servlets/resolver/src/test/java/org/apache/sling/servlets/resolver/internal/helper/ResourceCollectorTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/resolver/src/test/java/org/apache/sling/servlets/resolver/internal/helper/ResourceCollectorTest.java?rev=1095567&r1=1095566&r2=1095567&view=diff
==============================================================================
--- sling/trunk/bundles/servlets/resolver/src/test/java/org/apache/sling/servlets/resolver/internal/helper/ResourceCollectorTest.java
(original)
+++ sling/trunk/bundles/servlets/resolver/src/test/java/org/apache/sling/servlets/resolver/internal/helper/ResourceCollectorTest.java
Wed Apr 20 23:59:29 2011
@@ -270,7 +270,7 @@ public class ResourceCollectorTest exten
             pathMap.put(name, path);
         }
 
-        ResourceCollector lu = ResourceCollector.create(request, null, null);
+        ResourceCollector lu = ResourceCollector.create(request, null, null, new String[]
{"html"});
         Collection<Resource> res = lu.getServlets(request.getResource().getResourceResolver());
         Iterator<Resource> rIter = res.iterator();
 

Modified: sling/trunk/bundles/servlets/resolver/src/test/java/org/apache/sling/servlets/resolver/internal/helper/ScriptSelectionTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/resolver/src/test/java/org/apache/sling/servlets/resolver/internal/helper/ScriptSelectionTest.java?rev=1095567&r1=1095566&r2=1095567&view=diff
==============================================================================
--- sling/trunk/bundles/servlets/resolver/src/test/java/org/apache/sling/servlets/resolver/internal/helper/ScriptSelectionTest.java
(original)
+++ sling/trunk/bundles/servlets/resolver/src/test/java/org/apache/sling/servlets/resolver/internal/helper/ScriptSelectionTest.java
Wed Apr 20 23:59:29 2011
@@ -67,7 +67,7 @@ public class ScriptSelectionTest extends
 
         // Create mock request and get scripts from ResourceCollector
         final MockSlingHttpServletRequest req = makeRequest(method, selectors, extension);
-        final ResourceCollector u = ResourceCollector.create(req, null, null);
+        final ResourceCollector u = ResourceCollector.create(req, null, null, new String[]
{"html"});
         final Collection<Resource> s = u.getServlets(req.getResource().getResourceResolver());
 
         if(expectedScript == null) {



Mime
View raw message