You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2011/11/09 18:15:13 UTC

svn commit: r1199873 - /myfaces/commons/trunk/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/

Author: lu4242
Date: Wed Nov  9 17:15:13 2011
New Revision: 1199873

URL: http://svn.apache.org/viewvc?rev=1199873&view=rev
Log:
MFCOMMONS-44 Remove gzip compression feature from myfaces commons resourcehandler

Removed:
    myfaces/commons/trunk/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/GZIPResourceLoader.java
Modified:
    myfaces/commons/trunk/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/ExtendedDefaultResourceHandlerSupport.java
    myfaces/commons/trunk/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/ExtendedResourceHandlerImpl.java
    myfaces/commons/trunk/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/ExtendedResourceImpl.java

Modified: myfaces/commons/trunk/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/ExtendedDefaultResourceHandlerSupport.java
URL: http://svn.apache.org/viewvc/myfaces/commons/trunk/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/ExtendedDefaultResourceHandlerSupport.java?rev=1199873&r1=1199872&r2=1199873&view=diff
==============================================================================
--- myfaces/commons/trunk/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/ExtendedDefaultResourceHandlerSupport.java (original)
+++ myfaces/commons/trunk/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/ExtendedDefaultResourceHandlerSupport.java Wed Nov  9 17:15:13 2011
@@ -52,24 +52,30 @@ public class ExtendedDefaultResourceHand
         ExtendedDefaultResourceHandlerSupport.class.getName() + ".CACHED_SERVLET_MAPPING";
     
     /**
+     * DEPRECATED: feature removed according to community decision.
      * Enable or disable gzip compressions for resources served by this extended resource handler.
      * By default is disabled (false).
      */
     @JSFWebConfigParam(defaultValue="false")
+    @Deprecated
     public static final String INIT_PARAM_GZIP_RESOURCES_ENABLED = "org.apache.myfaces.commons.GZIP_RESOURCES_ENABLED";
     
     /**
+     * DEPRECATED: feature removed according to community decision.
      * Indicate the suffix used to recognize resources that should be compressed. By default is ".css .js".
      */
     @JSFWebConfigParam(defaultValue=".css, .js")
+    @Deprecated
     public static final String INIT_PARAM_GZIP_RESOURCES_SUFFIX = "org.apache.myfaces.commons.GZIP_RESOURCES_SUFFIX";
     public static final String INIT_PARAM_GZIP_RESOURCES_EXTENSIONS_DEFAULT = ".css .js";
     
     /**
+     * DEPRECATED: feature removed according to community decision.
      * Indicate if gzipped files are stored on a temporal directory to serve them later. By default is true. If this is
      * disable, the files are compressed when they are served. 
      */
     @JSFWebConfigParam(defaultValue="true")
+    @Deprecated
     public static final String INIT_PARAM_CACHE_DISK_GZIP_RESOURCES
             = "org.apache.myfaces.commons.CACHE_DISK_GZIP_RESOURCES";
     
@@ -96,12 +102,6 @@ public class ExtendedDefaultResourceHand
     
     private ResourceLoader[] _resourceLoaders;
     
-    private final boolean _gzipResourcesEnabled;
-    
-    private final String[] _gzipResourcesSuffix;
-    
-    private final boolean _cacheDiskGzipResources;
-    
     private final boolean _developmentStage;
     
     private MyFacesResourcesConfig _config;
@@ -115,13 +115,6 @@ public class ExtendedDefaultResourceHand
         super();
         FacesContext context = FacesContext.getCurrentInstance();
         
