sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject [sling-org-apache-sling-servlets-get] branch master updated: SLING-7593 : ResourceTraversor doesn't support ResourceDecorator pattern. Apply patch from Joanna Jasnowska and remove other deprecated methods usage
Date Tue, 24 Apr 2018 17:47:23 GMT
This is an automated email from the ASF dual-hosted git repository.

cziegeler pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-servlets-get.git


The following commit(s) were added to refs/heads/master by this push:
     new da32ee9  SLING-7593 : ResourceTraversor doesn't support ResourceDecorator pattern.
Apply patch from Joanna Jasnowska and remove other deprecated methods usage
da32ee9 is described below

commit da32ee94f18a3efe1bc048dd9f44dd600459dcd9
Author: Carsten Ziegeler <cziegele@adobe.com>
AuthorDate: Tue Apr 24 19:47:17 2018 +0200

    SLING-7593 : ResourceTraversor doesn't support ResourceDecorator pattern. Apply patch
from Joanna Jasnowska and remove other deprecated methods usage
---
 .../get/impl/helpers/PlainTextRendererServlet.java |  6 +++---
 .../get/impl/impl/info/SlingInfoServlet.java       |  1 -
 .../servlets/get/impl/util/JsonObjectCreator.java  |  9 ++++-----
 .../servlets/get/impl/util/ResourceTraversor.java  | 22 ++++++++++------------
 4 files changed, 17 insertions(+), 21 deletions(-)

