incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r813069 - in /sling/trunk/bundles/jcr/resource/src: main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver2.java test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver2Test.java
Date Wed, 09 Sep 2009 18:34:13 GMT
Author: fmeschbe
Date: Wed Sep  9 18:34:13 2009
New Revision: 813069

URL: http://svn.apache.org/viewvc?rev=813069&view=rev
Log:
SLING-1104 Ensure the resolutionPath and resolutionPathInfo properties
are correctly set in the resolveInternal method if the resource has
been resolved per sling:alias properties. Plus add unit tests.

Modified:
    sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver2.java
    sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver2Test.java

Modified: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver2.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver2.java?rev=813069&r1=813068&r2=813069&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver2.java
(original)
+++ sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver2.java
Wed Sep  9 18:34:13 2009
@@ -620,6 +620,7 @@
             // no direct resource found, so we have to drill down into the
             // resource tree to find a match
             resource = getResourceInternal("/");
+            StringBuilder resolutionPath = new StringBuilder();
             StringTokenizer tokener = new StringTokenizer(absPath, "/");
             while (resource != null && tokener.hasMoreTokens()) {
                 String childNameRaw = tokener.nextToken();
@@ -628,6 +629,7 @@
                 if (nextResource != null) {
 
                     resource = nextResource;
+                    resolutionPath.append("/").append(childNameRaw);
 
                 } else {
 
@@ -642,21 +644,30 @@
                     // switch the currentResource to the nextResource (may be
                     // null)
                     resource = nextResource;
+                    resolutionPath.append("/").append(childName);
 
-                    // SLING-627: set the part cut off from the uriPath as
-                    // sling.resolutionPathInfo property such that
-                    // uriPath = curPath + sling.resolutionPathInfo
+                    // terminate the search if a resource has been found
+                    // with the extension cut off
                     if (nextResource != null) {
-                        String path = ResourceUtil.normalize(ResourceUtil.getParent(
-                            nextResource).getPath()
-                            + "/" + childName);
-                        String pathInfo = absPath.substring(path.length());
-                        nextResource.getResourceMetadata().setResolutionPathInfo(
-                            pathInfo);
                         break;
                     }
                 }
             }
+
+            // SLING-627: set the part cut off from the uriPath as
+            // sling.resolutionPathInfo property such that
+            // uriPath = curPath + sling.resolutionPathInfo
+            if (resource != null) {
+                final String path = resolutionPath.toString();
+                final String pathInfo = absPath.substring(path.length());
+
+                resource.getResourceMetadata().setResolutionPath(path);
+                resource.getResourceMetadata().setResolutionPathInfo(pathInfo);
+
+                log.debug(
+                    "resolveInternal: Found resource {} with path info {} for {}",
+                    new Object[] { resource, pathInfo, absPath });
+            }
         }
 
         return resource;

Modified: sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver2Test.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver2Test.java?rev=813069&r1=813068&r2=813069&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver2Test.java
(original)
+++ sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver2Test.java
Wed Sep  9 18:34:13 2009
@@ -1041,10 +1041,10 @@
         String path = rootNode.getPath();
         String mapped = resResolver.map(path);
         assertEquals(path, mapped);
-        
+
         Node child = rootNode.addNode("child");
         session.save();
-        
+
         // absolute path, expect rootPath segment to be
         // cut off the mapped path because we map the rootPath
         // onto root
@@ -1053,15 +1053,15 @@
         mapped = resResolver.map(child.getPath() + selExt);
         assertEquals(path, mapped);
     }
-    
+
     public void testMapFragment() throws Exception {
         String path = rootNode.getPath();
         String mapped = resResolver.map(path);
         assertEquals(path, mapped);
-        
+
         Node child = rootNode.addNode("child");
         session.save();
-        
+
         // absolute path, expect rootPath segment to be
         // cut off the mapped path because we map the rootPath
         // onto root
@@ -1070,15 +1070,15 @@
         mapped = resResolver.map(child.getPath() + selExt);
         assertEquals(path, mapped);
     }
