incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r599511 - in /incubator/sling/trunk/microsling/microsling-core/src: main/java/org/apache/sling/microsling/scripting/ main/java/org/apache/sling/microsling/scripting/helpers/ main/webapp/WEB-INF/ test/java/org/apache/sling/microsling/integra...
Date Thu, 29 Nov 2007 16:45:23 GMT
Author: bdelacretaz
Date: Thu Nov 29 08:45:19 2007
New Revision: 599511

URL: http://svn.apache.org/viewvc?rev=599511&view=rev
Log:
SLING-107 - for GET requests, use request extension instead of content-type to build script
name, using GET if no extension

Modified:
    incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/scripting/MicroslingScriptResolver.java
    incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/scripting/helpers/ScriptFilenameBuilder.java
    incubator/sling/trunk/microsling/microsling-core/src/main/webapp/WEB-INF/web.xml
    incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/MicroslingHttpTestBase.java
    incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/NodetypeRenderingTest.java
    incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/SlingResourceTypeRenderingTest.java
    incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/scripting/helpers/ScriptFilenameBuilderTest.java

Modified: incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/scripting/MicroslingScriptResolver.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/scripting/MicroslingScriptResolver.java?rev=599511&r1=599510&r2=599511&view=diff
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/scripting/MicroslingScriptResolver.java
(original)
+++ incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/scripting/MicroslingScriptResolver.java
Thu Nov 29 08:45:19 2007
@@ -167,7 +167,8 @@
         String scriptFilename = scriptFilenameBuilder.buildScriptFilename(
             request.getMethod(),
             request.getRequestPathInfo().getSelectorString(),
-            request.getResponseContentType(), "*");
+            request.getRequestPathInfo().getExtension(), 
+            "*");
         String scriptPath = scriptFilenameBuilder.buildScriptPath(r);
 
         // SLING-72: if the scriptfilename contains a relative path, move that

Modified: incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/scripting/helpers/ScriptFilenameBuilder.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/scripting/helpers/ScriptFilenameBuilder.java?rev=599511&r1=599510&r2=599511&view=diff
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/scripting/helpers/ScriptFilenameBuilder.java
(original)
+++ incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/scripting/helpers/ScriptFilenameBuilder.java
Thu Nov 29 08:45:19 2007
@@ -41,7 +41,7 @@
     public static final String SCRIPT_BASE_PATH = "/sling/scripts";
 
     /** @return a name like "html.js" or "print/a4/html.vlt" or "POST.js" */
