tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject svn commit: r732879 - in /tapestry/tapestry5/trunk/tapestry-core/src: main/java/org/apache/tapestry5/internal/services/ main/java/org/apache/tapestry5/internal/test/ main/java/org/apache/tapestry5/services/ test/java/org/apache/tapestry5/internal/servi...
Date Fri, 09 Jan 2009 00:10:09 GMT
Author: hlship
Date: Thu Jan  8 16:10:08 2009
New Revision: 732879

URL: http://svn.apache.org/viewvc?rev=732879&view=rev
Log:
TAP5-411: Tapestry should be using ServletContext.getMimeType() to map from file extensions
to MIME types

Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ContextImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceStreamerImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/test/PageTesterContext.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/Context.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ResourceStreamerImplTest.java

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ContextImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ContextImpl.java?rev=732879&r1=732878&r2=732879&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ContextImpl.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ContextImpl.java
Thu Jan  8 16:10:08 2009
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2008 The Apache Software Foundation
+// Copyright 2006, 2007, 2008, 2009 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -86,7 +86,6 @@
                 if (match.endsWith("/")) queue.push(match);
                 else result.add(match);
             }
-
         }
 
         Collections.sort(result);
@@ -104,4 +103,8 @@
         return InternalUtils.toList(servletContext.getAttributeNames());
     }
 
+    public String getMimeType(String file)
+    {
+        return servletContext.getMimeType(file);
+    }
 }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceStreamerImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceStreamerImpl.java?rev=732879&r1=732878&r2=732879&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceStreamerImpl.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceStreamerImpl.java
Thu Jan  8 16:10:08 2009
@@ -21,6 +21,7 @@
 import org.apache.tapestry5.ioc.annotations.Symbol;
 import org.apache.tapestry5.ioc.internal.util.InternalUtils;
 import org.apache.tapestry5.ioc.util.TimeInterval;
+import org.apache.tapestry5.services.Context;
 import org.apache.tapestry5.services.Request;
 import org.apache.tapestry5.services.Response;
 import org.apache.tapestry5.services.ResponseCompressionAnalyzer;
@@ -40,23 +41,35 @@
 
     private final Response response;
 
+    private final Context context;
+
     private final ResponseCompressionAnalyzer analyzer;
 
     private final Map<String, String> configuration;
 
     private final int compressionCutoff;
 
-    public ResourceStreamerImpl(Request request, Response response, ResourceCache resourceCache,
+    public ResourceStreamerImpl(Request request,
+
+                                Response response,
+
+                                Context context,
+
+                                ResourceCache resourceCache,
+
                                 Map<String, String> configuration,
+
                                 ResponseCompressionAnalyzer analyzer,
 
                                 @Symbol(SymbolConstants.MIN_GZIP_SIZE)
                                 int compressionCutoff)
+
     {
+        this.request = request;
         this.response = response;
+        this.context = context;
         this.resourceCache = resourceCache;
         this.configuration = configuration;
-        this.request = request;
         this.analyzer = analyzer;
         this.compressionCutoff = compressionCutoff;
     }
@@ -115,21 +128,24 @@
 
         if ("content/unknown".equals(contentType)) contentType = null;
 
-        if (contentType == null)
-        {
-            String file = resource.getFile();
-            int dotx = file.lastIndexOf('.');
+        if (contentType != null) return contentType;
 
-            if (dotx > 0)
-            {
-                String extension = file.substring(dotx + 1);
+        contentType = context.getMimeType(resource.getPath());
 
-                contentType = configuration.get(extension);
-            }
+        if (contentType != null) return contentType;
+
+        String file = resource.getFile();
+        int dotx = file.lastIndexOf('.');
+
+        if (dotx > 0)
+        {
+            String extension = file.substring(dotx + 1);
 
-            if (contentType == null) contentType = "application/octet-stream";
+            contentType = configuration.get(extension);
         }
 
-        return contentType;
+        return contentType != null
+               ? contentType
+               : "application/octet-stream";
     }
 }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/test/PageTesterContext.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/test/PageTesterContext.java?rev=732879&r1=732878&r2=732879&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/test/PageTesterContext.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/test/PageTesterContext.java
