incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r584807 - in /incubator/sling/whiteboard/microsling/src/main: java/org/apache/sling/microsling/contenttype/ java/org/apache/sling/microsling/requestcontext/ java/org/apache/sling/microsling/scripting/ java/org/apache/sling/microsling/servle...
Date Mon, 15 Oct 2007 15:36:53 GMT
Author: bdelacretaz
Date: Mon Oct 15 08:36:52 2007
New Revision: 584807

URL: http://svn.apache.org/viewvc?rev=584807&view=rev
Log:
SLING-49 : microsling: add a RequestFilter that computes the desired Content-Type for the
response

Added:
    incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/contenttype/
    incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/contenttype/ResponseContentTypeResolverFilter.java
  (with props)
Modified:
    incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/requestcontext/SlingRequestContext.java
    incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/scripting/SlingScriptResolver.java
    incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/servlet/MicroSlingServlet.java
    incubator/sling/whiteboard/microsling/src/main/webapp/index.html
    incubator/sling/whiteboard/microsling/src/main/webapp/server-side-javascript.html
    incubator/sling/whiteboard/microsling/src/main/webapp/velocity-scripts.html

Added: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/contenttype/ResponseContentTypeResolverFilter.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/contenttype/ResponseContentTypeResolverFilter.java?rev=584807&view=auto
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/contenttype/ResponseContentTypeResolverFilter.java
(added)
+++ incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/contenttype/ResponseContentTypeResolverFilter.java
Mon Oct 15 08:36:52 2007
@@ -0,0 +1,18 @@
+package org.apache.sling.microsling.contenttype;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.sling.microsling.api.RequestFilter;
+import org.apache.sling.microsling.requestcontext.SlingRequestContext;
+
+public class ResponseContentTypeResolverFilter implements RequestFilter {
+
+    /** Set the desired Content-Type for the response in the SlingRequestContext */
+    public void doFilter(HttpServletRequest req) throws Exception {
+        final SlingRequestContext ctx = SlingRequestContext.getFromRequest(req);
+        
+        // TODO: use the Accept HTTP header instead?
+        ctx.setResponseContentType(ctx.getMimeType("fakefile." + ctx.getExtension()));
+    }
+
+}

Propchange: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/contenttype/ResponseContentTypeResolverFilter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/contenttype/ResponseContentTypeResolverFilter.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Modified: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/requestcontext/SlingRequestContext.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/requestcontext/SlingRequestContext.java?rev=584807&r1=584806&r2=584807&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/requestcontext/SlingRequestContext.java
(original)
+++ incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/requestcontext/SlingRequestContext.java
Mon Oct 15 08:36:52 2007
@@ -32,6 +32,7 @@
     private final Session session;
     private final String contentPath;
     private final String extension;
+    private String responseContentType;
     private final ServletContext servletContext;
     private Resource resource;
     
@@ -95,6 +96,14 @@
         this.resource = resource;
     }
     
