incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
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 GMT
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 <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 @@
             // 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<Resource>() {
                     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;
+    }
 }



Mime
View raw message