Author: cziegeler
Date: Thu Oct  5 09:51:24 2017
New Revision: 1811180

URL: http://svn.apache.org/viewvc?rev=1811180&view=rev
Log:
SLING-6878 : Bundle resource provider: support mounting of JSON files

Modified:
    
sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/BundleResourceIterator.java
    
sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/PathMapping.java

Modified: 
sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/BundleResourceIterator.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/BundleResourceIterator.java?rev=1811180&r1=1811179&r2=1811180&view=diff
==============================================================================
--- 
sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/BundleResourceIterator.java
 (original)
+++ 
sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/BundleResourceIterator.java
 Thu Oct  5 09:51:24 2017
@@ -65,7 +65,6 @@ class BundleResourceIterator implements
      * Creates an instance using the given parent bundle resource.
      */
     BundleResourceIterator(final BundleResource parent) {
-
         // trailing slash to enumerate children
         final String parentEntryPath = 
parent.getMappedPath().getEntryPath(parent.getPath().concat("/"));
         this.prefixLength = parentEntryPath.length();
@@ -123,6 +122,7 @@ class BundleResourceIterator implements
                 }
             }
         }
+
         return (bundleEntries.isEmpty() ? null : bundleEntries.iterator());
     }
 
@@ -167,7 +167,7 @@ class BundleResourceIterator implements
             }
 
             // another sanity check if the prefix is correct
-            int slash = entry.indexOf('/', prefixLength);
+            final int slash = entry.indexOf('/', prefixLength);
             if (slash < 0 || slash == entry.length() - 1) {
                 log.debug("seek: Using entry {}", entry);
                 final boolean isFolder = entry.endsWith("/");

Modified: 
sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/PathMapping.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/PathMapping.java?rev=1811180&r1=1811179&r2=1811180&view=diff
==============================================================================
--- 
sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/PathMapping.java
 (original)
+++ 
sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/PathMapping.java
 Thu Oct  5 09:51:24 2017
@@ -74,8 +74,8 @@ class PathMapping {
             final String expandDirective) {
         this.resourceRoot = ensureNoTrailingSlash(resourceRoot);
         this.resourceRootPrefix = ensureTrailingSlash(resourceRoot);
-        this.entryRoot = ensureNoTrailingSlash(entryRoot);
-        this.entryRootPrefix = ensureTrailingSlash(entryRoot);
+        this.entryRoot = ensureLeadingSlash(ensureNoTrailingSlash(entryRoot));
+        this.entryRootPrefix = 
ensureLeadingSlash(ensureTrailingSlash(entryRoot));
         this.jsonExpandExtension = ensureLeadingDot(expandDirective);
     }
 
@@ -164,6 +164,18 @@ class PathMapping {
         }
 
         return path;
+    }
+
+    private static String ensureLeadingSlash(final String path) {
+        if (path == null || path.length() == 0) {
+            return null;
+        }
+
+        if (!path.startsWith("/")) {
+            return "/".concat(path);
+        }
+
+        return path;
     }
 
     @Override


Reply via email to