org.riotfamily.riot.resource
Class AbstractResourceController

java.lang.Object
  extended by org.riotfamily.cachius.spring.AbstractCacheableController
      extended by org.riotfamily.riot.resource.AbstractResourceController
All Implemented Interfaces:
CacheableController, Compressible, BeanNameAware, Controller, LastModified
Direct Known Subclasses:
JoiningResourceController, ResourceController

public class AbstractResourceController
extends AbstractCacheableController
implements LastModified, Compressible

Controller that serves an internal resource.

Note: This will only work when a prefix mapping is used for the DispatcherServlet (like /riot/*) since request.getPathInfo() is used.


Field Summary
 
Fields inherited from interface org.riotfamily.cachius.spring.CacheableController
CACHE_ETERNALLY
 
Constructor Summary
AbstractResourceController()
           
 
Method Summary
protected  boolean contentTypeShouldBeZipped(String contentType)
           
protected  String getCacheKeyInternal(HttpServletRequest request)
          Returns the actual cache-key.
protected  String getContentType(Resource resource)
           
 long getLastModified(HttpServletRequest request)
          The default implementation returns System.currentTimeMillis() so that the item is refreshed as soon as it expires.
protected  long getLastModified(String path)
           
protected  Reader getReader(Resource res, String path, String contentType, HttpServletRequest request)
           
protected  String getResourcePath(HttpServletRequest request)
           
 long getTimeToLive()
          The default implementation returns 0 so that AbstractCacheableController.getLastModified(HttpServletRequest) is invoked every time the controller is requested.
 boolean gzipResponse(HttpServletRequest request)
          Returns whether the response should be gzipped.
 ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
           
protected  Resource lookupResource(String path)
           
protected  void serveBinary(Resource res, String contentType, OutputStream out)
           
protected  boolean serveResource(String path, HttpServletRequest request, HttpServletResponse response)
           
protected  void serveText(Resource res, String path, String contentType, HttpServletRequest request, Writer out)
           
 void setCheckForModifications(boolean checkForModifications)
          Sets whether the controller check for file modifications.
 void setFileTypeMap(FileTypeMap fileTypeMap)
           
 void setFilters(List<ResourceFilter> filters)
           
 void setMappings(List<ResourceMapping> resourceMappings)
           
 void setPathAttribute(String pathAttribute)
          Sets the name of the request attribute that will contain the resource path.
 void setPathParameter(String pathParameter)
          Sets the name of the request parameter that will contain the resource path.
 
Methods inherited from class org.riotfamily.cachius.spring.AbstractCacheableController
appendCacheKey, bypassCache, getBeanName, getCacheKey, setAddUriToCacheKey, setBeanName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractResourceController

public AbstractResourceController()
Method Detail

setPathAttribute

public void setPathAttribute(String pathAttribute)
Sets the name of the request attribute that will contain the resource path.


setPathParameter

public void setPathParameter(String pathParameter)
Sets the name of the request parameter that will contain the resource path.


setFileTypeMap

public void setFileTypeMap(FileTypeMap fileTypeMap)

setMappings

public void setMappings(List<ResourceMapping> resourceMappings)

setFilters

public void setFilters(List<ResourceFilter> filters)

setCheckForModifications

public void setCheckForModifications(boolean checkForModifications)
Sets whether the controller check for file modifications.


lookupResource

protected Resource lookupResource(String path)
                           throws IOException
Throws:
IOException

getContentType

protected String getContentType(Resource resource)

getResourcePath

protected String getResourcePath(HttpServletRequest request)

getLastModified

public long getLastModified(HttpServletRequest request)
Description copied from class: AbstractCacheableController
The default implementation returns System.currentTimeMillis() so that the item is refreshed as soon as it expires. Subclasses should override this method to return something reasonable.

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

getLastModified

protected long getLastModified(String path)

getTimeToLive

public long getTimeToLive()
Description copied from class: AbstractCacheableController
The default implementation returns 0 so that AbstractCacheableController.getLastModified(HttpServletRequest) is invoked every time the controller is requested.

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

getCacheKeyInternal

protected String getCacheKeyInternal(HttpServletRequest request)
Description copied from class: AbstractCacheableController
Returns the actual cache-key. Invoked by getCacheKey() if bypassCache() returned false.

The method creates a StringBuffer containing either the bean-name or the originating path and, in case of an include or forward, the nested path.

The StringBuffer is passed to AbstractCacheableController.appendCacheKey(StringBuffer, HttpServletRequest), allowing subclasses to add additional information.

Overrides:
getCacheKeyInternal in class AbstractCacheableController

contentTypeShouldBeZipped

protected boolean contentTypeShouldBeZipped(String contentType)

gzipResponse

public boolean gzipResponse(HttpServletRequest request)
Description copied from interface: Compressible
Returns whether the response should be gzipped. Implementors will usually return true, unless they serve multiple content types which and not all of them are eligible for compression. They don't have to check whether the client supports gzip compression as all compatibility checks are done by Cachius internally.

Specified by:
gzipResponse in interface Compressible

handleRequest

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

serveResource

protected boolean serveResource(String path,
                                HttpServletRequest request,
                                HttpServletResponse response)
                         throws IOException
Throws:
IOException

serveText

protected void serveText(Resource res,
                         String path,
                         String contentType,
                         HttpServletRequest request,
                         Writer out)
                  throws IOException
Throws:
IOException

getReader

protected Reader getReader(Resource res,
                           String path,
                           String contentType,
                           HttpServletRequest request)
                    throws IOException
Throws:
IOException

serveBinary

protected void serveBinary(Resource res,
                           String contentType,
                           OutputStream out)
                    throws IOException
Throws:
IOException