sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r788011 - 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/java/org/apache/sling/servlets/resolver/internal/r...
Date Wed, 24 Jun 2009 13:04:30 GMT
Author: cziegeler
Date: Wed Jun 24 13:04:29 2009
New Revision: 788011

URL: http://svn.apache.org/viewvc?rev=788011&view=rev
Log:
SLING-1022 : Add missing information to ResourceCollector and use new methods from ResourceUtil.

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/LocationIterator.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/java/org/apache/sling/servlets/resolver/internal/resource/ServletResourceProviderFactory.java
    sling/trunk/bundles/servlets/resolver/src/test/java/org/apache/sling/servlets/resolver/internal/helper/HelperTestBase.java
    sling/trunk/bundles/servlets/resolver/src/test/java/org/apache/sling/servlets/resolver/internal/helper/LocationIteratorTest.java
    sling/trunk/bundles/servlets/resolver/src/test/java/org/apache/sling/servlets/resolver/internal/helper/ResourceCollectorGetServletsTest.java
    sling/trunk/bundles/servlets/resolver/src/test/java/org/apache/sling/servlets/resolver/internal/helper/ScriptSelectionTest.java
    sling/trunk/bundles/servlets/resolver/src/test/java/org/apache/sling/servlets/resolver/internal/resource/ServletResourceProviderCreateTest.java