diff --git a/src/main/java/org/apache/sling/servlets/get/impl/helpers/PlainTextRendererServlet.java
b/src/main/java/org/apache/sling/servlets/get/impl/helpers/PlainTextRendererServlet.java
index 714f60b..6a919a1 100644
--- a/src/main/java/org/apache/sling/servlets/get/impl/helpers/PlainTextRendererServlet.java
+++ b/src/main/java/org/apache/sling/servlets/get/impl/helpers/PlainTextRendererServlet.java
@@ -64,9 +64,9 @@ public class PlainTextRendererServlet extends SlingSafeMethodsServlet {
         if ( map != null ) {
             dump(pw, r, map);
         } else if ( r.adaptTo(String.class) != null ) {
-            printPropertyValue(pw, ResourceUtil.getName(r), r.adaptTo(String.class), false);
+            printPropertyValue(pw, r.getName(), r.adaptTo(String.class), false);
         } else if ( r.adaptTo(String[].class) != null ) {
-            printPropertyValue(pw, ResourceUtil.getName(r), r.adaptTo(String[].class), false);
+            printPropertyValue(pw, r.getName(), r.adaptTo(String[].class), false);
         } else {
             resp.sendError(HttpServletResponse.SC_NO_CONTENT);
         }
@@ -93,7 +93,7 @@ public class PlainTextRendererServlet extends SlingSafeMethodsServlet {
         pw.println("Resource metadata: " + r.getResourceMetadata());
         pw.println("Resource type: " + r.getResourceType());
 
-        String resourceSuperType = ResourceUtil.findResourceSuperType(r);
+        String resourceSuperType = r.getResourceResolver().getParentResourceType(r);
         if (resourceSuperType == null) {
             resourceSuperType = "-";
         }
diff --git a/src/main/java/org/apache/sling/servlets/get/impl/impl/info/SlingInfoServlet.java
b/src/main/java/org/apache/sling/servlets/get/impl/impl/info/SlingInfoServlet.java
index 42e8bbc..8e902c4 100644
--- a/src/main/java/org/apache/sling/servlets/get/impl/impl/info/SlingInfoServlet.java
+++ b/src/main/java/org/apache/sling/servlets/get/impl/impl/info/SlingInfoServlet.java
@@ -26,7 +26,6 @@ import java.util.Map;
 
 import javax.json.Json;
 import javax.json.JsonException;
-import javax.json.JsonWriter;
 import javax.json.stream.JsonGenerator;
 import javax.servlet.Servlet;
 import javax.servlet.http.HttpServletResponse;
diff --git a/src/main/java/org/apache/sling/servlets/get/impl/util/JsonObjectCreator.java
b/src/main/java/org/apache/sling/servlets/get/impl/util/JsonObjectCreator.java
index f37ef16..1c9971b 100644
--- a/src/main/java/org/apache/sling/servlets/get/impl/util/JsonObjectCreator.java
+++ b/src/main/java/org/apache/sling/servlets/get/impl/util/JsonObjectCreator.java
@@ -34,7 +34,6 @@ import javax.json.JsonObjectBuilder;
 import javax.json.JsonValue;
 
 import org.apache.sling.api.resource.Resource;
-import org.apache.sling.api.resource.ResourceUtil;
 import org.apache.sling.api.resource.ValueMap;
 
 public abstract class JsonObjectCreator {
@@ -66,7 +65,7 @@ public abstract class JsonObjectCreator {
             if (value != null) {
 
                 // single value property or just plain String resource or...
-                obj.add(ResourceUtil.getName(resource), value.toString());
+                obj.add(resource.getName(), value.toString());
 
             } else {
 
@@ -78,7 +77,7 @@ public abstract class JsonObjectCreator {
                     {
                         builder.add(v);
                     }
-                    obj.add(ResourceUtil.getName(resource), builder);
+                    obj.add(resource.getName(), builder);
                 }
 
             }
@@ -101,7 +100,7 @@ public abstract class JsonObjectCreator {
 
         // the child nodes
         if (recursionLevelActive(currentRecursionLevel, maxRecursionLevels)) {
-            final Iterator<Resource> children = ResourceUtil.listChildren(resource);
+            final Iterator<Resource> children = resource.listChildren();
             while (children.hasNext()) {
                 final Resource n = children.next();
                 createSingleResource(n, obj, currentRecursionLevel,
@@ -153,7 +152,7 @@ public abstract class JsonObjectCreator {
     private static void createSingleResource(final Resource n, final JsonObjectBuilder parent,
             final int currentRecursionLevel, final int maxRecursionLevels) {
         if (recursionLevelActive(currentRecursionLevel, maxRecursionLevels)) {
-            parent.add(ResourceUtil.getName(n), create(n, currentRecursionLevel + 1, maxRecursionLevels));
+            parent.add(n.getName(), create(n, currentRecursionLevel + 1, maxRecursionLevels));
         }
     }
 
diff --git a/src/main/java/org/apache/sling/servlets/get/impl/util/ResourceTraversor.java
b/src/main/java/org/apache/sling/servlets/get/impl/util/ResourceTraversor.java
index 5f6fecf..16998fa 100644
--- a/src/main/java/org/apache/sling/servlets/get/impl/util/ResourceTraversor.java
+++ b/src/main/java/org/apache/sling/servlets/get/impl/util/ResourceTraversor.java
@@ -30,7 +30,6 @@ import javax.json.JsonObjectBuilder;
 
 import org.apache.sling.api.request.RecursionTooDeepException;
 import org.apache.sling.api.resource.Resource;
-import org.apache.sling.api.resource.ResourceUtil;
 
 public class ResourceTraversor
 {
@@ -43,7 +42,7 @@ public class ResourceTraversor
             this.json = o;
         }
     }
-    
+
     Map<JsonObjectBuilder, List<Entry>> tree = new HashMap<>();
 
     private long count;
@@ -71,8 +70,8 @@ public class ResourceTraversor
         this.maxResources = maxResources;
         this.maxRecursionLevels = levels;
         this.startResource = resource;
-        currentQueue = new LinkedList<Entry>();
-        nextQueue = new LinkedList<Entry>();
+        currentQueue = new LinkedList<>();
+        nextQueue = new LinkedList<>();
         this.startObject = this.adapt(resource);
     }
 
@@ -100,7 +99,7 @@ public class ResourceTraversor
             int currentLevel) {
 
         if (maxRecursionLevels == -1 || currentLevel < maxRecursionLevels) {
-            final Iterator<Resource> children = ResourceUtil.listChildren(resource);
+            final Iterator<Resource> children = resource.listChildren();
             while (children.hasNext()) {
                 count++;
                 final Resource res = children.next();
@@ -126,12 +125,11 @@ public class ResourceTraversor
             return -1;
         }
 
-        List<Entry> entries = new ArrayList<>();
         while (!currentQueue.isEmpty() || !nextQueue.isEmpty()) {
             if (currentQueue.isEmpty()) {
                 currentLevel++;
                 currentQueue = nextQueue;
-                nextQueue = new LinkedList<Entry>();
+                nextQueue = new LinkedList<>();
             }
             final Entry nextResource = currentQueue.removeFirst();
             final int maxLevel = collectChildren(nextResource.resource, nextResource.json,
currentLevel);
@@ -161,22 +159,22 @@ public class ResourceTraversor
     }
 
     public JsonObject getJSONObject() {
-        
+
         return addChildren(startObject).build();
     }
-    
+
     private JsonObjectBuilder addChildren(JsonObjectBuilder builder) {
         List<Entry> children = tree.get(builder);
-        
+
         if (children != null)
         {
             for (Entry child : children) {
                 addChildren(child.json);
 
-                builder.add(ResourceUtil.getName(child.resource), child.json);
+                builder.add(child.resource.getName(), child.json);
             }
         }
-        
+
         return builder;
     }
 }

-- 
To stop receiving notification emails like this one, please contact
cziegeler@apache.org.

Mime
View raw message