incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r1195981 - in /sling/trunk/bundles/jcr/resource/src: main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver.java test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverTest.java
Date Tue, 01 Nov 2011 13:16:30 GMT
Author: fmeschbe
Date: Tue Nov  1 13:16:30 2011
New Revision: 1195981

URL: http://svn.apache.org/viewvc?rev=1195981&view=rev
Log:
SLING-2258 Apply patch by Antonio Sanso (thanks alot). I have slightly modified the patch
to check for the suffix "/jcr:content" to prevent false positives for names like "xyzjcr:content"
(however unlikely that might be)

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

Modified: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver.java?rev=1195981&r1=1195980&r2=1195981&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver.java
(original)
+++ sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver.java
Tue Nov  1 13:16:30 2011
@@ -95,6 +95,12 @@ public class JcrResourceResolver
 
     public static final String PROP_REDIRECT_EXTERNAL_STATUS = "sling:status";
 
+    // The suffix of a resource being a content node of some parent
+    // such as nt:file. The slash is included to prevent false
+    // positives for the String.endsWith check for names like
+    // "xyzjcr:content"
+    private static final String JCR_CONTENT_LEAF = "/jcr:content";
+
     @SuppressWarnings("deprecation")
     private static final String DEFAULT_QUERY_LANGUAGE = Query.XPATH;
 
@@ -645,7 +651,7 @@ public class JcrResourceResolver
             String path = res.getPath();
             while ( path != null ) {
                 String alias = null;
-                if ( current != null && !path.endsWith("jcr:content")) {
+                if ( current != null && !path.endsWith(JCR_CONTENT_LEAF)) {
                     alias = getProperty(current, PROP_ALIAS);
                 }
                 if (alias == null || alias.length() == 0) {
@@ -1195,16 +1201,18 @@ public class JcrResourceResolver
         Iterator<Resource> children = listChildren(parent);
         while (children.hasNext()) {
             child = children.next();
-            String[] aliases = getProperty(child, PROP_ALIAS, String[].class);
-            if (aliases != null) {
-                for (String alias : aliases) {
-                    if (childName.equals(alias)) {
-                        LOGGER.debug(
-                            "getChildInternal: Found Resource {} with alias {} to use",
-                            child, childName);
-                        return child;
-                    }
-                }
+            if (!child.getPath().endsWith(JCR_CONTENT_LEAF)){
+            	String[] aliases = getProperty(child, PROP_ALIAS, String[].class);
+            	if (aliases != null) {
+            		for (String alias : aliases) {
+            			if (childName.equals(alias)) {
+            				LOGGER.debug(
+            						"getChildInternal: Found Resource {} with alias {} to use",
+            						child, childName);
+            				return child;
+            			}
+            		}
+            	}
             }
         }
 

Modified: sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverTest.java?rev=1195981&r1=1195980&r2=1195981&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverTest.java
(original)
+++ sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverTest.java
Tue Nov  1 13:16:30 2011
@@ -1304,6 +1304,19 @@ public class JcrResourceResolverTest ext
 
         assertNotNull(res.adaptTo(Node.class));
         assertTrue(rootNode.isSame(res.adaptTo(Node.class)));
+        
+        path = ResourceUtil.normalize(ResourceUtil.getParent(rootPath)
+                + "/" + alias + "/" + alias + ".print.html");
+        res = resResolver.resolve(request, path);
+        assertEquals("GET request resolution does not go up the path",
+                Resource.RESOURCE_TYPE_NON_EXISTING, res.getResourceType());
+        
+        Node child = rootNode.addNode("child", "nt:unstructured");
+        child.setProperty(JcrResourceResolver.PROP_ALIAS, alias);
+        session.save();
+        
+        res = resResolver.resolve(request, path);   
+        assertEquals(child.getPath(), res.getPath());
     }
 
     public void testResolveVanityPath() throws Exception {



Mime
View raw message