incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jus...@apache.org
Subject svn commit: r991565 - in /sling/trunk: bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/helpers/ launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/
Date Wed, 01 Sep 2010 15:14:03 GMT
Author: justin
Date: Wed Sep  1 15:14:02 2010
New Revision: 991565

URL: http://svn.apache.org/viewvc?rev=991565&view=rev
Log:
SLING-1718 - adding support for multi-valued properties in html rendering

Modified:
    sling/trunk/bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/helpers/HtmlRendererServlet.java
    sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/PropertyRenderingTest.java

Modified: sling/trunk/bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/helpers/HtmlRendererServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/helpers/HtmlRendererServlet.java?rev=991565&r1=991564&r2=991565&view=diff
==============================================================================
--- sling/trunk/bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/helpers/HtmlRendererServlet.java
(original)
+++ sling/trunk/bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/helpers/HtmlRendererServlet.java
Wed Sep  1 15:14:02 2010
@@ -70,6 +70,11 @@ public class HtmlRendererServlet extends
             printResourceInfo(pw, r);
             render(pw, r, r.adaptTo(String.class));
             printEpilog(pw, isIncluded);
+        } else if ( r.adaptTo(String[].class) != null ) {
+            printProlog(pw, isIncluded);
+            printResourceInfo(pw, r);
+            render(pw, r, r.adaptTo(String[].class));
+            printEpilog(pw, isIncluded);
         } else {
             if ( !isIncluded ) {
                 resp.sendError(HttpServletResponse.SC_NO_CONTENT); // NO Content
@@ -127,6 +132,12 @@ public class HtmlRendererServlet extends
         printPropertyValue(pw, "Resource Value", value);
     }
 
+    private void render(PrintWriter pw, Resource r, String[] values) {
+        for (String value : values) {
+            printPropertyValue(pw, "Resource Value", value);
+        }
+    }
+
     private void printPropertyValue(PrintWriter pw, String name, Object value) {
 
         pw.print(name + ": <b>");

Modified: sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/PropertyRenderingTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/PropertyRenderingTest.java?rev=991565&r1=991564&r2=991565&view=diff
==============================================================================
--- sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/PropertyRenderingTest.java
(original)
+++ sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/PropertyRenderingTest.java
Wed Sep  1 15:14:02 2010
@@ -20,6 +20,7 @@ import java.io.IOException;
 import java.util.HashMap;
 import java.util.Map;
 
+import org.apache.sling.commons.testing.integration.NameValuePairList;
 import org.apache.sling.servlets.post.SlingPostConstants;
 
 /** Test the rendering of JCR Properties, directly addressed by URLs.
@@ -28,6 +29,9 @@ import org.apache.sling.servlets.post.Sl
 public class PropertyRenderingTest extends RenderingTestBase {
 
     private String slingResourceType;
+    
+    private String testMultiText1;
+    private String testMultiText2;
 
     @Override
     protected void setUp() throws Exception {
@@ -35,19 +39,27 @@ public class PropertyRenderingTest exten
 
         // set test values
         testText = "This is a test " + System.currentTimeMillis();
+        testMultiText1 = "This is a multivalued test " + System.currentTimeMillis();
+        testMultiText2 = "This is another multivalued test " + System.currentTimeMillis();
+        
         slingResourceType = getClass().getName();
 
         // create the test node, under a path that's specific to this class to allow collisions
         final String url = HTTP_BASE_URL + "/" + getClass().getSimpleName() + "/" + System.currentTimeMillis()
+ SlingPostConstants.DEFAULT_CREATE_SUFFIX;
-        final Map<String,String> props = new HashMap<String,String>();
-        props.put("sling:resourceType", slingResourceType);
-        props.put("text", testText);
-        displayUrl = testClient.createNode(url, props);
+        
+        NameValuePairList list = new NameValuePairList();
+        list.add("sling:resourceType", slingResourceType);
+        list.add("text", testText);
+        list.add("multiText", testMultiText1);
+        list.add("multiText", testMultiText2);
+        displayUrl = testClient.createNode(url, list, null, true);
     }
 
     public void testNodeAccess() throws IOException {
         final String json = getContent(displayUrl + ".json", CONTENT_TYPE_JSON);
         assertJavascript(testText, json, "out.println(data.text)");
+        assertJavascript(testMultiText1, json, "out.println(data.multiText[0])");
+        assertJavascript(testMultiText2, json, "out.println(data.multiText[1])");
     }
 
     public void testTextJson() throws IOException {
@@ -70,6 +82,18 @@ public class PropertyRenderingTest exten
         assertEquals(testText, data);
     }
 
+    public void testMultiValuedTextJson() throws IOException {
+        final String json = getContent(displayUrl + "/multiText.json", CONTENT_TYPE_JSON);
+        assertEquals("{\"multiText\":[\"" + testMultiText1 + "\",\""+ testMultiText2 + "\"]}",json);
+    }
+
+    public void testMultiValuedTextHtml() throws IOException {
+        final String data = getContent(displayUrl + "/multiText.html", CONTENT_TYPE_HTML);
+        System.out.println(data);
+        assertTrue(data.contains(testMultiText1));
+        assertTrue(data.contains(testMultiText2));
+    }
+
     public void testResourceTypeNoExt() throws IOException {
         final String data = getContent(displayUrl + "/sling:resourceType", null);
         assertEquals(slingResourceType, data);



Mime
View raw message