-    public String buildScriptFilename(String methodName,String selectors,String contentType,String
scriptExtension) {
+    public String buildScriptFilename(String methodName,String selectors,String requestExtension,String
scriptExtension) {
         final StringBuffer sb = new StringBuffer();
 
         // path before filename:
@@ -57,15 +57,13 @@
             sb.append("NO_METHOD");
 
         } else if(HttpConstants.METHOD_GET.equalsIgnoreCase(methodName)) {
-            // for the GET method, use the simplified content-type, lowercased,
+            // for the GET method, use the request extension, lowercased,
             // as the filename.
             // TODO: how to handle HEAD?
-            if(contentType == null || contentType.length() == 0) {
-                sb.append("NO_CONTENT_TYPE");
+            if(requestExtension==null || requestExtension.length() == 0) {
+                sb.append(HttpConstants.METHOD_GET);
             } else {
-                // keep only what follows slash in the content-type
-                final String [] splitContentType = contentType.split("/");
-                sb.append(splitContentType[splitContentType.length - 1].toLowerCase());
+                sb.append(requestExtension.toLowerCase());
             }
 
         } else {

Modified: incubator/sling/trunk/microsling/microsling-core/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/main/webapp/WEB-INF/web.xml?rev=599511&r1=599510&r2=599511&view=diff
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/main/webapp/WEB-INF/web.xml (original)
+++ incubator/sling/trunk/microsling/microsling-core/src/main/webapp/WEB-INF/web.xml Thu Nov
29 08:45:19 2007
@@ -193,6 +193,10 @@
     <mime-type>application/vnd.ms-powerpoint</mime-type>
   </mime-mapping>
   <mime-mapping>
+    <extension>xls</extension>
+    <mime-type>application/vnd.ms-excel</mime-type>
+  </mime-mapping>  
+  <mime-mapping>
     <extension>vcd</extension>
     <mime-type>application/x-cdlink</mime-type>
   </mime-mapping>

Modified: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/MicroslingHttpTestBase.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/MicroslingHttpTestBase.java?rev=599511&r1=599510&r2=599511&view=diff
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/MicroslingHttpTestBase.java
(original)
+++ incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/MicroslingHttpTestBase.java
Thu Nov 29 08:45:19 2007
@@ -23,7 +23,6 @@
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.List;
-import java.util.Map;
 
 import junit.framework.TestCase;
 

Modified: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/NodetypeRenderingTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/NodetypeRenderingTest.java?rev=599511&r1=599510&r2=599511&view=diff
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/NodetypeRenderingTest.java
(original)
+++ incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/NodetypeRenderingTest.java
Thu Nov 29 08:45:19 2007
@@ -77,7 +77,7 @@
     }
 
     public void testEspPlain() throws IOException {
-        final String toDelete = uploadTestScript("rendering-test.esp","plain.esp");
+        final String toDelete = uploadTestScript("rendering-test.esp","txt.esp");
         try {
             final String content = getContent(displayUrl + ".txt", CONTENT_TYPE_PLAIN);
             assertTrue("Content includes ESP marker",content.contains("ESP template"));

Modified: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/SlingResourceTypeRenderingTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/SlingResourceTypeRenderingTest.java?rev=599511&r1=599510&r2=599511&view=diff
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/SlingResourceTypeRenderingTest.java
(original)
+++ incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/SlingResourceTypeRenderingTest.java
Thu Nov 29 08:45:19 2007
@@ -69,6 +69,41 @@
         }
     }
 
+    public void testEspHtmlUppercase() throws IOException {
+        final String toDelete = uploadTestScript("rendering-test.esp","html.esp");
+        try {
+            final String content = getContent(displayUrl + ".HTML", CONTENT_TYPE_HTML);
+            assertTrue("Content includes ESP marker",content.contains("ESP template"));
+            assertTrue("Content contains formatted test text",content.contains("<p>"
+ testText + "</p>"));
+        } finally {
+            testClient.delete(toDelete);
+        }
+    }
+
+    public void testEspNoExtension() throws IOException {
+        final String toDelete = uploadTestScript("rendering-test.esp","GET.esp");
+        try {
+            final String content = getContent(displayUrl, CONTENT_TYPE_PLAIN);
+            assertTrue("Content includes ESP marker",content.contains("ESP template"));
+            assertTrue("Content contains formatted test text",content.contains("<p>"
+ testText + "</p>"));
+        } finally {
+            testClient.delete(toDelete);
+        }
+    }
+
+    /** SLING-107, verify that extension is used instead of Content-Type for script name
*/
+    public void testEspJs() throws IOException {
+        final String toDelete = uploadTestScript("rendering-test.esp","js.esp");
+        try {
+            final String content = getContent(displayUrl + ".js", CONTENT_TYPE_JS);
+            // template makes no JS sense, that's not a problem for this test
+            assertTrue("Content includes ESP marker",content.contains("ESP template"));
+            assertTrue("Content contains formatted test text",content.contains("<p>"
+ testText + "</p>"));
+        } finally {
+            testClient.delete(toDelete);
+        }
+    }
+
     public void testEspXml() throws IOException {
         final String toDelete = uploadTestScript("rendering-test.esp","xml.esp");
         try {
@@ -81,7 +116,7 @@
     }
 
     public void testEspPlain() throws IOException {
-        final String toDelete = uploadTestScript("rendering-test.esp","plain.esp");
+        final String toDelete = uploadTestScript("rendering-test.esp","txt.esp");
         try {
             final String content = getContent(displayUrl + ".txt", CONTENT_TYPE_PLAIN);
             assertTrue("Content includes ESP marker",content.contains("ESP template"));

Modified: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/scripting/helpers/ScriptFilenameBuilderTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/scripting/helpers/ScriptFilenameBuilderTest.java?rev=599511&r1=599510&r2=599511&view=diff
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/scripting/helpers/ScriptFilenameBuilderTest.java
(original)
+++ incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/scripting/helpers/ScriptFilenameBuilderTest.java
Thu Nov 29 08:45:19 2007
@@ -36,11 +36,11 @@
     }
     
     public void testSimpleGet() {
-        assertEquals("html.js",builder.buildScriptFilename("GET",null,"text/html","js"));
+        assertEquals("html.js",builder.buildScriptFilename("GET",null,"html","js"));
     }
     
     public void testGetAndNulls() {
-        assertEquals("NO_CONTENT_TYPE.NO_EXT",builder.buildScriptFilename("GET",null,null,null));
+        assertEquals("GET.NO_EXT",builder.buildScriptFilename("GET",null,null,null));
     }
     
     public void testSimpleHead() {
@@ -48,31 +48,31 @@
     }
     
     public void testGetOneSelector() {
-        assertEquals("print/html.js",builder.buildScriptFilename("GET","print","text/html","js"));
+        assertEquals("print/html.js",builder.buildScriptFilename("GET","print","html","js"));
     }
     
     public void testGetTwoSelectors() {
-        assertEquals("print/a4/xml.vlt",builder.buildScriptFilename("GET","print.a4","text/xml","vlt"));
+        assertEquals("print/a4/xml.vlt",builder.buildScriptFilename("GET","print.a4","xml","vlt"));
     }
     
     public void testSimplePost() {
-        assertEquals("POST.js",builder.buildScriptFilename("POST",null,"text/html","js"));
+        assertEquals("POST.js",builder.buildScriptFilename("POST",null,"html","js"));
     }
     
     public void testSimplePut() {
-        assertEquals("PUT.js",builder.buildScriptFilename("PUT",null,"text/html","js"));
+        assertEquals("PUT.js",builder.buildScriptFilename("PUT",null,"html","js"));
     }
     
     public void testSimpleDelete() {
-        assertEquals("DELETE.js",builder.buildScriptFilename("DELETE",null,"text/html","js"));
+        assertEquals("DELETE.js",builder.buildScriptFilename("DELETE",null,"html","js"));
     }
     
     public void testGetTextMimeType() {
-        assertEquals("plain.js",builder.buildScriptFilename("GET",null,"text/plain","js"));
+        assertEquals("txt.js",builder.buildScriptFilename("GET",null,"txt","js"));
     }
     
     public void testGetWhateverMimeType() {
-        assertEquals("foo.js",builder.buildScriptFilename("GET",null,"whatever/Foo","js"));
+        assertEquals("whatever.js",builder.buildScriptFilename("GET",null,"whatever","js"));
     }
     
     public void testGetNoSlashMimeType() {
@@ -80,14 +80,14 @@
     }
     
     public void testCaseCleanupOne() {
-        assertEquals("POST.js",builder.buildScriptFilename("posT",null,"text/html","jS"));
+        assertEquals("POST.js",builder.buildScriptFilename("posT",null,"html","jS"));
     }
     
     public void testCaseCleanupTwo() {
-        assertEquals("html.js",builder.buildScriptFilename("get",null,"text/HTML","JS"));
+        assertEquals("html.js",builder.buildScriptFilename("get",null,"HTML","JS"));
     }
     
     public void testCaseCleanupThree() {
-        assertEquals("print/a4/html.js",builder.buildScriptFilename("get","PRInT.A4","text/HTML","JS"));
+        assertEquals("print/a4/html.js",builder.buildScriptFilename("get","PRInT.A4","HTML","JS"));
     }
 }



Mime
View raw message