Modified: sling/trunk/bundles/servlets/resolver/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/resolver/pom.xml?rev=788011&r1=788010&r2=788011&view=diff
==============================================================================
--- sling/trunk/bundles/servlets/resolver/pom.xml (original)
+++ sling/trunk/bundles/servlets/resolver/pom.xml Wed Jun 24 13:04:29 2009
@@ -70,7 +70,7 @@
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.api</artifactId>
-            <version>2.0.2-incubator</version>
+            <version>2.0.5-SNAPSHOT</version>
         </dependency>
         <dependency>
             <groupId>org.apache.sling</groupId>

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=788011&r1=788010&r2=788011&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 Jun 24 13:04:29 2009
@@ -123,7 +123,6 @@
     // ---------- ServletResolver interface -----------------------------------
 
     public Servlet resolveServlet(SlingHttpServletRequest request) {
-
         Resource resource = request.getResource();
 
         // start tracking servlet resolution
@@ -153,7 +152,7 @@
         // the resource type is not absolute, so lets go for the deep search
         if (servlet == null) {
             ResourceCollector locationUtil = ResourceCollector.create(request);
-            servlet = getServlet(locationUtil, request, resource);
+            servlet = getServlet(locationUtil, request, resource.getResourceResolver());
 
             if(log.isDebugEnabled()) {
             	log.debug("getServlet returns Servlet {}", RequestUtil.getServletName(servlet));
@@ -261,8 +260,9 @@
             // find a servlet for the status as the method name
             ResourceCollector locationUtil = new ResourceCollector(
                 String.valueOf(status),
-                ServletResolverConstants.ERROR_HANDLER_PATH);
-            Servlet servlet = getServlet(locationUtil, request, resource);
+                ServletResolverConstants.ERROR_HANDLER_PATH,
+                resource);
+            Servlet servlet = getServlet(locationUtil, request, resource.getResourceResolver());
 
             // fall back to default servlet if none
             if (servlet == null) {
@@ -322,8 +322,9 @@
                 // find a servlet for the simple class name as the method name
                 ResourceCollector locationUtil = new ResourceCollector(
                     tClass.getSimpleName(),
-                    ServletResolverConstants.ERROR_HANDLER_PATH);
-                servlet = getServlet(locationUtil, request, resource);
+                    ServletResolverConstants.ERROR_HANDLER_PATH,
+                    resource);
+                servlet = getServlet(locationUtil, request, resource.getResourceResolver());
 
                 // go to the base class
                 tClass = tClass.getSuperclass();
@@ -396,8 +397,8 @@
      *         such servlet willing to handle the request could be found.
      */
     private Servlet getServlet(ResourceCollector locationUtil,
-            SlingHttpServletRequest request, Resource resource) {
-        Collection<Resource> candidates = locationUtil.getServlets(resource);
+            SlingHttpServletRequest request, ResourceResolver resolver) {
+        final Collection<Resource> candidates = locationUtil.getServlets(resolver);
 
     	if(log.isDebugEnabled()) {
     		if(candidates.isEmpty()) {
@@ -410,6 +411,7 @@
     		}
     	}
 
+    	boolean hasOptingServlet = false;
         for (Resource candidateResource : candidates) {
         	if(log.isDebugEnabled()) {
         		log.debug("Checking if candidate Resource {} adapts to Servlet and accepts request",
@@ -417,11 +419,15 @@
         	}
             Servlet candidate = candidateResource.adaptTo(Servlet.class);
             if (candidate != null) {
-                boolean servletAcceptsRequest = !(candidate instanceof OptingServlet)
+                final boolean isOptingServlet = candidate instanceof OptingServlet;
+                boolean servletAcceptsRequest = !isOptingServlet
                     || ((OptingServlet) candidate).accepts(request);
                 if (servletAcceptsRequest) {
                     return candidate;
                 }
+                if ( isOptingServlet ) {
+                    hasOptingServlet = true;
+                }
             	if(log.isDebugEnabled()) {
             		log.debug("Candidate {} does not accept request, ignored", candidateResource.getPath());
             	}

Modified: sling/trunk/bundles/servlets/resolver/src/main/java/org/apache/sling/servlets/resolver/internal/helper/LocationIterator.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/resolver/src/main/java/org/apache/sling/servlets/resolver/internal/helper/LocationIterator.java?rev=788011&r1=788010&r2=788011&view=diff
==============================================================================
--- sling/trunk/bundles/servlets/resolver/src/main/java/org/apache/sling/servlets/resolver/internal/helper/LocationIterator.java
(original)
+++ sling/trunk/bundles/servlets/resolver/src/main/java/org/apache/sling/servlets/resolver/internal/helper/LocationIterator.java
Wed Jun 24 13:04:29 2009
@@ -21,10 +21,8 @@
 import java.util.Iterator;
 import java.util.NoSuchElementException;
 
-import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceResolver;
-import org.apache.sling.jcr.resource.JcrResourceUtil;
-import org.apache.sling.servlets.resolver.internal.ServletResolverConstants;
+import org.apache.sling.api.resource.ResourceUtil;
 
 /**
  * The <code>LocationIterator</code> provides access to an ordered collection
@@ -49,7 +47,7 @@
 
     // The resource for which this iterator is created. This resource
     // gives the initial resource type and the first resource super type
-    private final Resource resource;
+    //private final Resource resource;
 
     // The resource resolver used to find resource super types of
     // resource types
@@ -69,6 +67,12 @@
     // The resource type to use for the next iteration loop
     private String resourceType;
 
+    // The first resource type to use
+    private final String firstResourceType;
+
+    // The first resource super type to use
+    private final String firstResourceSuperType;
+
     // The current relative path generated from the resource type
     private String relPath;
 
@@ -80,19 +84,15 @@
      * Creates an instance of this iterator starting with a location built from
      * the resource type of the <code>resource</code> and ending with the
      * given <code>baseResourceType</code>.
-     * 
-     * @param resource The <code>Resource</code> used to define the initial
-     *            resource type and resource super type.
-     * @param baseResourceType The base resource type. If this is
-     *            <code>null</code> the
-     *            {@link ServletResolverConstants#DEFAULT_SERVLET_NAME} is used.
+     *
+     * @param resourceType the initial resource type.
+     * @param resourceSuperType the initial resource super type.
+     * @param baseResourceType The base resource type.
+     * @param resolver The resource resolver
      */
-    public LocationIterator(Resource resource, String baseResourceType) {
-        this.resource = resource;
-        this.resolver = resource.getResourceResolver();
-        this.baseResourceType = (baseResourceType != null)
-                ? baseResourceType
-                : ServletResolverConstants.DEFAULT_SERVLET_NAME;
+    public LocationIterator(String resourceType, String resourceSuperType, String baseResourceType,
ResourceResolver resolver) {
+        this.resolver = resolver;
+        this.baseResourceType = baseResourceType;
 
         String[] tmpPath = resolver.getSearchPath();
         if (tmpPath == null || tmpPath.length == 0) {
@@ -100,7 +100,10 @@
         }
         searchPath = tmpPath;
 
-        resourceType = resource.getResourceType();
+        this.firstResourceType = resourceType;
+        this.firstResourceSuperType = resourceSuperType;
+        // we start with the first resource type
+        this.resourceType = firstResourceType;
 
         nextLocation = seek();
     }
@@ -114,7 +117,7 @@
 
     /**
      * Returns the next entry of this iterator.
-     * 
+     *
      * @throws NoSuchElementException if {@link #hasNext()} returns
      *             <code>false</code>.
      */
@@ -143,7 +146,7 @@
                 return null;
             }
 
-            String typePath = JcrResourceUtil.resourceTypeToPath(resourceType);
+            String typePath = ResourceUtil.resourceTypeToPath(resourceType);
             if (typePath.startsWith("/")) {
                 resourceType = getResourceSuperType(resourceType);
                 return typePath;
@@ -185,10 +188,10 @@
 
         // get the super type of the current resource type
         String superType;
-        if (resourceType.equals(resource.getResourceType())) {
-            superType = resource.getResourceSuperType();
+        if (resourceType.equals(this.firstResourceType)) {
+            superType = this.firstResourceSuperType;
         } else {
-            superType = JcrResourceUtil.getResourceSuperType(resolver,
+            superType = ResourceUtil.getResourceSuperType(resolver,
                 resourceType);
         }
 

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=788011&r1=788010&r2=788011&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 Jun 24 13:04:29 2009
@@ -30,11 +30,12 @@
 import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.api.resource.ResourceUtil;
 import org.apache.sling.api.resource.SyntheticResource;
+import org.apache.sling.servlets.resolver.internal.ServletResolverConstants;
 import org.apache.sling.servlets.resolver.internal.resource.ServletResourceProviderFactory;
 
 /**
  * The <code>ResourceCollector</code> class provides a single public method -
- * {@link #getServlets(Resource)} - which is used to find an ordered collection
+ * {@link #getServlets(ResourceResolver)} - which is used to find an ordered collection
  * of <code>Resource</code> instances which may be used to find a servlet or
  * script to handle a request to the given resource.
  */
@@ -72,6 +73,12 @@
     // request is GET or HEAD and extension is html
     private final boolean isHtml;
 
+    private final int hashCode;
+
+    private final String resourceType;
+
+    private final String resourceSuperType;
+
     /**
      * Creates a <code>ResourceCollector</code> for the given
      * <code>request</code>. If the request is a GET or HEAD request, a
@@ -100,15 +107,22 @@
      *            default value
      *            {@link org.apache.sling.servlets.resolver.internal.ServletResolverConstants#DEFAULT_SERVLET_NAME}
      *            is assumed.
+     * @param resource the resource to invoke, the resource type and resource super type
are taken from this resource.
      */
-    public ResourceCollector(String methodName, String baseResourceType) {
+    public ResourceCollector(String methodName, String baseResourceType, Resource resource)
{
         this.methodName = methodName;
-        this.baseResourceType = baseResourceType;
+        this.baseResourceType = (baseResourceType != null ? baseResourceType : ServletResolverConstants.DEFAULT_SERVLET_NAME);
         this.requestSelectors = new String[0];
         this.numRequestSelectors = 0;
         this.extension = null;
         this.isGet = false;
         this.isHtml = false;
+        this.resourceType = resource.getResourceType();
+        this.resourceSuperType = resource.getResourceSuperType();
+        // create the hash code once
+        final String key = methodName + ':' + baseResourceType + ':' + extension + "::" +
+            (this.resourceType == null ? "" : this.resourceType)+ ':' + (this.resourceSuperType
== null ? "" : this.resourceSuperType);
+        this.hashCode = key.hashCode();
     }
 
     /**
@@ -125,7 +139,9 @@
      */
     private ResourceCollector(SlingHttpServletRequest request) {
         this.methodName = request.getMethod();
-        this.baseResourceType = null;
+        this.baseResourceType = ServletResolverConstants.DEFAULT_SERVLET_NAME;
+        this.resourceType = request.getResource().getResourceType();
+        this.resourceSuperType = request.getResource().getResourceSuperType();
 
         RequestPathInfo requestpaInfo = request.getRequestPathInfo();
 
@@ -135,15 +151,18 @@
 
         isGet = "GET".equals(methodName) || "HEAD".equals(methodName);
         isHtml = isGet && "html".equals(extension);
+        // create the hash code once
+        final String key = methodName + ':' + baseResourceType + ':' + extension + ':' +
requestpaInfo.getSelectorString() + ':' +
+            (this.resourceType == null ? "" : this.resourceType)+ ':' + (this.resourceSuperType
== null ? "" : this.resourceSuperType);
+        this.hashCode = key.hashCode();
     }
 
-    public final Collection<Resource> getServlets(Resource resource) {
+    public final Collection<Resource> getServlets(ResourceResolver resolver) {
 
         SortedSet<Resource> resources = new TreeSet<Resource>();
 
-        ResourceResolver resolver = resource.getResourceResolver();
-        Iterator<String> locations = new LocationIterator(resource,
-            baseResourceType);
+        Iterator<String> locations = new LocationIterator(resourceType, resourceSuperType,
+            baseResourceType, resolver);
         while (locations.hasNext()) {
             String location = locations.next();
 
@@ -312,4 +331,50 @@
 
         return res;
     }
+
+    @Override
+    public boolean equals(Object obj) {
+        if ( !(obj instanceof ResourceCollector) ) {
+            return false;
+        }
+        if ( obj == this ) {
+            return true;
+        }
+        final ResourceCollector o = (ResourceCollector)obj;
+        if ( isGet == o.isGet
+             && isHtml == o.isHtml
+             && numRequestSelectors == o.numRequestSelectors
+             && stringEquals(methodName, o.methodName)
+             && stringEquals(baseResourceType, o.baseResourceType)
+             && stringEquals(resourceType, o.resourceType)
+             && stringEquals(resourceSuperType, o.resourceSuperType)
+             && stringEquals(extension, o.extension) ) {
+            // now compare selectors
+            for(int i=0;i<numRequestSelectors;i++) {
+                if ( !stringEquals(requestSelectors[i], o.requestSelectors[i]) ) {
+                    return false;
+                }
+            }
+            return true;
+        }
+        return false;
+    }
+
+    @Override
+    public int hashCode() {
+        return this.hashCode;
+    }
+
+    /**
+     * Helper method to compare two strings which can possibly be <code>null</code>
+     */
+    private boolean stringEquals(final String s1, final String s2) {
+        if ( s1 == null && s2 == null ) {
+            return true;
+        }
+        if ( s1 == null || s2 == null ) {
+            return false;
+        }
+        return s1.equals(s2);
+    }
 }

Modified: sling/trunk/bundles/servlets/resolver/src/main/java/org/apache/sling/servlets/resolver/internal/resource/ServletResourceProviderFactory.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/resolver/src/main/java/org/apache/sling/servlets/resolver/internal/resource/ServletResourceProviderFactory.java?rev=788011&r1=788010&r2=788011&view=diff
==============================================================================
--- sling/trunk/bundles/servlets/resolver/src/main/java/org/apache/sling/servlets/resolver/internal/resource/ServletResourceProviderFactory.java
(original)
+++ sling/trunk/bundles/servlets/resolver/src/main/java/org/apache/sling/servlets/resolver/internal/resource/ServletResourceProviderFactory.java
Wed Jun 24 13:04:29 2009
@@ -28,9 +28,9 @@
 import java.util.HashSet;
 import java.util.Set;
 
+import org.apache.sling.api.resource.ResourceUtil;
 import org.apache.sling.api.servlets.HttpConstants;
 import org.apache.sling.commons.osgi.OsgiUtil;
-import org.apache.sling.jcr.resource.JcrResourceUtil;
 import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.component.ComponentConstants;
@@ -258,7 +258,7 @@
         for (String type : types) {
 
             // ensure namespace prefixes are converted to slashes
-            type = JcrResourceUtil.resourceTypeToPath(type);
+            type = ResourceUtil.resourceTypeToPath(type);
 
             // make absolute if relative
             if (!type.startsWith("/")) {

Modified: sling/trunk/bundles/servlets/resolver/src/test/java/org/apache/sling/servlets/resolver/internal/helper/HelperTestBase.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/resolver/src/test/java/org/apache/sling/servlets/resolver/internal/helper/HelperTestBase.java?rev=788011&r1=788010&r2=788011&view=diff
==============================================================================
--- sling/trunk/bundles/servlets/resolver/src/test/java/org/apache/sling/servlets/resolver/internal/helper/HelperTestBase.java
(original)
+++ sling/trunk/bundles/servlets/resolver/src/test/java/org/apache/sling/servlets/resolver/internal/helper/HelperTestBase.java
Wed Jun 24 13:04:29 2009
@@ -20,10 +20,10 @@
 
 import junit.framework.TestCase;
 
+import org.apache.sling.api.resource.ResourceUtil;
 import org.apache.sling.commons.testing.sling.MockResource;
 import org.apache.sling.commons.testing.sling.MockResourceResolver;
 import org.apache.sling.commons.testing.sling.MockSlingHttpServletRequest;
-import org.apache.sling.jcr.resource.JcrResourceUtil;
 
 public abstract class HelperTestBase extends TestCase {
 
@@ -51,18 +51,18 @@
         resourceResolver.setSearchPath("/apps", "/libs");
 
         resourceType = "foo:bar";
-        resourceTypePath = JcrResourceUtil.resourceTypeToPath(resourceType);
+        resourceTypePath = ResourceUtil.resourceTypeToPath(resourceType);
 
         resourcePath = "/content/page";
         resource = new MockResource(resourceResolver, resourcePath,
             resourceType);
         resourceResolver.addResource(resource);
 
-        request = makeRequest("GET", "print.a4", "html"); 
+        request = makeRequest("GET", "print.a4", "html");
     }
-    
+
     protected MockSlingHttpServletRequest makeRequest(String method, String selectors, String
extension) {
-        final MockSlingHttpServletRequest result = 
+        final MockSlingHttpServletRequest result =
             new MockSlingHttpServletRequest(resourcePath, selectors, extension, null, null);
         result.setMethod(method);
         result.setResourceResolver(resourceResolver);
@@ -78,5 +78,5 @@
         request = null;
         resource = null;
     }
-    
+
 }

Modified: sling/trunk/bundles/servlets/resolver/src/test/java/org/apache/sling/servlets/resolver/internal/helper/LocationIteratorTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/resolver/src/test/java/org/apache/sling/servlets/resolver/internal/helper/LocationIteratorTest.java?rev=788011&r1=788010&r2=788011&view=diff
==============================================================================
--- sling/trunk/bundles/servlets/resolver/src/test/java/org/apache/sling/servlets/resolver/internal/helper/LocationIteratorTest.java
(original)
+++ sling/trunk/bundles/servlets/resolver/src/test/java/org/apache/sling/servlets/resolver/internal/helper/LocationIteratorTest.java
Wed Jun 24 13:04:29 2009
@@ -20,7 +20,8 @@
 
 import static org.apache.sling.servlets.resolver.internal.ServletResolverConstants.DEFAULT_SERVLET_NAME;
 
-import org.apache.sling.jcr.resource.JcrResourceUtil;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceUtil;
 
 public class LocationIteratorTest extends HelperTestBase {
 
@@ -28,8 +29,11 @@
         // expect path gets { "/" }
         resourceResolver.setSearchPath((String[]) null);
 
-        LocationIterator li = new LocationIterator(request.getResource(),
-            DEFAULT_SERVLET_NAME);
+        final Resource r = request.getResource();
+        LocationIterator li = new LocationIterator(r.getResourceType(),
+                r.getResourceSuperType(),
+                DEFAULT_SERVLET_NAME,
+                resourceResolver);
 
         // 1. /foo/bar
         assertTrue(li.hasNext());
@@ -47,8 +51,11 @@
         String root0 = "/apps";
         resourceResolver.setSearchPath(root0);
 
-        LocationIterator li = new LocationIterator(request.getResource(),
-            DEFAULT_SERVLET_NAME);
+        final Resource r = request.getResource();
+        LocationIterator li = new LocationIterator(r.getResourceType(),
+                r.getResourceSuperType(),
+                DEFAULT_SERVLET_NAME,
+                resourceResolver);
 
         // 1. /apps/foo/bar
         assertTrue(li.hasNext());
@@ -67,8 +74,11 @@
         String root1 = "/libs";
         resourceResolver.setSearchPath(root0, root1);
 
-        LocationIterator li = new LocationIterator(request.getResource(),
-            DEFAULT_SERVLET_NAME);
+        final Resource r = request.getResource();
+        LocationIterator li = new LocationIterator(r.getResourceType(),
+                r.getResourceSuperType(),
+                DEFAULT_SERVLET_NAME,
+                resourceResolver);
 
         // 1. /apps/foo/bar
         assertTrue(li.hasNext());
@@ -96,11 +106,14 @@
 
         // absolute resource type
         resourceType = "/foo/bar";
-        resourceTypePath = JcrResourceUtil.resourceTypeToPath(resourceType);
+        resourceTypePath = ResourceUtil.resourceTypeToPath(resourceType);
         resource.setResourceType(resourceType);
 
-        LocationIterator li = new LocationIterator(request.getResource(),
-            DEFAULT_SERVLET_NAME);
+        final Resource r = request.getResource();
+        LocationIterator li = new LocationIterator(r.getResourceType(),
+                r.getResourceSuperType(),
+                DEFAULT_SERVLET_NAME,
+                resourceResolver);
 
         // 1. /foo/bar
         assertTrue(li.hasNext());
@@ -120,11 +133,14 @@
 
         // absolute resource type
         resourceType = "/foo/bar";
-        resourceTypePath = JcrResourceUtil.resourceTypeToPath(resourceType);
+        resourceTypePath = ResourceUtil.resourceTypeToPath(resourceType);
         resource.setResourceType(resourceType);
 
-        LocationIterator li = new LocationIterator(request.getResource(),
-            DEFAULT_SERVLET_NAME);
+        final Resource r = request.getResource();
+        LocationIterator li = new LocationIterator(r.getResourceType(),
+                r.getResourceSuperType(),
+                DEFAULT_SERVLET_NAME,
+                resourceResolver);
 
         // 1. /foo/bar
         assertTrue(li.hasNext());
@@ -145,11 +161,14 @@
 
         // absolute resource type
         resourceType = "/foo/bar";
-        resourceTypePath = JcrResourceUtil.resourceTypeToPath(resourceType);
+        resourceTypePath = ResourceUtil.resourceTypeToPath(resourceType);
         resource.setResourceType(resourceType);
 
-        LocationIterator li = new LocationIterator(request.getResource(),
-            DEFAULT_SERVLET_NAME);
+        final Resource r = request.getResource();
+        LocationIterator li = new LocationIterator(r.getResourceType(),
+                r.getResourceSuperType(),
+                DEFAULT_SERVLET_NAME,
+                resourceResolver);
 
         // 1. /foo/bar
         assertTrue(li.hasNext());
@@ -173,11 +192,14 @@
 
         // set resource super type
         resourceSuperType = "foo:superBar";
-        resourceSuperTypePath = JcrResourceUtil.resourceTypeToPath(resourceSuperType);
+        resourceSuperTypePath = ResourceUtil.resourceTypeToPath(resourceSuperType);
         resource.setResourceSuperType(resourceSuperType);
 
-        LocationIterator li = new LocationIterator(request.getResource(),
-            DEFAULT_SERVLET_NAME);
+        final Resource r = request.getResource();
+        LocationIterator li = new LocationIterator(r.getResourceType(),
+                r.getResourceSuperType(),
+                DEFAULT_SERVLET_NAME,
+                resourceResolver);
 
         // 1. /foo/bar
         assertTrue(li.hasNext());
@@ -201,11 +223,14 @@
 
         // set resource super type
         resourceSuperType = "foo:superBar";
-        resourceSuperTypePath = JcrResourceUtil.resourceTypeToPath(resourceSuperType);
+        resourceSuperTypePath = ResourceUtil.resourceTypeToPath(resourceSuperType);
         resource.setResourceSuperType(resourceSuperType);
 
-        LocationIterator li = new LocationIterator(request.getResource(),
-            DEFAULT_SERVLET_NAME);
+        final Resource r = request.getResource();
+        LocationIterator li = new LocationIterator(r.getResourceType(),
+                r.getResourceSuperType(),
+                DEFAULT_SERVLET_NAME,
+                resourceResolver);
 
         // 1. /apps/foo/bar
         assertTrue(li.hasNext());
@@ -230,11 +255,14 @@
 
         // set resource super type
         resourceSuperType = "foo:superBar";
-        resourceSuperTypePath = JcrResourceUtil.resourceTypeToPath(resourceSuperType);
+        resourceSuperTypePath = ResourceUtil.resourceTypeToPath(resourceSuperType);
         resource.setResourceSuperType(resourceSuperType);
 
-        LocationIterator li = new LocationIterator(request.getResource(),
-            DEFAULT_SERVLET_NAME);
+        final Resource r = request.getResource();
+        LocationIterator li = new LocationIterator(r.getResourceType(),
+                r.getResourceSuperType(),
+                DEFAULT_SERVLET_NAME,
+                resourceResolver);
 
         // 1. /apps/foo/bar
         assertTrue(li.hasNext());
@@ -270,16 +298,19 @@
 
         // absolute resource type
         resourceType = "/foo/bar";
-        resourceTypePath = JcrResourceUtil.resourceTypeToPath(resourceType);
+        resourceTypePath = ResourceUtil.resourceTypeToPath(resourceType);
         resource.setResourceType(resourceType);
 
         // set resource super type
         resourceSuperType = "foo:superBar";
-        resourceSuperTypePath = JcrResourceUtil.resourceTypeToPath(resourceSuperType);
+        resourceSuperTypePath = ResourceUtil.resourceTypeToPath(resourceSuperType);
         resource.setResourceSuperType(resourceSuperType);
 
-        LocationIterator li = new LocationIterator(request.getResource(),
-            DEFAULT_SERVLET_NAME);
+        final Resource r = request.getResource();
+        LocationIterator li = new LocationIterator(r.getResourceType(),
+                r.getResourceSuperType(),
+                DEFAULT_SERVLET_NAME,
+                resourceResolver);
 
         // 1. /foo/bar
         assertTrue(li.hasNext());
@@ -303,16 +334,19 @@
 
         // absolute resource type
         resourceType = "/foo/bar";
-        resourceTypePath = JcrResourceUtil.resourceTypeToPath(resourceType);
+        resourceTypePath = ResourceUtil.resourceTypeToPath(resourceType);
         resource.setResourceType(resourceType);
 
         // set resource super type
         resourceSuperType = "foo:superBar";
-        resourceSuperTypePath = JcrResourceUtil.resourceTypeToPath(resourceSuperType);
+        resourceSuperTypePath = ResourceUtil.resourceTypeToPath(resourceSuperType);
         resource.setResourceSuperType(resourceSuperType);
 
-        LocationIterator li = new LocationIterator(request.getResource(),
-            DEFAULT_SERVLET_NAME);
+        final Resource r = request.getResource();
+        LocationIterator li = new LocationIterator(r.getResourceType(),
+                r.getResourceSuperType(),
+                DEFAULT_SERVLET_NAME,
+                resourceResolver);
 
         // 1. /foo/bar
         assertTrue(li.hasNext());
@@ -337,16 +371,19 @@
 
         // absolute resource type
         resourceType = "/foo/bar";
-        resourceTypePath = JcrResourceUtil.resourceTypeToPath(resourceType);
+        resourceTypePath = ResourceUtil.resourceTypeToPath(resourceType);
         resource.setResourceType(resourceType);
 
         // set resource super type
         resourceSuperType = "foo:superBar";
-        resourceSuperTypePath = JcrResourceUtil.resourceTypeToPath(resourceSuperType);
+        resourceSuperTypePath = ResourceUtil.resourceTypeToPath(resourceSuperType);
         resource.setResourceSuperType(resourceSuperType);
 
-        LocationIterator li = new LocationIterator(request.getResource(),
-            DEFAULT_SERVLET_NAME);
+        final Resource r = request.getResource();
+        LocationIterator li = new LocationIterator(r.getResourceType(),
+                r.getResourceSuperType(),
+                DEFAULT_SERVLET_NAME,
+                resourceResolver);
 
         // 1. /foo/bar
         assertTrue(li.hasNext());

Modified: sling/trunk/bundles/servlets/resolver/src/test/java/org/apache/sling/servlets/resolver/internal/helper/ResourceCollectorGetServletsTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/resolver/src/test/java/org/apache/sling/servlets/resolver/internal/helper/ResourceCollectorGetServletsTest.java?rev=788011&r1=788010&r2=788011&view=diff
==============================================================================
--- sling/trunk/bundles/servlets/resolver/src/test/java/org/apache/sling/servlets/resolver/internal/helper/ResourceCollectorGetServletsTest.java
(original)
+++ sling/trunk/bundles/servlets/resolver/src/test/java/org/apache/sling/servlets/resolver/internal/helper/ResourceCollectorGetServletsTest.java
Wed Jun 24 13:04:29 2009
@@ -155,7 +155,7 @@
         }
 
         ResourceCollector lu = ResourceCollector.create(request);
-        Collection<Resource> res = lu.getServlets(request.getResource());
+        Collection<Resource> res = lu.getServlets(request.getResource().getResourceResolver());
         Iterator<Resource> rIter = res.iterator();
 
         for (int index : indices) {

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=788011&r1=788010&r2=788011&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 Jun 24 13:04:29 2009
@@ -24,12 +24,12 @@
 import org.apache.sling.commons.testing.sling.MockResource;
 import org.apache.sling.commons.testing.sling.MockSlingHttpServletRequest;
 
-/** Various tests that explain and demonstrate how scripts are 
+/** Various tests that explain and demonstrate how scripts are
  *  selected. See the assertScript methods for how to interpret
  *  the various tests.
  */
 public class ScriptSelectionTest extends HelperTestBase {
-    
+
     /** Test set of available scripts */
     protected final String [] SET_A = {
             "/apps/foo/bar/html.esp",
@@ -45,31 +45,31 @@
             "/apps/foo/bar/UNKNOWN.esp"
 
     };
-    
-    /** Given a list of available scripts and the request method, selectors 
+
+    /** Given a list of available scripts and the request method, selectors
      *  and extension, check that the expected script is selected.
      *  The resource type is foo:bar, set by HelperTestBase
-     *  
+     *
      *  @param method the HTTP method of the simulated request
      *  @param selectors the selectors of the simulated request
      *  @param extension the extension of the simulated request
      *  @param scripts the list of scripts that would be available in the repository
      *  @param expectedScript the script that we expect to be selected
-     */ 
+     */
     protected void assertScript(String method, String selectors, String extension,
-            String [] scripts, String expectedScript) 
+            String [] scripts, String expectedScript)
     {
         // Add given scripts to our mock resource resolver
         for(String script : scripts) {
             final MockResource r = new MockResource(resourceResolver, script, "nt:file");
-            resourceResolver.addResource(r);            
+            resourceResolver.addResource(r);
         }
-        
+
         // Create mock request and get scripts from ResourceCollector
         final MockSlingHttpServletRequest req = makeRequest(method, selectors, extension);
         final ResourceCollector u = ResourceCollector.create(req);
-        final Collection<Resource> s = u.getServlets(req.getResource());
-        
+        final Collection<Resource> s = u.getServlets(req.getResource().getResourceResolver());
+
         if(expectedScript == null) {
             assertFalse("No script must be found", s.iterator().hasNext());
         } else {
@@ -79,15 +79,15 @@
             assertEquals("First script is the expected one", expectedScript, scriptPath);
         }
     }
-    
+
     public void testHtmlGet() {
         assertScript("GET", null, "html", SET_A, "/apps/foo/bar/html.esp");
     }
-    
+
     public void testHtmlGetSelectors() {
         assertScript("GET", "print.a4", "html", SET_A, "/apps/foo/bar/print.esp");
     }
-    
+
     public void testHtmlGetSelectorsAndResourceLabel() {
         final String [] scripts = {
                 "/apps/foo/bar/bar.esp",
@@ -97,11 +97,11 @@
         // to be selector-specific
         assertScript("GET", "print.a4", "html", scripts, "/apps/foo/bar/bar.esp");
     }
-    
+
     public void testHtmlGetSingleSelector() {
         assertScript("GET", "print", "html", SET_A, "/apps/foo/bar/print.esp");
     }
-    
+
     public void testHtmlGetHtmlHasPriorityA() {
         final String [] scripts = {
             "/apps/foo/bar/html.esp",
@@ -109,7 +109,7 @@
         };
         assertScript("GET", null, "html", scripts, "/apps/foo/bar/html.esp");
     }
-    
+
     public void testHtmlGetHtmlHasPriorityB() {
         final String [] scripts = {
             "/apps/foo/bar/bar.esp",
@@ -117,7 +117,7 @@
         };
         assertScript("GET", null, "html", scripts, "/apps/foo/bar/html.esp");
     }
-    
+
     public void testHtmlGetBarUsedIfFound() {
         final String [] scripts = {
                 "/apps/foo/bar/bar.esp",
@@ -125,15 +125,15 @@
             };
         assertScript("GET", null, "html", scripts, "/apps/foo/bar/bar.esp");
     }
-    
+
     public void testXmlGetSetC() {
         assertScript("GET", null, "xml", SET_A, "/apps/foo/bar/xml.esp");
     }
-    
+
     public void testXmlGetSelectors() {
         assertScript("GET", "print.a4", "xml", SET_A, "/apps/foo/bar/print.xml.esp");
     }
-    
+
     public void testMultipleSelectorsA() {
         final String [] scripts = {
                 "/apps/foo/bar/print",
@@ -146,7 +146,7 @@
             };
             assertScript("GET", "print.a4", "html", scripts, "/apps/foo/bar/print/a4.esp");
     }
-    
+
     public void testMultipleSelectorsB() {
         final String [] scripts = {
                 "/apps/foo/bar/print.a4.esp",
@@ -158,7 +158,7 @@
             assertScript("GET", "a4.print", "html", scripts, "/apps/foo/bar/a4.esp");
             assertScript("GET", null, "html", scripts, "/apps/foo/bar/html.esp");
     }
-    
+
     public void testMultipleSelectorsC() {
         final String [] scripts = {
                 "/apps/foo/bar/print.esp",
@@ -166,7 +166,7 @@
             };
             assertScript("GET", "print.a4", "html", scripts, "/apps/foo/bar/print.esp");
     }
-    
+
     public void testMultipleSelectorsD() {
         final String [] scripts = {
                 "/apps/foo/bar/a4.esp",
@@ -175,7 +175,7 @@
             assertScript("GET", "print.a4", "html", scripts, "/apps/foo/bar/html.esp");
             assertScript("GET", "a4.print", "html", scripts, "/apps/foo/bar/a4.esp");
     }
-    
+
     public void testMultipleSelectorsE() {
         final String [] scripts = {
                 "/apps/foo/bar/bar.print.a4.esp",
@@ -191,11 +191,11 @@
             assertScript("GET", "a4.print", "html", scripts, "/apps/foo/bar/a4.esp");
             assertScript("GET", null, "html", scripts, "/apps/foo/bar/html.esp");
     }
-    
+
     public void testXmlGetSingleSelector() {
         assertScript("GET", "print", "xml", SET_A, "/apps/foo/bar/print.xml.esp");
     }
-    
+
     public void testHtmlGetAppsOverridesLibsA() {
         final String [] scripts = {
                 "/apps/foo/bar/bar.esp",
@@ -203,7 +203,7 @@
             };
         assertScript("GET", null, "html", scripts, "/apps/foo/bar/bar.esp");
     }
-    
+
     public void testHtmlGetAppsOverridesLibsB() {
         final String [] scripts = {
                 "/libs/foo/bar/bar.esp",
@@ -211,18 +211,18 @@
             };
         assertScript("GET", null, "html", scripts, "/apps/foo/bar/bar.esp");
     }
-    
+
     public void testHtmlGetLibUsedIfFound() {
         final String [] scripts = {
                 "/libs/foo/bar/bar.esp"
             };
         assertScript("GET", null, "html", scripts, "/libs/foo/bar/bar.esp");
     }
-    
+
     public void testHtmlPost() {
         assertScript("POST", null, "html", SET_A, "/apps/foo/bar/POST.esp");
     }
-    
+
     public void testHtmlPostBadCaseFindsNoScript() {
         final String [] scripts = {
                 "/apps/foo/bar/html.esp",
@@ -230,35 +230,35 @@
         };
         assertScript("POST", null, "html", scripts, null);
     }
-    
+
     public void testHtmlPostSelectors() {
         assertScript("POST", "print.a4", "html", SET_A, "/apps/foo/bar/print/POST.esp");
         assertScript("POST", "print", "html", SET_A, "/apps/foo/bar/print/POST.esp");
         assertScript("POST", "a4.print", "html", SET_A, "/apps/foo/bar/POST.esp");
         assertScript("POST", null, "html", SET_A, "/apps/foo/bar/POST.esp");
     }
-    
+
     public void testHtmlMethodSelectors() {
         assertScript("DELETE", "print.a4", "html", SET_A, "/apps/foo/bar/print/DELETE.esp");
         assertScript("SPURIOUS", "print", "html", SET_A, "/apps/foo/bar/SPURIOUS.esp");
         assertScript("UNKNOWN", "a4.print", "html", SET_A, "/apps/foo/bar/UNKNOWN.esp");
         assertScript("UNKNOWN", null, "html", SET_A, "/apps/foo/bar/UNKNOWN.esp");
     }
-    
+
     public void testHtmlPostSelectorsAreIgnored() {
         final String [] scripts = {
                 "/apps/foo/bar/print/POST.esp"
         };
         assertScript("POST", "print.a4", "html", scripts, null);
     }
-    
+
     public void testHtmlPostExtensionIsIgnored() {
         final String [] scripts = {
                 "/apps/foo/bar/POST.html.esp"
         };
         assertScript("POST", "print.a4", "html", scripts, null);
     }
-    
+
     public void testHtmlPostCannotIncludeResourceType() {
         final String [] scripts = {
                 "/apps/foo/bar/bar.POST.esp"

Modified: sling/trunk/bundles/servlets/resolver/src/test/java/org/apache/sling/servlets/resolver/internal/resource/ServletResourceProviderCreateTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/resolver/src/test/java/org/apache/sling/servlets/resolver/internal/resource/ServletResourceProviderCreateTest.java?rev=788011&r1=788010&r2=788011&view=diff
==============================================================================
--- sling/trunk/bundles/servlets/resolver/src/test/java/org/apache/sling/servlets/resolver/internal/resource/ServletResourceProviderCreateTest.java
(original)
+++ sling/trunk/bundles/servlets/resolver/src/test/java/org/apache/sling/servlets/resolver/internal/resource/ServletResourceProviderCreateTest.java
Wed Jun 24 13:04:29 2009
@@ -28,9 +28,9 @@
 
 import junit.framework.TestCase;
 
+import org.apache.sling.api.resource.ResourceUtil;
 import org.apache.sling.api.servlets.HttpConstants;
 import org.apache.sling.commons.testing.osgi.MockServiceReference;
-import org.apache.sling.jcr.resource.JcrResourceUtil;
 import org.apache.sling.servlets.resolver.internal.ServletResolverConstants;
 
 public class ServletResourceProviderCreateTest extends TestCase {
@@ -45,7 +45,7 @@
 
     private static final String RES_TYPE = "sling:sample";
 
-    private static final String RES_TYPE_PATH = JcrResourceUtil.resourceTypeToPath(RES_TYPE);
+    private static final String RES_TYPE_PATH = ResourceUtil.resourceTypeToPath(RES_TYPE);
 
     private ServletResourceProviderFactory factory = new ServletResourceProviderFactory(
         ROOT, new String[] {"/apps/"});



Mime
View raw message