-        _gzipResourcesEnabled = WebConfigParamUtils.getBooleanInitParameter(context.getExternalContext(), 
-                INIT_PARAM_GZIP_RESOURCES_ENABLED, false);
-        _gzipResourcesSuffix = StringUtils.splitShortString(
-                WebConfigParamUtils.getStringInitParameter(context.getExternalContext(),
-                        INIT_PARAM_GZIP_RESOURCES_SUFFIX, INIT_PARAM_GZIP_RESOURCES_EXTENSIONS_DEFAULT), ' ');
-        _cacheDiskGzipResources = WebConfigParamUtils.getBooleanInitParameter(context.getExternalContext(), 
-                INIT_PARAM_CACHE_DISK_GZIP_RESOURCES, true);
         _developmentStage = context.isProjectStage(ProjectStage.Development);
         
         _resourceIdentifier = WebConfigParamUtils.getStringInitParameter(context.getExternalContext(), 
@@ -145,75 +138,6 @@ public class ExtendedDefaultResourceHand
     {
         return _config;
     }
-    
-    public String[] getGzipResourcesSuffixes()
-    {
-        return _gzipResourcesSuffix;
-    }
-    
-    public boolean isGzipResourcesEnabled()
-    {
-        return _gzipResourcesEnabled;
-    }
-    
-    public boolean isCacheDiskGzipResources()
-    {
-        return _cacheDiskGzipResources;
-    }
-    
-    public boolean isCompressable(ResourceMeta resourceMeta)
-    {
-        if (getGzipResourcesSuffixes() != null)
-        {
-            boolean compressable = false;            
-            for (int i = 0; i < getGzipResourcesSuffixes().length; i++)
-            {
-                if (getGzipResourcesSuffixes()[i] != null && 
-                    getGzipResourcesSuffixes()[i].length() > 0 &&
-                    resourceMeta.getResourceName().endsWith(getGzipResourcesSuffixes()[i]))
-                {
-                    compressable = true;
-                    break;
-                }
-            }
-            return compressable;
-        }
-        else
-        {
-            return true;
-        }
-    }
-    
-    public boolean isCompressable(Resource resource)
-    {
-        if (getGzipResourcesSuffixes() != null)
-        {
-            boolean compressable = false;            
-            for (int i = 0; i < getGzipResourcesSuffixes().length; i++)
-            {
-                if (getGzipResourcesSuffixes()[i] != null && 
-                    getGzipResourcesSuffixes()[i].length() > 0 &&
-                    resource.getResourceName().endsWith(getGzipResourcesSuffixes()[i]))
-                {
-                    compressable = true;
-                    break;
-                }
-            }
-            return compressable;
-        }
-        else
-        {
-            return true;
-        }
-    }
-
-    public boolean userAgentSupportsCompression(FacesContext facesContext)
-    {
-        String acceptEncodingHeader = facesContext.getExternalContext()
-                .getRequestHeaderMap().get(ACCEPT_ENCODING_HEADER);
-
-        return ResourceUtils.isGZIPEncodingAccepted(acceptEncodingHeader);
-    }
 
     public String calculateResourceBasePath(FacesContext facesContext)
     {        
@@ -396,26 +320,10 @@ public class ExtendedDefaultResourceHand
     {
         if (_resourceLoaders == null)
         {
-            // we should serve a compressed version of the resource, if
-            //   - ProjectStage != Development
-            //   - a compressed version is available (created in constructor)
-            //   - the user agent supports compresssion
-            if (/*!_developmentStage && */isGzipResourcesEnabled() && isCacheDiskGzipResources())
-            {
-                _resourceLoaders = new ResourceLoader[] {
-                        new GZIPResourceLoader(new ExtendedResourceLoaderWrapper(
-                                new ExternalContextResourceLoader("/resources")), this),
-                        new GZIPResourceLoader(new ExtendedResourceLoaderWrapper(
-                                new ClassLoaderResourceLoader("META-INF/resources")), this)
-                };
-            }
-            else
-            {
-                _resourceLoaders = new ResourceLoader[] {
-                        new ExtendedResourceLoaderWrapper(new ExternalContextResourceLoader("/resources")),
-                        new ExtendedResourceLoaderWrapper(new ClassLoaderResourceLoader("META-INF/resources"))
-                };
-            }
+            _resourceLoaders = new ResourceLoader[] {
+                    new ExtendedResourceLoaderWrapper(new ExternalContextResourceLoader("/resources")),
+                    new ExtendedResourceLoaderWrapper(new ClassLoaderResourceLoader("META-INF/resources"))
+            };
         }
         return _resourceLoaders;
     }

Modified: myfaces/commons/trunk/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/ExtendedResourceHandlerImpl.java
URL: http://svn.apache.org/viewvc/myfaces/commons/trunk/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/ExtendedResourceHandlerImpl.java?rev=1199873&r1=1199872&r2=1199873&view=diff
==============================================================================
--- myfaces/commons/trunk/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/ExtendedResourceHandlerImpl.java (original)
+++ myfaces/commons/trunk/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/ExtendedResourceHandlerImpl.java Wed Nov  9 17:15:13 2011
@@ -449,55 +449,24 @@ public class ExtendedResourceHandlerImpl
                 //   - a compressed version is available (created in constructor)
                 //   - the user agent supports compresssion
                 // and if there is no caching on disk, do compression here!
-                if (!facesContext.isProjectStage(ProjectStage.Development) &&
-                    getResourceHandlerSupport().isGzipResourcesEnabled() && 
-                    !getResourceHandlerSupport().isCacheDiskGzipResources() && 
-                    getResourceHandlerSupport().userAgentSupportsCompression(facesContext) && 
-                    getResourceHandlerSupport().isCompressable(resource))
+                InputStream in = resource.getInputStream();
+                OutputStream out = httpServletResponse.getOutputStream();
+                byte[] buffer = new byte[_BUFFER_SIZE];
+                try
                 {
-                    InputStream in = resource.getInputStream();
-                    OutputStream out = new GZIPOutputStream(httpServletResponse.getOutputStream(), _BUFFER_SIZE);
-                    byte[] buffer = new byte[_BUFFER_SIZE];
-        
-                    try
-                    {
-                        int count = pipeBytes(in, out, buffer);
-                        //set the content lenght
-                        httpServletResponse.setContentLength(count);
-                    }
-                    finally
-                    {
-                        try
-                        {
-                            in.close();
-                        }
-                        finally
-                        {
-                            out.close();
-                        }
-                    }
+                    int count = pipeBytes(in, out, buffer);
+                    //set the content lenght
+                    httpServletResponse.setContentLength(count);
                 }
-                else
+                finally
                 {
-                    InputStream in = resource.getInputStream();
-                    OutputStream out = httpServletResponse.getOutputStream();
-                    byte[] buffer = new byte[_BUFFER_SIZE];
                     try
                     {
-                        int count = pipeBytes(in, out, buffer);
-                        //set the content lenght
-                        httpServletResponse.setContentLength(count);
+                        in.close();
                     }
                     finally
                     {
-                        try
-                        {
-                            in.close();
-                        }
-                        finally
-                        {
-                            out.close();
-                        }
+                        out.close();
                     }
                 }
             }

Modified: myfaces/commons/trunk/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/ExtendedResourceImpl.java
URL: http://svn.apache.org/viewvc/myfaces/commons/trunk/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/ExtendedResourceImpl.java?rev=1199873&r1=1199872&r2=1199873&view=diff
==============================================================================
--- myfaces/commons/trunk/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/ExtendedResourceImpl.java (original)
+++ myfaces/commons/trunk/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/ExtendedResourceImpl.java Wed Nov  9 17:15:13 2011
@@ -18,9 +18,6 @@
  */
 package org.apache.myfaces.commons.resourcehandler;
 
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.Locale;
 import java.util.Map;
@@ -64,23 +61,6 @@ public class ExtendedResourceImpl extend
     }
     
     @Override
