This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to annotated tag org.apache.sling.fsresource-0.9.2-incubator in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-fsresource.git
commit 7ab3c812ffe64db8b9e9eb39c4b46b7b51a9e752 Author: Felix Meschberger <[email protected]> AuthorDate: Mon Jul 28 10:50:07 2008 +0000 SLING-583 Cleanup to consistently not return FsResource instances for directories "hiding" existing repository items. git-svn-id: https://svn.apache.org/repos/asf/incubator/sling/trunk/samples/fsresource@680317 13f79535-47bb-0310-9956-ffa450edef68 --- .../sling/fsprovider/FsResourceProvider.java | 96 +++++++++++++--------- 1 file changed, 57 insertions(+), 39 deletions(-) diff --git a/src/main/java/org/apache/sling/fsprovider/FsResourceProvider.java b/src/main/java/org/apache/sling/fsprovider/FsResourceProvider.java index f2a70f8..63c26ea 100644 --- a/src/main/java/org/apache/sling/fsprovider/FsResourceProvider.java +++ b/src/main/java/org/apache/sling/fsprovider/FsResourceProvider.java @@ -94,36 +94,7 @@ public class FsResourceProvider implements ResourceProvider { * method returns <code>null</code>. */ 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 @@ public class FsResourceProvider implements ResourceProvider { // 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 @@ public class FsResourceProvider implements ResourceProvider { return new Iterator<Resource>() { int index = 0; + Resource next = seek(); + public boolean hasNext() { - return index < children.length; + return next != null; } public Resource next() { @@ -180,16 +154,28 @@ public class FsResourceProvider implements ResourceProvider { 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 @@ public class FsResourceProvider implements ResourceProvider { 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; + } } -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
