incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r813472 - in /sling/trunk/bundles/api/src: main/java/org/apache/sling/api/resource/ResourceUtil.java test/java/org/apache/sling/api/resource/ResourceUtilTest.java
Date Thu, 10 Sep 2009 15:10:51 GMT
Author: cziegeler
Date: Thu Sep 10 15:10:50 2009
New Revision: 813472

URL: http://svn.apache.org/viewvc?rev=813472&view=rev
Log:
SLING-1107 - ResourceUtil.getResourceSuperType should check for overwritten resource super
type

Modified:
    sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceUtil.java
    sling/trunk/bundles/api/src/test/java/org/apache/sling/api/resource/ResourceUtilTest.java

Modified: sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceUtil.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceUtil.java?rev=813472&r1=813471&r2=813472&view=diff
==============================================================================
--- sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceUtil.java
(original)
+++ sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceUtil.java
Thu Sep 10 15:10:50 2009
@@ -346,13 +346,26 @@
                                               final String resourceType) {
         // normalize resource type to a path string
         final String rtPath = resourceTypeToPath(resourceType);
-        // get the resource type resource
-        final Resource rtResource = resourceResolver.getResource(rtPath);
-        // check for endless recursion
-        if ( rtResource != null ) {
-            return rtResource.getResourceSuperType();
+        // 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 Resource rtResource = resourceResolver.getResource(rtPath);
+            if ( rtResource != null ) {
+                resourceSuperType = rtResource.getResourceSuperType();
+            }
+
+        } else {
+            // if the path is relative we use the search paths
+            for(final String searchPath : resourceResolver.getSearchPath()) {
+                final Resource rtResource = resourceResolver.getResource(searchPath + rtPath);
+                if ( rtResource != null && rtResource.getResourceSuperType() != null
) {
+                    resourceSuperType = rtResource.getResourceSuperType();
+                    break;
+                }
+            }
         }
-        return null;
+        return resourceSuperType;
     }
 
     /**

Modified: sling/trunk/bundles/api/src/test/java/org/apache/sling/api/resource/ResourceUtilTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/api/src/test/java/org/apache/sling/api/resource/ResourceUtilTest.java?rev=813472&r1=813471&r2=813472&view=diff
==============================================================================
--- sling/trunk/bundles/api/src/test/java/org/apache/sling/api/resource/ResourceUtilTest.java
(original)
+++ sling/trunk/bundles/api/src/test/java/org/apache/sling/api/resource/ResourceUtilTest.java
Thu Sep 10 15:10:50 2009
@@ -277,6 +277,8 @@
             will(returnValue(typeResource));
             allowing(resolver).getResource("a/c");
             will(returnValue(null));
+            allowing(resolver).getSearchPath();
+            will(returnValue(new String[] {""}));
         }});
         assertEquals("t:c", ResourceUtil.getResourceSuperType(r.getResourceResolver(), r.getResourceType()));
         assertNull(ResourceUtil.getResourceSuperType(r2.getResourceResolver(), r2.getResourceType()));
@@ -306,6 +308,8 @@
             will(returnValue(null));
             allowing(resolver).getResource("d/e");
             will(returnValue(typeResource));
+            allowing(resolver).getSearchPath();
+            will(returnValue(new String[] {""}));
         }});
         assertTrue(ResourceUtil.isA(r, "a:b"));
         assertTrue(ResourceUtil.isA(r, "d:e"));



Mime
View raw message