-    public InputStream getInputStream() throws IOException
-    {
-        if ( getExtendedDefaultResourceHandlerSupport().isGzipResourcesEnabled() &&
-             getExtendedDefaultResourceHandlerSupport().isCacheDiskGzipResources() &&
-             getExtendedDefaultResourceHandlerSupport().isCompressable(this) &&
-             getExtendedDefaultResourceHandlerSupport().userAgentSupportsCompression(FacesContext.getCurrentInstance()))
-        {
-            //GZIPResourceLoader will take care of resources containing ValueExpressions 
-            return getResourceLoader().getResourceInputStream(getResourceMeta());
-        }
-        else
-        {
-            return super.getInputStream();
-        }
-    }
-
-    @Override
     public String getRequestPath()
     {
         String mapping = getResourceHandlerSupport().getMapping() != null ?
@@ -162,31 +142,6 @@ public class ExtendedResourceImpl extend
         return _extendedDefaultResourceHandlerSupport;
     }
     
-    @Override
-    public Map<String, String> getResponseHeaders()
-    {
-        FacesContext facesContext = FacesContext.getCurrentInstance();
-        
-        if (facesContext.getApplication().getResourceHandler().isResourceRequest(facesContext))
-        {
-            Map<String, String> headers = super.getResponseHeaders();
-            
-            if (getExtendedDefaultResourceHandlerSupport().isGzipResourcesEnabled() && 
-                getExtendedDefaultResourceHandlerSupport().userAgentSupportsCompression(facesContext) && 
-                getExtendedDefaultResourceHandlerSupport().isCompressable(this))
-                {
-                    headers.put("Content-Encoding", "gzip");
-                }
-            
-            return headers; 
-        }
-        else
-        {
-            //No need to return headers 
-            return Collections.emptyMap();
-        }
-    }
-    
     /**
      * Returns the String representation of the current locale for the use in the request path.
      *