Return-Path: Delivered-To: apmail-incubator-sling-commits-archive@locus.apache.org Received: (qmail 38568 invoked from network); 28 Jul 2008 10:50:59 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 28 Jul 2008 10:50:59 -0000 Received: (qmail 26553 invoked by uid 500); 28 Jul 2008 10:50:58 -0000 Delivered-To: apmail-incubator-sling-commits-archive@incubator.apache.org Received: (qmail 26520 invoked by uid 500); 28 Jul 2008 10:50:58 -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 26511 invoked by uid 99); 28 Jul 2008 10:50:58 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 28 Jul 2008 03:50:58 -0700 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; Mon, 28 Jul 2008 10:50:12 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 94B0923889E3; Mon, 28 Jul 2008 03:50:08 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r680317 - /incubator/sling/trunk/samples/fsresource/src/main/java/org/apache/sling/fsprovider/FsResourceProvider.java Date: Mon, 28 Jul 2008 10:50:08 -0000 To: sling-commits@incubator.apache.org From: fmeschbe@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080728105008.94B0923889E3@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: fmeschbe Date: Mon Jul 28 03:50:07 2008 New Revision: 680317 URL: http://svn.apache.org/viewvc?rev=680317&view=rev Log: SLING-583 Cleanup to consistently not return FsResource instances for directories "hiding" existing repository items. Modified: incubator/sling/trunk/samples/fsresource/src/main/java/org/apache/sling/fsprovider/FsResourceProvider.java Modified: incubator/sling/trunk/samples/fsresource/src/main/java/org/apache/sling/fsprovider/FsResourceProvider.java URL: http://svn.apache.org/viewvc/incubator/sling/trunk/samples/fsresource/src/main/java/org/apache/sling/fsprovider/FsResourceProvider.java?rev=680317&r1=680316&r2=680317&view=diff ============================================================================== --- incubator/sling/trunk/samples/fsresource/src/main/java/org/apache/sling/fsprovider/FsResourceProvider.java (original) +++ incubator/sling/trunk/samples/fsresource/src/main/java/org/apache/sling/fsprovider/FsResourceProvider.java Mon Jul 28 03:50:07 2008 @@ -94,36 +94,7 @@ * method returns null. */ public Resource getResource(ResourceResolver resourceResolver, String path) { - - // convert the path to a file - File file = getFile(path); - if (file != null) { - - // if the file is a directory, and a repository item exists for - // the path, do not return the directory here - if (file.isDirectory()) { - Session session = resourceResolver.adaptTo(Session.class); - if (session != null) { - try { - if (session.itemExists(path)) { - return null; - } - } catch (RepositoryException re) { - // don't care - } - } - } - - // if the file exists, but is not a directory or no repository entry - // exists, return it as a resource - if (file.exists()) { - return new FsResource(resourceResolver, path, file); - } - - } - - // not applicable or not an existing file path - return null; + return getResource(resourceResolver, path, getFile(path)); } /** @@ -137,19 +108,20 @@ // if the parent path is at or below the provider root, get // the respective file parentFile = getFile(parent.getPath()); - + // if the parent path is actually the parent of the provider // root, return a single element iterator just containing the // provider file, unless the provider file is a directory and // a repository item with the same path actually exists if (parentFile == null) { - + String parentPath = parent.getPath().concat("/"); if (providerRoot.startsWith(parentPath)) { String relPath = providerRoot.substring(parentPath.length()); if (relPath.indexOf('/') < 0) { Resource res = getResource( - parent.getResourceResolver(), providerRoot); + parent.getResourceResolver(), providerRoot, + providerFile); if (res != null) { return Collections.singletonList(res).iterator(); } @@ -171,8 +143,10 @@ return new Iterator() { int index = 0; + Resource next = seek(); + public boolean hasNext() { - return index < children.length; + return next != null; } public Resource next() { @@ -180,16 +154,28 @@ throw new NoSuchElementException(); } - File file = children[index]; - index++; - - return new FsResource(resolver, parentPath + "/" - + file.getName(), file); + Resource result = next; + next = seek(); + return result; } public void remove() { throw new UnsupportedOperationException("remove"); } + + private Resource seek() { + while (index < children.length) { + File file = children[index++]; + String path = parentPath + "/" + file.getName(); + Resource result = getResource(resolver, path, file); + if (result != null) { + return result; + } + } + + // nothing found any more + return null; + } }; } } @@ -275,4 +261,36 @@ return null; } + + private Resource getResource(ResourceResolver resourceResolver, + String resourcePath, File file) { + + if (file != null) { + + // if the file is a directory, and a repository item exists for + // the path, do not return the directory here + if (file.isDirectory()) { + Session session = resourceResolver.adaptTo(Session.class); + if (session != null) { + try { + if (session.itemExists(resourcePath)) { + return null; + } + } catch (RepositoryException re) { + // don't care + } + } + } + + // if the file exists, but is not a directory or no repository entry + // exists, return it as a resource + if (file.exists()) { + return new FsResource(resourceResolver, resourcePath, file); + } + + } + + // not applicable or not an existing file path + return null; + } }