incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From i..@apache.org
Subject svn commit: r936614 - /sling/trunk/bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/helpers/StreamRendererServlet.java
Date Thu, 22 Apr 2010 04:59:44 GMT
Author: ieb
Date: Thu Apr 22 04:59:44 2010
New Revision: 936614

URL: http://svn.apache.org/viewvc?rev=936614&view=rev
Log:
SLING-1496 fixes missing content type on directory listings where there is a resource.

Modified:
    sling/trunk/bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/helpers/StreamRendererServlet.java

Modified: sling/trunk/bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/helpers/StreamRendererServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/helpers/StreamRendererServlet.java?rev=936614&r1=936613&r2=936614&view=diff
==============================================================================
--- sling/trunk/bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/helpers/StreamRendererServlet.java
(original)
+++ sling/trunk/bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/helpers/StreamRendererServlet.java
Thu Apr 22 04:59:44 2010
@@ -176,38 +176,7 @@ public class StreamRendererServlet exten
 
             // set various response headers, unless the request is included
             if (!included) {
-                final ResourceMetadata meta = resource.getResourceMetadata();
-                final long modifTime = meta.getModificationTime();
-                if (modifTime > 0) {
-                    response.setDateHeader(HEADER_LAST_MODIFIED, modifTime);
-                }
-
-                final String defaultContentType = "application/octet-stream";
-                String contentType = meta.getContentType();
-                if (contentType == null || defaultContentType.equals(contentType)) {
-                    // if repository doesn't provide a content-type, or
-                    // provides the
-                    // default one,
-                    // try to do better using our servlet context
-                    final String ct = getServletContext().getMimeType(
-                        resource.getPath());
-                    if (ct != null) {
-                        contentType = ct;
-                    }
-                }
-                if (contentType != null) {
-                    response.setContentType(contentType);
-                }
-
-                String encoding = meta.getCharacterEncoding();
-                if (encoding != null) {
-                    response.setCharacterEncoding(encoding);
-                }
-
-                long length = meta.getContentLength();
-                if (length > 0 && length < Integer.MAX_VALUE) {
-                    response.setContentLength((int) length);
-                }
+                setHeaders(resource, response);
             }
 
             OutputStream out = response.getOutputStream();
@@ -260,6 +229,8 @@ public class StreamRendererServlet exten
                     dispatcher = request.getRequestDispatcher(fileRes, rdo);
                 }
 
+                setHeaders(fileRes, response);
+
                 dispatcher.include(request, response);
                 return;
             }
@@ -273,6 +244,49 @@ public class StreamRendererServlet exten
 
     }
 
+    /**
+     * @param resource
+     * @param request
+     * @param response
+     */
+    private void setHeaders(Resource resource, 
+            SlingHttpServletResponse response) {
+        
+        final ResourceMetadata meta = resource.getResourceMetadata();
+        final long modifTime = meta.getModificationTime();
+        if (modifTime > 0) {
+            response.setDateHeader(HEADER_LAST_MODIFIED, modifTime);
+        }
+
+        final String defaultContentType = "application/octet-stream";
+        String contentType = meta.getContentType();
+        if (contentType == null || defaultContentType.equals(contentType)) {
+            // if repository doesn't provide a content-type, or
+            // provides the
+            // default one,
+            // try to do better using our servlet context
+            final String ct = getServletContext().getMimeType(
+                resource.getPath());
+            if (ct != null) {
+                contentType = ct;
+            }
+        }
+        if (contentType != null) {
+            response.setContentType(contentType);
+        }
+
+        String encoding = meta.getCharacterEncoding();
+        if (encoding != null) {
+            response.setCharacterEncoding(encoding);
+        }
+
+        long length = meta.getContentLength();
+        if (length > 0 && length < Integer.MAX_VALUE) {
+            response.setContentLength((int) length);
+        }
+        
+    }
+
     private void renderIndex(Resource resource,
             SlingHttpServletResponse response) throws IOException {
 



Mime
View raw message