incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jus...@apache.org
Subject svn commit: r958601 - in /sling/trunk/bundles/servlets/resolver/src: main/java/org/apache/sling/servlets/resolver/internal/helper/ test/java/org/apache/sling/servlets/resolver/internal/helper/
Date Mon, 28 Jun 2010 15:23:36 GMT
Author: justin
Date: Mon Jun 28 15:23:36 2010
New Revision: 958601

URL: http://svn.apache.org/viewvc?rev=958601&view=rev
Log:
SLING-1446 - resolving super resource type against correct resource

Modified:
    sling/trunk/bundles/servlets/resolver/src/main/java/org/apache/sling/servlets/resolver/internal/helper/AbstractResourceCollector.java
    sling/trunk/bundles/servlets/resolver/src/main/java/org/apache/sling/servlets/resolver/internal/helper/LocationIterator.java
    sling/trunk/bundles/servlets/resolver/src/test/java/org/apache/sling/servlets/resolver/internal/helper/LocationIteratorTest.java

Modified: sling/trunk/bundles/servlets/resolver/src/main/java/org/apache/sling/servlets/resolver/internal/helper/AbstractResourceCollector.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/resolver/src/main/java/org/apache/sling/servlets/resolver/internal/helper/AbstractResourceCollector.java?rev=958601&r1=958600&r2=958601&view=diff
==============================================================================
--- sling/trunk/bundles/servlets/resolver/src/main/java/org/apache/sling/servlets/resolver/internal/helper/AbstractResourceCollector.java
(original)
+++ sling/trunk/bundles/servlets/resolver/src/main/java/org/apache/sling/servlets/resolver/internal/helper/AbstractResourceCollector.java
Mon Jun 28 15:23:36 2010
@@ -72,7 +72,7 @@ public abstract class AbstractResourceCo
 
         final SortedSet<Resource> resources = new TreeSet<Resource>();
         final Iterator<String> locations = new LocationIterator(resourceType, resourceSuperType,
-                                                                baseResourceType, resolver);
+                                                                baseResourceType, workspaceName,
resolver);
         while (locations.hasNext()) {
             final String location = locations.next();
 

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=958601&r1=958600&r2=958601&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
Mon Jun 28 15:23:36 2010
@@ -23,6 +23,7 @@ import java.util.Iterator;
 import java.util.NoSuchElementException;
 import java.util.Set;
 
+import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.api.resource.ResourceUtil;
 import org.slf4j.LoggerFactory;
@@ -85,6 +86,9 @@ public class LocationIterator implements
 
     /** Set of used resource types to detect a circular resource type hierarchy. */
     private final Set<String> usedResourceTypes = new HashSet<String>();
+    
+    // the workspace name
+    private String workspaceName;
 
     /**
      * Creates an instance of this iterator starting with a location built from
@@ -96,9 +100,11 @@ public class LocationIterator implements
      * @param baseResourceType The base resource type.
      * @param resolver The resource resolver
      */
-    public LocationIterator(String resourceType, String resourceSuperType, String baseResourceType,
ResourceResolver resolver) {
+    public LocationIterator(String resourceType, String resourceSuperType, String baseResourceType,
+            String workspaceName, ResourceResolver resolver) {
         this.resolver = resolver;
         this.baseResourceType = baseResourceType;
+        this.workspaceName = workspaceName;
 
         String[] tmpPath = resolver.getSearchPath();
         if (tmpPath == null || tmpPath.length == 0) {
@@ -200,8 +206,7 @@ public class LocationIterator implements
                 && this.firstResourceSuperType != null ) {
             superType = this.firstResourceSuperType;
         } else {
-            superType = ResourceUtil.getResourceSuperType(resolver,
-                resourceType);
+            superType = getResourceSuperType(resolver, resourceType);
         }
 
         // detect circular dependency
@@ -220,5 +225,46 @@ public class LocationIterator implements
 
         return superType;
     }
+   
+    // this method is largely duplicated from ResourceUtil, but takes the configured
+    // workspaceName into account.
+    private String getResourceSuperType(final ResourceResolver resourceResolver,
+                                              final String resourceType) {
+        // normalize resource type to a path string
+        final String rtPath = ResourceUtil.resourceTypeToPath(resourceType);
+        // get the resource type resource and check its super type
+        String resourceSuperType = null;
+        // if the path is absolute, use it directly
+        if ( rtPath != null && rtPath.startsWith("/") ) {
+            final String candidatePath;
+            if ( this.workspaceName != null ) {
+                candidatePath = workspaceName + ':' + rtPath;
+            } else {
+                candidatePath = rtPath;
+            }
+            
+            final Resource rtResource = resourceResolver.getResource(candidatePath);
+            if ( rtResource != null ) {
+                resourceSuperType = rtResource.getResourceSuperType();
+            }
+
+        } else {
+            // if the path is relative we use the search paths
+            for(final String searchPath : resourceResolver.getSearchPath()) {
+                final String candidatePath;
+                if ( this.workspaceName != null ) {
+                    candidatePath = workspaceName + ':' + searchPath + rtPath;
+                } else {
+                    candidatePath = searchPath + rtPath;
+                }
+                final Resource rtResource = resourceResolver.getResource(candidatePath);
+                if ( rtResource != null && rtResource.getResourceSuperType() != null
) {
+                    resourceSuperType = rtResource.getResourceSuperType();
+                    break;
+                }
+            }
+        }
+        return resourceSuperType;
+    }
 
 }

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=958601&r1=958600&r2=958601&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
Mon Jun 28 15:23:36 2010
@@ -33,7 +33,7 @@ public class LocationIteratorTest extend
         final Resource r = request.getResource();
         LocationIterator li = new LocationIterator(r.getResourceType(),
                 r.getResourceSuperType(),
-                DEFAULT_SERVLET_NAME,
+                DEFAULT_SERVLET_NAME, null,
                 resourceResolver);
 
         // 1. /foo/bar
@@ -55,7 +55,7 @@ public class LocationIteratorTest extend
         final Resource r = request.getResource();
         LocationIterator li = new LocationIterator(r.getResourceType(),
                 r.getResourceSuperType(),
-                DEFAULT_SERVLET_NAME,
+                DEFAULT_SERVLET_NAME, null,
                 resourceResolver);
 
         // 1. /apps/foo/bar
@@ -78,7 +78,7 @@ public class LocationIteratorTest extend
         final Resource r = request.getResource();
         LocationIterator li = new LocationIterator(r.getResourceType(),
                 r.getResourceSuperType(),
-                DEFAULT_SERVLET_NAME,
+                DEFAULT_SERVLET_NAME, null,
                 resourceResolver);
 
         // 1. /apps/foo/bar
@@ -113,7 +113,7 @@ public class LocationIteratorTest extend
         final Resource r = request.getResource();
         LocationIterator li = new LocationIterator(r.getResourceType(),
                 r.getResourceSuperType(),
-                DEFAULT_SERVLET_NAME,
+                DEFAULT_SERVLET_NAME, null,
                 resourceResolver);
 
         // 1. /foo/bar
@@ -140,7 +140,7 @@ public class LocationIteratorTest extend
         final Resource r = request.getResource();
         LocationIterator li = new LocationIterator(r.getResourceType(),
                 r.getResourceSuperType(),
-                DEFAULT_SERVLET_NAME,
+                DEFAULT_SERVLET_NAME, null,
                 resourceResolver);
 
         // 1. /foo/bar
@@ -168,7 +168,7 @@ public class LocationIteratorTest extend
         final Resource r = request.getResource();
         LocationIterator li = new LocationIterator(r.getResourceType(),
                 r.getResourceSuperType(),
-                DEFAULT_SERVLET_NAME,
+                DEFAULT_SERVLET_NAME, null,
                 resourceResolver);
 
         // 1. /foo/bar
@@ -199,7 +199,7 @@ public class LocationIteratorTest extend
         final Resource r = request.getResource();
         LocationIterator li = new LocationIterator(r.getResourceType(),
                 r.getResourceSuperType(),
-                DEFAULT_SERVLET_NAME,
+                DEFAULT_SERVLET_NAME, null,
                 resourceResolver);
 
         // 1. /foo/bar
@@ -230,7 +230,7 @@ public class LocationIteratorTest extend
         final Resource r = request.getResource();
         LocationIterator li = new LocationIterator(r.getResourceType(),
                 r.getResourceSuperType(),
-                DEFAULT_SERVLET_NAME,
+                DEFAULT_SERVLET_NAME, null,
                 resourceResolver);
 
         // 1. /apps/foo/bar
@@ -262,7 +262,7 @@ public class LocationIteratorTest extend
         final Resource r = request.getResource();
         LocationIterator li = new LocationIterator(r.getResourceType(),
                 r.getResourceSuperType(),
-                DEFAULT_SERVLET_NAME,
+                DEFAULT_SERVLET_NAME, null,
                 resourceResolver);
 
         // 1. /apps/foo/bar
@@ -310,7 +310,7 @@ public class LocationIteratorTest extend
         final Resource r = request.getResource();
         LocationIterator li = new LocationIterator(r.getResourceType(),
                 r.getResourceSuperType(),
-                DEFAULT_SERVLET_NAME,
+                DEFAULT_SERVLET_NAME, null,
                 resourceResolver);
 
         // 1. /foo/bar
@@ -346,7 +346,7 @@ public class LocationIteratorTest extend
         final Resource r = request.getResource();
         LocationIterator li = new LocationIterator(r.getResourceType(),
                 r.getResourceSuperType(),
-                DEFAULT_SERVLET_NAME,
+                DEFAULT_SERVLET_NAME, null,
                 resourceResolver);
 
         // 1. /foo/bar
@@ -383,7 +383,7 @@ public class LocationIteratorTest extend
         final Resource r = request.getResource();
         LocationIterator li = new LocationIterator(r.getResourceType(),
                 r.getResourceSuperType(),
-                DEFAULT_SERVLET_NAME,
+                DEFAULT_SERVLET_NAME, null,
                 resourceResolver);
 
         // 1. /foo/bar
@@ -416,7 +416,7 @@ public class LocationIteratorTest extend
         resourceResolver.setSearchPath(root0, root1);
         LocationIterator li = new LocationIterator("",
                 null,
-                "",
+                "", null,
                 resourceResolver);
         assertTrue(li.hasNext());
         assertEquals("/apps/", li.next());
@@ -431,7 +431,7 @@ public class LocationIteratorTest extend
         resourceResolver.setSearchPath(root0, root1);
         LocationIterator li = new LocationIterator("a/b",
                 null,
-                DEFAULT_SERVLET_NAME,
+                DEFAULT_SERVLET_NAME, null,
                 resourceResolver);
         assertTrue(li.hasNext());
         assertEquals(root0 + "/a/b", li.next());
@@ -450,7 +450,7 @@ public class LocationIteratorTest extend
         resourceResolver.setSearchPath(root0, root1);
         LocationIterator li = new LocationIterator("a/b",
                 "c/d",
-                DEFAULT_SERVLET_NAME,
+                DEFAULT_SERVLET_NAME, null,
                 resourceResolver);
         assertTrue(li.hasNext());
         assertEquals(root0 + "/a/b", li.next());
@@ -487,7 +487,7 @@ public class LocationIteratorTest extend
 
         LocationIterator li = new LocationIterator(resourceType,
                 resourceSuperType,
-                DEFAULT_SERVLET_NAME,
+                DEFAULT_SERVLET_NAME, null,
                 resourceResolver);
 
         // 1. /libs/foo/bar



Mime
View raw message