Return-Path: Delivered-To: apmail-sling-commits-archive@www.apache.org Received: (qmail 5645 invoked from network); 10 Sep 2009 15:11:14 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 10 Sep 2009 15:11:14 -0000 Received: (qmail 57440 invoked by uid 500); 10 Sep 2009 15:11:14 -0000 Delivered-To: apmail-sling-commits-archive@sling.apache.org Received: (qmail 57383 invoked by uid 500); 10 Sep 2009 15:11:14 -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 57374 invoked by uid 99); 10 Sep 2009 15:11:14 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 10 Sep 2009 15:11:14 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.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; Thu, 10 Sep 2009 15:11:11 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 69CDA23888D4; Thu, 10 Sep 2009 15:10:51 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@sling.apache.org From: cziegeler@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090910151051.69CDA23888D4@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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"));