-    
+
     public void testMapQuery() throws Exception {
         String path = rootNode.getPath();
         String mapped = resResolver.map(path);
         assertEquals(path, mapped);
-        
+
         Node child = rootNode.addNode("child");
         session.save();
-        
+
         // absolute path, expect rootPath segment to be
         // cut off the mapped path because we map the rootPath
         // onto root
@@ -1087,15 +1087,15 @@
         mapped = resResolver.map(child.getPath() + selExt);
         assertEquals(path, mapped);
     }
-    
+
     public void testMapFragmentQuery() throws Exception {
         String path = rootNode.getPath();
         String mapped = resResolver.map(path);
         assertEquals(path, mapped);
-        
+
         Node child = rootNode.addNode("child");
         session.save();
-        
+
         // absolute path, expect rootPath segment to be
         // cut off the mapped path because we map the rootPath
         // onto root
@@ -1104,7 +1104,7 @@
         mapped = resResolver.map(child.getPath() + selExt);
         assertEquals(path, mapped);
     }
-    
+
     public void testMapExtensionFragmentQuery() throws Exception {
         String path = rootNode.getPath();
         String mapped = resResolver.map(path);
@@ -1122,7 +1122,155 @@
         assertEquals(path, mapped);
     }
 
-    public void testAlias() throws Exception {
+    public void test_resolve() throws Exception {
+
+        Node child = rootNode.addNode("child");
+        session.save();
+
+        // expect kind due to alias and no parent due to mapping
+        // the rootPath onto root
+        String path = "/child";
+        String mapped = resResolver.map(child.getPath());
+        assertEquals(path, mapped);
+
+        Resource res = resResolver.resolve(null, path);
+        assertNotNull(res);
+        assertEquals(rootNode.getPath() + "/child", res.getResourceMetadata().getResolutionPath());
+        assertEquals("", res.getResourceMetadata().getResolutionPathInfo());
+
+        Node resNode = res.adaptTo(Node.class);
+        assertNotNull(resNode);
+
+        assertEquals(child.getPath(), resNode.getPath());
+
+
+        // second level alias
+        Node grandchild = child.addNode("grandchild");
+        session.save();
+
+        // expect kind/enkel due to alias and no parent due to mapping
+        // the rootPath onto root
+        String pathEnkel = "/child/grandchild";
+        String mappedEnkel = resResolver.map(grandchild.getPath());
+        assertEquals(pathEnkel, mappedEnkel);
+
+        Resource resEnkel = resResolver.resolve(null, pathEnkel);
+        assertNotNull(resEnkel);
+        assertEquals(rootNode.getPath() + "/child/grandchild", resEnkel.getResourceMetadata().getResolutionPath());
+        assertEquals("", resEnkel.getResourceMetadata().getResolutionPathInfo());
+
+        Node resNodeEnkel = resEnkel.adaptTo(Node.class);
+        assertNotNull(resNodeEnkel);
+        assertEquals(grandchild.getPath(), resNodeEnkel.getPath());
+    }
+
+    public void test_resolve_extension() throws Exception {
+
+        final String selExt = ".html";
+
+        Node child = rootNode.addNode("child");
+        session.save();
+
+        // expect kind due to alias and no parent due to mapping
+        // the rootPath onto root
+        String path = "/child" + selExt;
+        String mapped = resResolver.map(child.getPath() + selExt);
+        assertEquals(path, mapped);
+
+        Resource res = resResolver.resolve(null, path);
+        assertNotNull(res);
+        assertEquals(rootNode.getPath() + "/child", res.getResourceMetadata().getResolutionPath());
+        assertEquals(selExt, res.getResourceMetadata().getResolutionPathInfo());
+
+        Node resNode = res.adaptTo(Node.class);
+        assertNotNull(resNode);
+        assertEquals(child.getPath(), resNode.getPath());
+
+
+        // second level alias
+        Node grandchild = child.addNode("grandchild");
+        session.save();
+
+        // expect kind/enkel due to alias and no parent due to mapping
+        // the rootPath onto root
+        String pathEnkel = "/child/grandchild" + selExt;
+        String mappedEnkel = resResolver.map(grandchild.getPath() + selExt);
+        assertEquals(pathEnkel, mappedEnkel);
+
+        Resource resEnkel = resResolver.resolve(null, pathEnkel);
+        assertNotNull(resEnkel);
+        assertEquals(rootNode.getPath() + "/child/grandchild", resEnkel.getResourceMetadata().getResolutionPath());
+        assertEquals(selExt, resEnkel.getResourceMetadata().getResolutionPathInfo());
+
+        Node resNodeEnkel = resEnkel.adaptTo(Node.class);
+        assertNotNull(resNodeEnkel);
+        assertEquals(grandchild.getPath(), resNodeEnkel.getPath());
+    }
+
+    public void test_resolve_selectors_extension() throws Exception {
+
+        final String selExt = ".sel1.sel2.html";
+
+        Node child = rootNode.addNode("child");
+        session.save();
+
+        // expect kind due to alias and no parent due to mapping
+        // the rootPath onto root
+        String path = "/child" + selExt;
+        String mapped = resResolver.map(child.getPath() + selExt);
+        assertEquals(path, mapped);
+
+        Resource res = resResolver.resolve(null, path);
+        assertNotNull(res);
+        assertEquals(rootNode.getPath() + "/child", res.getResourceMetadata().getResolutionPath());
+        assertEquals(selExt, res.getResourceMetadata().getResolutionPathInfo());
+
+        Node resNode = res.adaptTo(Node.class);
+        assertNotNull(resNode);
+        assertEquals(child.getPath(), resNode.getPath());
+
+        // second level alias
+        Node grandchild = child.addNode("grandchild");
+        session.save();
+
+        // expect kind/enkel due to alias and no parent due to mapping
+        // the rootPath onto root
+        String pathEnkel = "/child/grandchild" + selExt;
+        String mappedEnkel = resResolver.map(grandchild.getPath() + selExt);
+        assertEquals(pathEnkel, mappedEnkel);
+
+        Resource resEnkel = resResolver.resolve(null, pathEnkel);
+        assertNotNull(resEnkel);
+        assertEquals(rootNode.getPath() + "/child/grandchild", resEnkel.getResourceMetadata().getResolutionPath());
+        assertEquals(selExt, resEnkel.getResourceMetadata().getResolutionPathInfo());
+
+        Node resNodeEnkel = resEnkel.adaptTo(Node.class);
+        assertNotNull(resNodeEnkel);
+        assertEquals(grandchild.getPath(), resNodeEnkel.getPath());
+    }
+
+    public void test_resolve_extension_suffix() throws Exception {
+
+        final String selExt = ".html/some/suffx.pdf";
+
+        Node child = rootNode.addNode("child");
+        session.save();
+
+        // expect kind due to alias and no parent due to mapping
+        // the rootPath onto root
+        String path = "/child" + selExt;
+        String mapped = resResolver.map(child.getPath() + selExt);
+        assertEquals(path, mapped);
+
+        Resource res = resResolver.resolve(null, path);
+        Node resNode = res.adaptTo(Node.class);
+        assertNotNull(resNode);
+
+        assertEquals(child.getPath(), resNode.getPath());
+    }
+
+
+    public void test_resolve_with_sling_alias() throws Exception {
 
         Node child = rootNode.addNode("child");
         child.setProperty(JcrResourceResolver2.PROP_ALIAS, "kind");
@@ -1135,13 +1283,38 @@
         assertEquals(path, mapped);
 
         Resource res = resResolver.resolve(null, path);
+        assertNotNull(res);
+        assertEquals(rootNode.getPath() + "/kind", res.getResourceMetadata().getResolutionPath());
+        assertEquals("", res.getResourceMetadata().getResolutionPathInfo());
+
         Node resNode = res.adaptTo(Node.class);
         assertNotNull(resNode);
 
         assertEquals(child.getPath(), resNode.getPath());
+
+
+        // second level alias
+        Node grandchild = child.addNode("grandchild");
+        grandchild.setProperty(JcrResourceResolver2.PROP_ALIAS, "enkel");
+        session.save();
+
+        // expect kind/enkel due to alias and no parent due to mapping
+        // the rootPath onto root
+        String pathEnkel = "/kind/enkel";
+        String mappedEnkel = resResolver.map(grandchild.getPath());
+        assertEquals(pathEnkel, mappedEnkel);
+
+        Resource resEnkel = resResolver.resolve(null, pathEnkel);
+        assertNotNull(resEnkel);
+        assertEquals(rootNode.getPath() + "/kind/enkel", resEnkel.getResourceMetadata().getResolutionPath());
+        assertEquals("", resEnkel.getResourceMetadata().getResolutionPathInfo());
+
+        Node resNodeEnkel = resEnkel.adaptTo(Node.class);
+        assertNotNull(resNodeEnkel);
+        assertEquals(grandchild.getPath(), resNodeEnkel.getPath());
     }
 
-    public void testAliasExtension() throws Exception {
+    public void test_resolve_with_sling_alias_extension() throws Exception {
 
         final String selExt = ".html";
 
@@ -1156,13 +1329,37 @@
         assertEquals(path, mapped);
 
         Resource res = resResolver.resolve(null, path);
+        assertNotNull(res);
+        assertEquals(rootNode.getPath() + "/kind", res.getResourceMetadata().getResolutionPath());
+        assertEquals(selExt, res.getResourceMetadata().getResolutionPathInfo());
+
         Node resNode = res.adaptTo(Node.class);
         assertNotNull(resNode);
-
         assertEquals(child.getPath(), resNode.getPath());
+
+
+        // second level alias
+        Node grandchild = child.addNode("grandchild");
+        grandchild.setProperty(JcrResourceResolver2.PROP_ALIAS, "enkel");
+        session.save();
+
+        // expect kind/enkel due to alias and no parent due to mapping
+        // the rootPath onto root
+        String pathEnkel = "/kind/enkel" + selExt;
+        String mappedEnkel = resResolver.map(grandchild.getPath() + selExt);
+        assertEquals(pathEnkel, mappedEnkel);
+
+        Resource resEnkel = resResolver.resolve(null, pathEnkel);
+        assertNotNull(resEnkel);
+        assertEquals(rootNode.getPath() + "/kind/enkel", resEnkel.getResourceMetadata().getResolutionPath());
+        assertEquals(selExt, resEnkel.getResourceMetadata().getResolutionPathInfo());
+
+        Node resNodeEnkel = resEnkel.adaptTo(Node.class);
+        assertNotNull(resNodeEnkel);
+        assertEquals(grandchild.getPath(), resNodeEnkel.getPath());
     }
 
-    public void testAliasSelectorsExtension() throws Exception {
+    public void test_resolve_with_sling_alias_selectors_extension() throws Exception {
 
         final String selExt = ".sel1.sel2.html";
 
@@ -1177,13 +1374,36 @@
         assertEquals(path, mapped);
 
         Resource res = resResolver.resolve(null, path);
+        assertNotNull(res);
+        assertEquals(rootNode.getPath() + "/kind", res.getResourceMetadata().getResolutionPath());
+        assertEquals(selExt, res.getResourceMetadata().getResolutionPathInfo());
+
         Node resNode = res.adaptTo(Node.class);
         assertNotNull(resNode);
-
         assertEquals(child.getPath(), resNode.getPath());
+
+        // second level alias
+        Node grandchild = child.addNode("grandchild");
+        grandchild.setProperty(JcrResourceResolver2.PROP_ALIAS, "enkel");
+        session.save();
+
+        // expect kind/enkel due to alias and no parent due to mapping
+        // the rootPath onto root
+        String pathEnkel = "/kind/enkel" + selExt;
+        String mappedEnkel = resResolver.map(grandchild.getPath() + selExt);
+        assertEquals(pathEnkel, mappedEnkel);
+
+        Resource resEnkel = resResolver.resolve(null, pathEnkel);
+        assertNotNull(resEnkel);
+        assertEquals(rootNode.getPath() + "/kind/enkel", resEnkel.getResourceMetadata().getResolutionPath());
+        assertEquals(selExt, resEnkel.getResourceMetadata().getResolutionPathInfo());
+
+        Node resNodeEnkel = resEnkel.adaptTo(Node.class);
+        assertNotNull(resNodeEnkel);
+        assertEquals(grandchild.getPath(), resNodeEnkel.getPath());
     }
 
-    public void testAliasExtensionSuffix() throws Exception {
+    public void test_resolve_with_sling_alias_extension_suffix() throws Exception {
 
         final String selExt = ".html/some/suffx.pdf";
 



Mime
View raw message