incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r1210669 - in /sling/trunk/bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/helpers: JsonRendererServlet.java ResourceTraversor.java
Date Mon, 05 Dec 2011 22:14:50 GMT
Author: fmeschbe
Date: Mon Dec  5 22:14:50 2011
New Revision: 1210669

URL: http://svn.apache.org/viewvc?rev=1210669&view=rev
Log:
SLING-2320 Apply slightly modified patch by Jeff Young (thanks alot).
The change is from

  if (maxRecursionLevels == 1) {
  	// some comment
  } else if (count > maxResources) {
    throw new RecursionTooDeepException(String.valueOf(currentLevel));
  }

to

  if (count > maxResources && maxRecursionLevels > 1) {
    throw new RecursionTooDeepException(String.valueOf(currentLevel));
  }

Modified:
    sling/trunk/bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/helpers/JsonRendererServlet.java
    sling/trunk/bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/helpers/ResourceTraversor.java

Modified: sling/trunk/bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/helpers/JsonRendererServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/helpers/JsonRendererServlet.java?rev=1210669&r1=1210668&r2=1210669&view=diff
==============================================================================
--- sling/trunk/bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/helpers/JsonRendererServlet.java
(original)
+++ sling/trunk/bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/helpers/JsonRendererServlet.java
Mon Dec  5 22:14:50 2011
@@ -97,7 +97,7 @@ public class JsonRendererServlet extends
         ResourceTraversor traversor = null;
         try {
             traversor = new ResourceTraversor(maxRecursionLevels, maximumResults, r, tidy);
-            traversor.check();
+			traversor.collectResources();
         } catch (RecursionTooDeepException e) {
             allowDump = false;
             allowedLevel = Integer.parseInt(e.getMessage()); // this is to avoid depending
on a SNAPSHOT version of the SLing API.

Modified: sling/trunk/bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/helpers/ResourceTraversor.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/helpers/ResourceTraversor.java?rev=1210669&r1=1210668&r2=1210669&view=diff
==============================================================================
--- sling/trunk/bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/helpers/ResourceTraversor.java
(original)
+++ sling/trunk/bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/helpers/ResourceTraversor.java
Mon Dec  5 22:14:50 2011
@@ -56,27 +56,29 @@ public class ResourceTraversor {
   }
 
   /**
-   * Check if the resource has less child nodes for the specified amount of levels.
-   * 
+   * Recursive descent from startResource, collecting JSONObjects into startObject.
+   * Throws a RecursionTooDeepException if the maximum number of nodes is reached on a
+   * "deep" traversal (where "deep" === level greateer than 1).
+   *
    * @throws RepositoryException
    * @throws RecursionTooDeepException
    *           When the resource has more child nodes then allowed.
    * @throws JSONException
    */
-  public void check() throws RepositoryException, RecursionTooDeepException,
+  public void collectResources() throws RepositoryException, RecursionTooDeepException,
       JSONException {
-    checkResource(startResource, 0);
+    collectChildren(startResource, 0);
   }
 
   /**
-   * 
+   *
    * @param resource
    * @param currentLevel
    * @throws RecursionTooDeepException
    * @throws JSONException
    * @throws RepositoryException
    */
-  private void checkResource(Resource resource, int currentLevel)
+  private void collectChildren(Resource resource, int currentLevel)
       throws RecursionTooDeepException, JSONException, RepositoryException {
 
     if (maxRecursionLevels == -1 || currentLevel < maxRecursionLevels) {
@@ -84,8 +86,10 @@ public class ResourceTraversor {
       while (children.hasNext()) {
         count++;
         Resource res = children.next();
-        if (count > maxResources) {
-          throw new RecursionTooDeepException(String.valueOf(currentLevel));
+        // SLING-2320: always allow enumeration of one's children;
+        // DOS-limitation is for deeper traversals.
+        if (count > maxResources && maxRecursionLevels > 1) {
+            throw new RecursionTooDeepException(String.valueOf(currentLevel));
         }
         collectResource(res, currentLevel);
         nextQueue.addLast(res);
@@ -99,13 +103,13 @@ public class ResourceTraversor {
         nextQueue = new LinkedList<Resource>();
       }
       Resource nextResource = currentQueue.removeFirst();
-      checkResource(nextResource, currentLevel);
+      collectChildren(nextResource, currentLevel);
     }
   }
 
   /**
    * Adds a resource in the JSON tree.
-   * 
+   *
    * @param resource
    *          The resource to add
    * @param level
@@ -125,7 +129,7 @@ public class ResourceTraversor {
 
   /**
    * Adapt a Resource to a JSON Object.
-   * 
+   *
    * @param resource
    *          The resource to adapt.
    * @return The JSON representation of the Resource
@@ -140,7 +144,7 @@ public class ResourceTraversor {
 
   /**
    * Get the JSON Object where this resource should be added in.
-   * 
+   *
    * @param resource
    * @param level
    * @return



Mime
View raw message