Return-Path: Delivered-To: apmail-incubator-sling-commits-archive@locus.apache.org Received: (qmail 37733 invoked from network); 8 Dec 2008 11:31:59 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 8 Dec 2008 11:31:59 -0000 Received: (qmail 11761 invoked by uid 500); 8 Dec 2008 11:32:11 -0000 Delivered-To: apmail-incubator-sling-commits-archive@incubator.apache.org Received: (qmail 11713 invoked by uid 500); 8 Dec 2008 11:32:11 -0000 Mailing-List: contact sling-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: sling-dev@incubator.apache.org Delivered-To: mailing list sling-commits@incubator.apache.org Received: (qmail 11704 invoked by uid 99); 8 Dec 2008 11:32:10 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 08 Dec 2008 03:32:10 -0800 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= 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; Mon, 08 Dec 2008 11:31:56 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 41185238889E; Mon, 8 Dec 2008 03:31:35 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r724311 - /incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/ResourceProviderEntry.java Date: Mon, 08 Dec 2008 11:31:34 -0000 To: sling-commits@incubator.apache.org From: fmeschbe@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20081208113135.41185238889E@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: fmeschbe Date: Mon Dec 8 03:31:34 2008 New Revision: 724311 URL: http://svn.apache.org/viewvc?rev=724311&view=rev Log: SLING-761 Provide synthetic resources for non-existing JCR resources where a descendant resource exists for the requested path. Also register all resources returned from the child resource iterator to ensure no duplicate resource is returned. Modified: incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/ResourceProviderEntry.java Modified: incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/ResourceProviderEntry.java URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/ResourceProviderEntry.java?rev=724311&r1=724310&r2=724311&view=diff ============================================================================== --- incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/ResourceProviderEntry.java (original) +++ incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/ResourceProviderEntry.java Mon Dec 8 03:31:34 2008 @@ -20,6 +20,7 @@ import java.util.Arrays; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashSet; import java.util.Map; @@ -130,6 +131,8 @@ private Resource nextResource; private Map delayed; + + private Set visited; private Iterator delayedIter; @@ -147,6 +150,7 @@ providers = providersSet.iterator(); delayed = new HashMap(); + visited = new HashSet(); nextResource = seek(); } @@ -178,20 +182,40 @@ if (resources != null && resources.hasNext()) { Resource res = resources.next(); - if (res instanceof SyntheticResource) { - delayed.put(res.getPath(), res); + String resPath = res.getPath(); + + if (visited.contains(resPath)) { + + // ignore a path, we have already visited and + // ensure it will not be listed as a delayed + // resource at the end + delayed.remove(resPath); + + } else if (res instanceof SyntheticResource) { + + // don't return synthetic resources right away, + // since a concrete resource for the same path + // may be provided later on + delayed.put(resPath, res); + } else { + + // we use this concrete, unvisited resource but + // mark it as visited + visited.add(resPath); return res; + } } else { break; } } + // we exhausted all resource providers with their concrete + // resources. now lets do the delayed (synthetic) resources if (delayedIter == null) { delayedIter = delayed.values().iterator(); } - return delayedIter.hasNext() ? delayedIter.next() : null; } }; @@ -337,7 +361,26 @@ } // no more specific provider, return mine - return getResourceProvider().getResource(resourceResolver, fullPath); + Resource resource = getResourceProvider().getResource(resourceResolver, fullPath); + + // there is no concrete resource for the requested path, so lets + // check whether one of the child provider entries is prefixed + // with the requested path. if so, a synthetic resource is + // returned for the requested path + if (resource == null && entries != null) { + String checkPath = path.concat("/"); + for (ResourceProviderEntry entry : entries) { + if (entry.path.startsWith(checkPath)) { + resource = new SyntheticResource(resourceResolver, fullPath, + ResourceProvider.RESOURCE_TYPE_SYNTHETIC); + + // don't look further + break; + } + } + } + + return resource; } // no match for my prefix, return null