+    public void setResponseContentType(String responseContentType) {
+        this.responseContentType = responseContentType;
+    }
+
+    public String getResponseContentType() {
+        return responseContentType;
+    }
+
     /** Use the ServletContext to compute the mime-type for given filename */
     public String getMimeType(String filename) {
         return servletContext.getMimeType(filename);

Modified: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/scripting/SlingScriptResolver.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/scripting/SlingScriptResolver.java?rev=584807&r1=584806&r2=584807&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/scripting/SlingScriptResolver.java
(original)
+++ incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/scripting/SlingScriptResolver.java
Mon Oct 15 08:36:52 2007
@@ -42,7 +42,7 @@
     private static final Logger log = LoggerFactory.getLogger(SlingScriptResolver.class);
 
     public static final String SCRIPT_BASE_PATH = "/sling/scripts";
-
+    
     /** Try to find a script Node that can process the given request, based on the
      *  rules defined above.
      *  @return null if not found.
@@ -58,9 +58,9 @@
             return null;
         }
 
-        String extensionPart = "";
-        if(ctx.getExtension() != null && ctx.getExtension().length() > 0) {
-            extensionPart = "." + ctx.getExtension();
+        String contentTypePart = "";
+        if(ctx.getResponseContentType() != null && ctx.getResponseContentType().length()
> 0) {
+            contentTypePart = "." + filterStringForFilename(ctx.getResponseContentType());
         }
 
         final String scriptPath =
@@ -69,7 +69,7 @@
             + r.getResourceType()
             + "/"
             + req.getMethod().toLowerCase()
-            + extensionPart
+            + contentTypePart
             + "." + scriptExtension
         ;
 
@@ -92,5 +92,19 @@
         }
 
         return result;
+    }
+    
+    protected String filterStringForFilename(String inputString) {
+        final StringBuffer sb = new StringBuffer();
+        final String str = inputString.toLowerCase();
+        for(int i=0; i < str.length(); i++) {
+            final char c = str.charAt(i);
+            if(Character.isLetterOrDigit(c)) {
+                sb.append(c);
+            } else {
+                sb.append("_");
+            }
+        }
+        return sb.toString();
     }
 }

Modified: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/servlet/MicroSlingServlet.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/servlet/MicroSlingServlet.java?rev=584807&r1=584806&r2=584807&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/servlet/MicroSlingServlet.java
(original)
+++ incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/servlet/MicroSlingServlet.java
Mon Oct 15 08:36:52 2007
@@ -30,6 +30,7 @@
 import org.apache.sling.microsling.api.HttpStatusCodeException;
 import org.apache.sling.microsling.api.RequestFilter;
 import org.apache.sling.microsling.api.SlingServlet;
+import org.apache.sling.microsling.contenttype.ResponseContentTypeResolverFilter;
 import org.apache.sling.microsling.etc.HttpConstants;
 import org.apache.sling.microsling.requestcontext.SlingRequestContext;
 import org.apache.sling.microsling.resource.ResourceResolverFilter;
@@ -55,6 +56,7 @@
         try {
             // TODO use OSGi to setup this list
             requestFilters.add(new ResourceResolverFilter());
+            requestFilters.add(new ResponseContentTypeResolverFilter());
             
             // TODO use OSGi to setup this list 
             servlets.add(new SlingPostServlet());

Modified: incubator/sling/whiteboard/microsling/src/main/webapp/index.html
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/webapp/index.html?rev=584807&r1=584806&r2=584807&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/webapp/index.html (original)
+++ incubator/sling/whiteboard/microsling/src/main/webapp/index.html Mon Oct 15 08:36:52 2007
@@ -50,10 +50,21 @@
       <li>
         <a href="http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/RequestFilter.java?view=markup">RequestFilter</a>
          objects process the incoming requests before passing them on to SlingServlet objects
-        which do the actual processing. For now, the only RequestFilter is the 
-        <a href="http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/resource/ResourceResolverFilter.java?view=markup">ResourceResolverFilter</a>
which
-        selects the <a href="http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/Resource.java?view=markup">Resource</a>
(currently a JCR Node, OCM is not used yet) to process. Other filters would include
-        Locale selection, client capabilities analysis, etc.
+        which do the actual processing.
+        <ul>
+          <li>
+	      	The
+	        <a href="http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/resource/ResourceResolverFilter.java?view=markup">ResourceResolverFilter</a>
+	        selects the <a href="http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/Resource.java?view=markup">Resource</a>
(currently a JCR Node, OCM is not used yet) to process. 
+	      </li>
+	      <li>
+		      The <a href="http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/contenttype/ResponseContentTypeResolverFilter.java?view=markup">ResponseContentTypeResolverFilter</a>
+		      computes the desired <em>Content-Type</em> for the response, so that
rendering scripts or SlingServlets know what output format to generate.
+	      </li>
+	    </ul>
+	    	        Other filters would include
+	        Locale selection, client capabilities analysis, etc.
+	    
       </li>
       <li>
         After applying the RequestFilters, the MicroSlingServlet selects a 

Modified: incubator/sling/whiteboard/microsling/src/main/webapp/server-side-javascript.html
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/webapp/server-side-javascript.html?rev=584807&r1=584806&r2=584807&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/webapp/server-side-javascript.html (original)
+++ incubator/sling/whiteboard/microsling/src/main/webapp/server-side-javascript.html Mon
Oct 15 08:36:52 2007
@@ -22,7 +22,7 @@
   	To test this, remove or rename <a href="velocity-scripts.html">Velocity templates</a>
     if you played with them before (Velocity has priority due to the order in which the SlingServlet
classes
     are setup),  and store the script shown
-  	below under <em> /sling/scripts/microsling/example/get.html.js</em> in the
repository.
+  	below under <em> /sling/scripts/microsling/example/get.text_html.js</em> in
the repository.
   </p>
   <p>
   	Content nodes created with the <a href="content-creation-forms.html">Content creation
forms</a>
@@ -31,10 +31,11 @@
   </p>
   <p>
     As for the Velocity templates, other output formats can be generated, for example by
renaming the script 
-    to <em>get.txt.js</em> and modifying it to output plain text.
+    to <em>get.text_plain.js</em>, modifying it to output plain text and using
a <em>.txt</em> extension
+    in the request.
   </p>
   <p>
-  	Raw server-side javascript is probably more suited for handling POST and PUT requests
(that would be
+  	Raw server-side javascript is probably better suited for handling POST and PUT requests
(that would be
   	the <em>post.js</em> and <em>put.js</em> scripts), unless a suitable
templating library is used. 
   </p>
   <p>

Modified: incubator/sling/whiteboard/microsling/src/main/webapp/velocity-scripts.html
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/webapp/velocity-scripts.html?rev=584807&r1=584806&r2=584807&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/webapp/velocity-scripts.html (original)
+++ incubator/sling/whiteboard/microsling/src/main/webapp/velocity-scripts.html Mon Oct 15
08:36:52 2007
@@ -19,7 +19,7 @@
   </p>
   <p>
   	To test this, try storing (via WebDAV, see mount point URL on the microsling homepage)
the following script in your 
-  	repository under <em> /sling/scripts/microsling/example/get.html.vlt</em>.

+  	repository under <em> /sling/scripts/microsling/example/get.text_html.vlt</em>.

     Doing so will cause that script to be used
   	to render nodes having <em>slingResourceType=microsling/example</em>. 
   </p>
@@ -28,13 +28,13 @@
     and node and display it.
   </p>
   <p>
-  	 The name <em>get.html.vlt</em> indicates that this script is meant to process
HTTP GET requests with
-     an URL having an <em>html</em> extension.
+  	 The name <em>get.text_html.vlt</em> indicates that this script is meant to
process HTTP GET requests with
+  	 expect a <em>text/html</em> response.
   	 GET is probably the only request method that makes sense to process with Velocity, but
other
   	 script types might want to handle other HTTP methods. 
   </p>
   <p>
-    To generate XML instead, rename the script to <em>get.xml.vlt</em>, modify
it to generate
+    To generate XML instead, rename the script to <em>get.text_xml.vlt</em>,
modify it to generate
     the XML of your choice, and replace <em>.html</em> with <em>.xml</em>
at the end of the request URL.
   </p>
   <p>



Mime
View raw message