org.riotfamily.website.minify
Class AbstractMinifyController

java.lang.Object
  extended by org.riotfamily.cachius.spring.AbstractCacheableController
      extended by org.riotfamily.website.minify.AbstractMinifyController
All Implemented Interfaces:
CacheableController, Compressible, BeanNameAware, Controller, LastModified
Direct Known Subclasses:
MinifyCssController, MinifyScriptController

public abstract class AbstractMinifyController
extends AbstractCacheableController
implements LastModified, Compressible

Controller that concatenates resources and optionally compresses or obfuscates them. The result is cached by Cachius and gzipped when possible.

The controller uses a RequestDispatcher to request the resources and captures them using a CapturingResponseWrapper, which allows us to include dynamic resources, too.

Note: This will not work if an included controller uses request.getRequestURI() to look up a resource. Please use ServletUtils.getRequestUri(HttpServletRequest) instead.

Since:
6.5
Author:
Felix Gnass [fgnass at neteye dot de]

Field Summary
 
Fields inherited from interface org.riotfamily.cachius.spring.CacheableController
CACHE_ETERNALLY
 
Constructor Summary
AbstractMinifyController()
           
 
Method Summary
protected  void appendCacheKey(StringBuffer key, HttpServletRequest request)
          Adds the query-string to the cache-key.
protected  boolean bypassCache(HttpServletRequest request)
          The cache is bypassed in development mode.
protected  void capture(String path, ByteArrayOutputStream buffer, HttpServletRequest request, HttpServletResponse response)
           
protected abstract  Compressor getCompressor()
           
protected abstract  String getContentType()
           
 long getLastModified(HttpServletRequest request)
          Returns the server start-up time, or the current time if running in development mode.
 long getTimeToLive()
          Returns CACHE_ETERNALLY to request eternal caching.
 boolean gzipResponse(HttpServletRequest request)
          Always returns true.
 ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
           
 void setReloadable(boolean reloadable)
          If set to true, the output will not be cached, not compressed or obfuscated and no expires header will be sent.
 
Methods inherited from class org.riotfamily.cachius.spring.AbstractCacheableController
getBeanName, getCacheKey, getCacheKeyInternal, setAddUriToCacheKey, setBeanName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractMinifyController

public AbstractMinifyController()
Method Detail

setReloadable

public void setReloadable(boolean reloadable)
If set to true, the output will not be cached, not compressed or obfuscated and no expires header will be sent.


getLastModified

public long getLastModified(HttpServletRequest request)
Returns the server start-up time, or the current time if running in development mode.

Specified by:
getLastModified in interface CacheableController
Specified by:
getLastModified in interface LastModified
Overrides:
getLastModified in class AbstractCacheableController

bypassCache

protected boolean bypassCache(HttpServletRequest request)
The cache is bypassed in development mode.

Overrides:
bypassCache in class AbstractCacheableController

appendCacheKey

protected void appendCacheKey(StringBuffer key,
                              HttpServletRequest request)
Adds the query-string to the cache-key.

Overrides:
appendCacheKey in class AbstractCacheableController
See Also:
AbstractCacheableController.getCacheKeyInternal(HttpServletRequest)

getTimeToLive

public long getTimeToLive()
Returns CACHE_ETERNALLY to request eternal caching.

Specified by:
getTimeToLive in interface CacheableController
Overrides:
getTimeToLive in class AbstractCacheableController

gzipResponse

public boolean gzipResponse(HttpServletRequest request)
Always returns true.

Specified by:
gzipResponse in interface Compressible

handleRequest

public ModelAndView handleRequest(HttpServletRequest request,
                                  HttpServletResponse response)
                           throws Exception
Specified by:
handleRequest in interface Controller
Throws:
Exception

capture

protected void capture(String path,
                       ByteArrayOutputStream buffer,
                       HttpServletRequest request,
                       HttpServletResponse response)
                throws ServletException,
                       IOException
Throws:
ServletException
IOException

getContentType

protected abstract String getContentType()

getCompressor

protected abstract Compressor getCompressor()