Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.roller.presentation.filters
Class CompressionFilter  view CompressionFilter download CompressionFilter.java

java.lang.Object
  extended byorg.roller.presentation.filters.CompressionFilter
All Implemented Interfaces:
javax.servlet.Filter

public class CompressionFilter
extends java.lang.Object
implements javax.servlet.Filter

Filter that compresses output with gzip (assuming that browser supports gzip).

Taken from More Servlets and JavaServer Pages from Prentice Hall and Sun Microsystems Press, http://www.moreservlets.com/. © 2002 Marty Hall; may be freely used or adapted.


Field Summary
private  javax.servlet.FilterConfig config
           
private static org.apache.commons.logging.Log mLogger
           
 
Constructor Summary
CompressionFilter()
           
 
Method Summary
 void destroy()
          Called by the web container to indicate to a filter that it is being taken out of service.
 void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain)
          If browser does not support gzip, invoke resource normally.
protected  javax.servlet.FilterConfig getFilterConfig()
           
 void init(javax.servlet.FilterConfig config)
          Store the FilterConfig object in case subclasses want it.
private  boolean isGzipSupported(javax.servlet.http.HttpServletRequest req)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mLogger

private static org.apache.commons.logging.Log mLogger

config

private javax.servlet.FilterConfig config
Constructor Detail

CompressionFilter

public CompressionFilter()
Method Detail

doFilter

public void doFilter(javax.servlet.ServletRequest request,
                     javax.servlet.ServletResponse response,
                     javax.servlet.FilterChain chain)
              throws javax.servlet.ServletException,
                     java.io.IOException
If browser does not support gzip, invoke resource normally. If browser does support gzip, set the Content-Encoding response header and invoke resource with a wrapped response that collects all the output. Extract the output and write it into a gzipped byte array. Finally, write that array to the client's output stream.

Specified by:
doFilter in interface javax.servlet.Filter

init

public void init(javax.servlet.FilterConfig config)
          throws javax.servlet.ServletException
Store the FilterConfig object in case subclasses want it.

Specified by:
init in interface javax.servlet.Filter

getFilterConfig

protected javax.servlet.FilterConfig getFilterConfig()

destroy

public void destroy()
Description copied from interface: javax.servlet.Filter
Called by the web container to indicate to a filter that it is being taken out of service. This method is only called once all threads within the filter's doFilter method have exited or after a timeout period has passed. After the web container calls this method, it will not call the doFilter method again on this instance of the filter.

This method gives the filter an opportunity to clean up any resources that are being held (for example, memory, file handles, threads) and make sure that any persistent state is synchronized with the filter's current state in memory.

Specified by:
destroy in interface javax.servlet.Filter

isGzipSupported

private boolean isGzipSupported(javax.servlet.http.HttpServletRequest req)