You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2017/09/08 14:58:06 UTC

svn commit: r1807776 - in /sling/trunk/bundles/extensions/bundleresource/src: main/java/org/apache/sling/bundleresource/impl/ test/java/org/apache/sling/bundleresource/impl/

Author: cziegeler
Date: Fri Sep  8 14:58:06 2017
New Revision: 1807776

URL: http://svn.apache.org/viewvc?rev=1807776&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/BundleResource.java
    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/BundleResourceProvider.java
    sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/BundleResourceTest.java

Modified: sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/BundleResource.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/BundleResource.java?rev=1807776&r1=1807775&r2=1807776&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/BundleResource.java (original)
+++ sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/BundleResource.java Fri Sep  8 14:58:06 2017
@@ -73,7 +73,6 @@ public class BundleResource extends Abst
             final BundleResourceCache cache,
             final MappedPath mappedPath,
             final String resourcePath,
-            final String propsPath,
             final Map<String, Object> readProps,
             final boolean isFolder) {
 
@@ -121,30 +120,33 @@ public class BundleResource extends Abst
                 }
             }
         }
-        if ( propsPath != null ) {
-            try {
-                final URL url = this.cache.getEntry(mappedPath.getEntryPath(propsPath));
-                if (url != null) {
-                    final JsonObject obj = Json.createReader(url.openStream()).readObject();
-                    for(final Map.Entry<String, JsonValue> entry : obj.entrySet()) {
-                        final Object value = getValue(entry.getValue(), true);
-                        if ( value != null ) {
-                            if ( value instanceof Map ) {
-                                if ( children == null ) {
-                                    children = new HashMap<>();
+        if ( this.mappedPath.getJSONPropertiesExtension() != null ) {
+            final String propsPath = mappedPath.getEntryPath(resourcePath.concat(this.mappedPath.getJSONPropertiesExtension()));
+            if ( propsPath != null ) {
+
+                try {
+                    final URL url = this.cache.getEntry(propsPath);
+                    if (url != null) {
+                        final JsonObject obj = Json.createReader(url.openStream()).readObject();
+                        for(final Map.Entry<String, JsonValue> entry : obj.entrySet()) {
+                            final Object value = getValue(entry.getValue(), true);
+                            if ( value != null ) {
+                                if ( value instanceof Map ) {
+                                    if ( children == null ) {
+                                        children = new HashMap<>();
+                                    }
+                                    children.put(entry.getKey(), (Map<String, Object>)value);
+                                } else {
+                                    properties.put(entry.getKey(), value);
                                 }
-                                children.put(entry.getKey(), (Map<String, Object>)value);
-                            } else {
-                                properties.put(entry.getKey(), value);
                             }
                         }
                     }
+                } catch (final IOException ioe) {
+                    log.error(
+                            "getInputStream: Cannot get input stream for " + propsPath, ioe);
                 }
-            } catch (final IOException ioe) {
-                log.error(
-                        "getInputStream: Cannot get input stream for " + mappedPath.getEntryPath(propsPath), ioe);
             }
-
         }
         this.subResources = children;
     }
@@ -158,7 +160,7 @@ public class BundleResource extends Abst
                 final Map<String, Object> props = resources.get(segment);
                 if ( props != null ) {
                     result = new BundleResource(this.resourceResolver, this.cache, this.mappedPath,
-                            path, path.concat(this.mappedPath.getJSONPropertiesExtension()), props, false);
+                            path, props, false);
                     resources = ((BundleResource)result).subResources;
                 } else {
                     result = null;

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=1807776&r1=1807775&r2=1807776&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 Fri Sep  8 14:58:06 2017
@@ -169,14 +169,9 @@ class BundleResourceIterator implements
             if (slash < 0 || slash == entry.length() - 1) {
                 log.debug("seek: Using entry {}", entry);
                 final boolean isFolder = entry.endsWith("/");
-                String propsPath = null;
-                if ( mappedPath.getJSONPropertiesExtension() != null ) {
-                    propsPath = entry.concat(mappedPath.getJSONPropertiesExtension());
-                }
                 final String entryPath = isFolder ? entry.substring(0, entry.length()-1) : entry;
                 return new BundleResource(resourceResolver, cache, mappedPath,
                         entryPath,
-                        propsPath,
                         this.subResources != null ? this.subResources.get(ResourceUtil.getName(entryPath)) : null,
                         isFolder);
             }

Modified: sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/BundleResourceProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/BundleResourceProvider.java?rev=1807776&r1=1807775&r2=1807776&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/BundleResourceProvider.java (original)
+++ sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/BundleResourceProvider.java Fri Sep  8 14:58:06 2017
@@ -117,15 +117,10 @@ public class BundleResourceProvider exte
                 if ( this.root.getJSONPropertiesExtension() == null
                      || !entryPath.endsWith(this.root.getJSONPropertiesExtension()) ) {
 
-                    String propsPath = null;
-                    if ( this.root.getJSONPropertiesExtension() != null ) {
-                        propsPath = entryPath.concat(this.root.getJSONPropertiesExtension());
-                    }
                     return new BundleResource(ctx.getResourceResolver(),
                             cache,
                             mappedPath,
                             path,
-                            propsPath,
                             null,
                             isFolder);
                 }

Modified: sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/BundleResourceTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/BundleResourceTest.java?rev=1807776&r1=1807775&r2=1807776&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/BundleResourceTest.java (original)
+++ sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/BundleResourceTest.java Fri Sep  8 14:58:06 2017
@@ -72,7 +72,7 @@ public class BundleResourceTest {
         final BundleResourceCache cache = getBundleResourceCache();
         when(cache.getEntry("/libs/foo/test.json")).thenReturn(new URL("file:/libs/foo/test.json"));
         final BundleResource rsrc = new BundleResource(null, cache,
-                new MappedPath("/libs/foo", null, null), "/libs/foo/test.json", null, null, false);
+                new MappedPath("/libs/foo", null, null), "/libs/foo/test.json", null, false);
         assertEquals(JcrConstants.NT_FILE, rsrc.getResourceType());
         assertNull(rsrc.getResourceSuperType());
         final ValueMap vm = rsrc.getValueMap();
@@ -83,7 +83,7 @@ public class BundleResourceTest {
         final BundleResourceCache cache = getBundleResourceCache();
         addContent(cache, "/libs/foo/test.json", Collections.singletonMap("test", (Object)"foo"));
         final BundleResource rsrc = new BundleResource(null, cache,
-                new MappedPath("/libs/foo", null, "json"), "/libs/foo/test", "/libs/foo/test.json", null, false);
+                new MappedPath("/libs/foo", null, "json"), "/libs/foo/test", null, false);
         assertEquals(JcrConstants.NT_FILE, rsrc.getResourceType());
         assertNull(rsrc.getResourceSuperType());
         final ValueMap vm = rsrc.getValueMap();