Author: bdelacretaz
Date: Tue Dec 23 07:42:04 2008
New Revision: 729005

URL: http://svn.apache.org/viewvc?rev=729005&view=rev
Log:
SLING-795 - do not recurse into synthetic resources when generating a JSON dump

Modified:
    incubator/sling/trunk/   (props changed)
    
incubator/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/JsonRenderingTest.java
    
incubator/sling/trunk/servlets/get/src/main/java/org/apache/sling/servlets/get/helpers/JsonResourceWriter.java

Propchange: incubator/sling/trunk/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Tue Dec 23 07:42:04 2008
@@ -10,3 +10,4 @@
 .project
 .classpath
 .externalToolBuilders
+cachedir

Modified: 
incubator/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/JsonRenderingTest.java
URL: 
http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/JsonRenderingTest.java?rev=729005&r1=729004&r2=729005&view=diff
==============================================================================
--- 
incubator/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/JsonRenderingTest.java
 (original)
+++ 
incubator/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/JsonRenderingTest.java
 Tue Dec 23 07:42:04 2008
@@ -28,6 +28,7 @@
 /** Test creating Nodes and rendering them in JSON */
 public class JsonRenderingTest extends HttpTestBase {
 
+       private final String testPath = "/" + getClass().getSimpleName();
     private String postUrl;
 
     private String testText;
@@ -45,7 +46,7 @@
 
         // create the test node, under a path that's specific to this class to
         // allow collisions
-        postUrl = HTTP_BASE_URL + "/" + getClass().getSimpleName() + "_"
+        postUrl = HTTP_BASE_URL + testPath + "_"
             + System.currentTimeMillis()
             + SlingPostConstants.DEFAULT_CREATE_SUFFIX;
         final Map<String, String> props = new HashMap<String, String>();
@@ -212,4 +213,16 @@
        
        assertTrue("The .tidy selector should add at least 2 EOL chars to json 
output (delta=" + delta + ")", delta > min);
     }
+    
+    public void testRootNoRecursion() throws IOException {
+       final String json = getContent(HTTP_BASE_URL + "/.json", 
CONTENT_TYPE_JSON);
+       assertJavascript("rep:root", json, 
"out.print(data['jcr:primaryType'])");
+       assertJavascript("undefined", json, "out.print(typeof 
data['jcr:system'])");
+    }
+    
+    public void testRootWithRecursion() throws IOException {
+       final String json = getContent(HTTP_BASE_URL + "/.1.json", 
CONTENT_TYPE_JSON);
+       assertJavascript("rep:root", json, 
"out.print(data['jcr:primaryType'])");
+       assertJavascript("rep:system", json, 
"out.print(data['jcr:system']['jcr:primaryType'])");
+    }
 }
\ No newline at end of file

Modified: 
incubator/sling/trunk/servlets/get/src/main/java/org/apache/sling/servlets/get/helpers/JsonResourceWriter.java
URL: 
http://svn.apache.org/viewvc/incubator/sling/trunk/servlets/get/src/main/java/org/apache/sling/servlets/get/helpers/JsonResourceWriter.java?rev=729005&r1=729004&r2=729005&view=diff
==============================================================================
--- 
incubator/sling/trunk/servlets/get/src/main/java/org/apache/sling/servlets/get/helpers/JsonResourceWriter.java
 (original)
+++ 
incubator/sling/trunk/servlets/get/src/main/java/org/apache/sling/servlets/get/helpers/JsonResourceWriter.java
 Tue Dec 23 07:42:04 2008
@@ -132,7 +132,7 @@
     protected void dumpSingleResource(Resource n, JSONWriter w,
             int currentRecursionLevel, int maxRecursionLevels)
             throws JSONException {
-        if (recursionLevelActive(currentRecursionLevel, maxRecursionLevels)) {
+        if (recursionLevelActive(currentRecursionLevel, maxRecursionLevels) && 
!ResourceUtil.isSyntheticResource(n) ) {
             w.key(ResourceUtil.getName(n));
             dump(n, w, currentRecursionLevel + 1, maxRecursionLevels);
         }


Reply via email to