Return-Path: X-Original-To: apmail-sling-commits-archive@www.apache.org Delivered-To: apmail-sling-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 24E347510 for ; Tue, 1 Nov 2011 13:16:55 +0000 (UTC) Received: (qmail 22094 invoked by uid 500); 1 Nov 2011 13:16:55 -0000 Delivered-To: apmail-sling-commits-archive@sling.apache.org Received: (qmail 22054 invoked by uid 500); 1 Nov 2011 13:16:54 -0000 Mailing-List: contact commits-help@sling.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@sling.apache.org Delivered-To: mailing list commits@sling.apache.org Received: (qmail 22047 invoked by uid 99); 1 Nov 2011 13:16:54 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 01 Nov 2011 13:16:54 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 01 Nov 2011 13:16:51 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id B6C47238890A; Tue, 1 Nov 2011 13:16:30 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@sling.apache.org From: fmeschbe@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20111101131630.B6C47238890A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 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 {