You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ja...@apache.org on 2010/11/30 19:39:41 UTC
svn commit: r1040688 -
/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/ResourceHandlerImpl.java
Author: jakobk
Date: Tue Nov 30 18:39:40 2010
New Revision: 1040688
URL: http://svn.apache.org/viewvc?rev=1040688&view=rev
Log:
MYFACES-2984 Myfaces should return a proper contentType if ResourceWrapper doesn't return one.
Modified:
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/ResourceHandlerImpl.java
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/ResourceHandlerImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/ResourceHandlerImpl.java?rev=1040688&r1=1040687&r2=1040688&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/ResourceHandlerImpl.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/ResourceHandlerImpl.java Tue Nov 30 18:39:40 2010
@@ -31,6 +31,7 @@ import java.util.logging.Logger;
import javax.faces.application.Resource;
import javax.faces.application.ResourceHandler;
+import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletResponse;
@@ -326,7 +327,7 @@ public class ResourceHandlerImpl extends
return;
}
- httpServletResponse.setContentType(resource.getContentType());
+ httpServletResponse.setContentType(_getContentType(resource, facesContext.getExternalContext()));
Map<String, String> headers = resource.getResponseHeaders();
@@ -578,4 +579,17 @@ public class ResourceHandlerImpl extends
_resourceHandlerCache = new ResourceHandlerCache();
return _resourceHandlerCache;
}
+
+ private String _getContentType(Resource resource, ExternalContext externalContext)
+ {
+ String contentType = resource.getContentType();
+
+ if (contentType == null || "".equals(contentType))
+ {
+ // the resource does not provide a content-type --> determine it via mime-type
+ contentType = externalContext.getMimeType(resource.getResourceName());
+ }
+
+ return contentType;
+ }
}