Thu Jan  8 16:10:08 2009
@@ -1,4 +1,4 @@
-// Copyright 2007, 2008 The Apache Software Foundation
+// Copyright 2007, 2008, 2009 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -70,6 +70,11 @@
         return Collections.emptyList();
     }
 
+    public String getMimeType(String file)
+    {
+        return null;
+    }
+
     /**
      * Always returns null.
      */

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/Context.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/Context.java?rev=732879&r1=732878&r2=732879&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/Context.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/Context.java
Thu Jan  8 16:10:08 2009
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2008 The Apache Software Foundation
+// Copyright 2006, 2007, 2008, 2009 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -69,4 +69,14 @@
      * Returns the names of all attributes of the context, sorted alphabetically.
      */
     List<String> getAttributeNames();
+
+    /**
+     * Returns the MIME content type of the specified file, or null if no content type is
known. MIME types are built-in
+     * to servlet containers and may be futher specified via the web application deployment
descriptor.
+     *
+     * @param file name of file
+     * @return the presumed MIME content type, or null if not known
+     * @since 5.1.0.0
+     */
+    String getMimeType(String file);
 }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ResourceStreamerImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ResourceStreamerImplTest.java?rev=732879&r1=732878&r2=732879&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ResourceStreamerImplTest.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ResourceStreamerImplTest.java
Thu Jan  8 16:10:08 2009
@@ -18,9 +18,7 @@
 import org.apache.tapestry5.internal.test.InternalBaseTestCase;
 import org.apache.tapestry5.ioc.Resource;
 import org.apache.tapestry5.ioc.internal.util.ClasspathResource;
-import org.apache.tapestry5.services.Request;
-import org.apache.tapestry5.services.RequestGlobals;
-import org.apache.tapestry5.services.Response;
+import org.apache.tapestry5.services.*;
 import static org.easymock.EasyMock.*;
 import org.testng.annotations.Test;
 
@@ -37,26 +35,27 @@
     @Test
     public void content_type_css() throws IOException
     {
-        content_type("text/css", "test.css");
+        content_type("text/css", "test.css", true);
     }
 
     @Test
     public void content_type_js() throws IOException
     {
-        content_type("text/javascript", "test.js");
+        content_type("text/javascript", "test.js", true);
     }
 
     @Test
     public void content_type_gif() throws IOException
     {
-        content_type("image/gif", "test.gif");
+        content_type("image/gif", "test.gif", false);
     }
 
-    private void content_type(String contentType, String fileName) throws IOException
+    private void content_type(String contentType, String fileName, boolean consultsContext)
throws IOException
     {
         Request request = mockRequest();
         HttpServletRequest hsRequest = mockHttpServletRequest();
         HttpServletResponse hsResponse = mockHttpServletResponse();
+        Context context = mockContext();
 
         request.setAttribute(InternalConstants.SUPPRESS_COMPRESSION, true);
 
@@ -70,6 +69,10 @@
         train_setContentType(hsResponse, contentType);
         train_getOutputStream(hsResponse, new TestServletOutputStream());
 
+        if (consultsContext)
+            expect(context.getMimeType(endsWith(fileName))).andReturn(null);
+
+
         replay();
 
         Response response = new ResponseImpl(hsResponse);
@@ -79,6 +82,8 @@
         globals.storeServletRequestResponse(hsRequest, hsResponse);
         globals.storeRequestResponse(request, response);
 
+        getService(ApplicationGlobals.class).storeContext(context);
+
         String path = getClass().getPackage().getName().replace('.', '/') + "/" + fileName;
 
         Resource resource = new ClasspathResource(path);



Mime
View raw message