incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r618936 - in /incubator/sling/trunk: commons/json/src/main/java/org/apache/sling/commons/json/io/ launchpad/launchpad-servlets/src/main/java/org/apache/sling/launchpad/renderers/ launchpad/launchpad-webapp/src/test/java/org/apache/sling/lau...
Date Wed, 06 Feb 2008 09:37:47 GMT
Author: bdelacretaz
Date: Wed Feb  6 01:37:45 2008
New Revision: 618936

URL: http://svn.apache.org/viewvc?rev=618936&view=rev
Log:
SLING-167 - 'infinity' recursion level implemented for JSON output

Modified:
    incubator/sling/trunk/commons/json/src/main/java/org/apache/sling/commons/json/io/JSONWriter.java
    incubator/sling/trunk/launchpad/launchpad-servlets/src/main/java/org/apache/sling/launchpad/renderers/JsonRendererServlet.java
    incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/JsonRenderingTest.java

Modified: incubator/sling/trunk/commons/json/src/main/java/org/apache/sling/commons/json/io/JSONWriter.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/commons/json/src/main/java/org/apache/sling/commons/json/io/JSONWriter.java?rev=618936&r1=618935&r2=618936&view=diff
==============================================================================
--- incubator/sling/trunk/commons/json/src/main/java/org/apache/sling/commons/json/io/JSONWriter.java
(original)
+++ incubator/sling/trunk/commons/json/src/main/java/org/apache/sling/commons/json/io/JSONWriter.java
Wed Feb  6 01:37:45 2008
@@ -60,7 +60,9 @@
  * @version 2
  */
 public class JSONWriter {
-    private static final int maxdepth = 20;
+    // This was previously 20 - increased while creating
+    // the JsonRenderingTest.testRecursiveInfinity test
+    private static final int maxdepth = 50;
 
     /**
      * The comma flag determines if a comma should be output before the next
@@ -267,7 +269,7 @@
      */
     private void push(char c) throws JSONException {
         if (this.top >= maxdepth) {
-            throw new JSONException("Nesting too deep.");
+            throw new JSONException("Nesting too deep (maximum is " + maxdepth + " levels)");
         }
         this.stack[this.top] = c;
         this.mode = c;

Modified: incubator/sling/trunk/launchpad/launchpad-servlets/src/main/java/org/apache/sling/launchpad/renderers/JsonRendererServlet.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/launchpad-servlets/src/main/java/org/apache/sling/launchpad/renderers/JsonRendererServlet.java?rev=618936&r1=618935&r2=618936&view=diff
==============================================================================
--- incubator/sling/trunk/launchpad/launchpad-servlets/src/main/java/org/apache/sling/launchpad/renderers/JsonRendererServlet.java
(original)
+++ incubator/sling/trunk/launchpad/launchpad-servlets/src/main/java/org/apache/sling/launchpad/renderers/JsonRendererServlet.java
Wed Feb  6 01:37:45 2008
@@ -46,6 +46,9 @@
     private static final long serialVersionUID = 5577121546674133317L;
     private final String responseContentType;
     private final JsonItemWriter itemWriter;
+    
+    /** Recursion level selector that means "all levels" */
+    public static final String INFINITY = "infinity";
 
     public JsonRendererServlet(String responseContentTypeHeaderValue) {
         this.responseContentType = responseContentTypeHeaderValue;
@@ -97,12 +100,16 @@
         final String [] selectors = req.getRequestPathInfo().getSelectors();
         if(selectors != null && selectors.length > 0) {
             String level = selectors[selectors.length - 1];
-            try {
-                maxRecursionLevels = Integer.parseInt(level);
-            } catch(NumberFormatException nfe) {
-                resp.sendError(HttpServletResponse.SC_BAD_REQUEST,
-                    "Invalid recursion selector value '" + level + "'");
-                return;
+            if(INFINITY.equals(level)) {
+                maxRecursionLevels = -1;
+            } else {
+                try {
+                    maxRecursionLevels = Integer.parseInt(level);
+                } catch(NumberFormatException nfe) {
+                    resp.sendError(HttpServletResponse.SC_BAD_REQUEST,
+                        "Invalid recursion selector value '" + level + "'");
+                    return;
+                }
             }
         }
 

Modified: incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/JsonRenderingTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/JsonRenderingTest.java?rev=618936&r1=618935&r2=618936&view=diff
==============================================================================
--- incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/JsonRenderingTest.java
(original)
+++ incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/JsonRenderingTest.java
Wed Feb  6 01:37:45 2008
@@ -103,6 +103,17 @@
         }
     }
     
+    /** Test the "infinity" recursion level */
+    public void testRecursiveInfinity() throws IOException {
+        final Map<String,String> props = new HashMap<String,String>();
+        props.put("text", testText);
+        props.put("a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y", "yes");
+        final String url = testClient.createNode(postUrl, props);
+        final String json = getContent(url + ".infinity.json", CONTENT_TYPE_JSON);
+        assertJavascript(testText, json, "out.print(data.text)");
+        assertJavascript("yes", json, "out.print(data.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y)");
+    }
+    
     public void testInvalidLevel() throws IOException {
         assertHttpStatus(createdNodeUrl + ".notAnIntegerOnPurpose.json", HttpServletResponse.SC_BAD_REQUEST);
     }



Mime
View raw message