org.riotfamily.website.css
Class CssTemplateController

java.lang.Object
  extended by org.riotfamily.cachius.spring.AbstractCacheableController
      extended by org.riotfamily.website.css.CssTemplateController
All Implemented Interfaces:
CacheableController, Compressible, BeanNameAware, InitializingBean, ServletContextAware, Controller, LastModified

public class CssTemplateController
extends AbstractCacheableController
implements ServletContextAware, InitializingBean, LastModified, Compressible

Controller that serves dynamic CSS files.

It's sometimes desirable to use constants in CSS files or to perform arithmetic operations. This controller allows you to do so, by using FreeMarker to process the stylesheets.

You can place a css.ini file in the same directory where your stylesheets are located. All properties defined in that file will be available within the FreeMarker template.

Additionally the controller allows you to create styles that look different in various contexts. A good example would be a website that uses multiple color schemes. Therefore you can add named sections to your your ini file and request <file>_<section-name>.css instead of <file>.css. This will cause the controller to expose the properties of the requested section, possibly overriding any default values with the same name.

You can access the properties from all sections at any time by using <section_name>.<property_name> in the FreeMarker template. If a default value has been overridden by a section value you can still access the original default, by using global.<property_name>.


Nested Class Summary
protected  class CssTemplateController.DynamicStylesheet
           
 
Field Summary
static String CONTEXT_PATH_PROPERTY
           
static String KEY_PROPERTY
           
 
Fields inherited from interface org.riotfamily.cachius.spring.CacheableController
CACHE_ETERNALLY
 
Constructor Summary
CssTemplateController()
           
 
Method Summary
 void afterPropertiesSet()
           
 long getLastModified(HttpServletRequest request)
          The default implementation returns System.currentTimeMillis() so that the item is refreshed as soon as it expires.
 boolean gzipResponse(HttpServletRequest request)
          Returns whether the response should be gzipped.
 ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
           
protected  CssTemplateController.DynamicStylesheet lookup(HttpServletRequest request)
           
 void setAddContextPathToUrls(boolean addContextPathToUrls)
          Sets whether the contextPath should be added to absolute URLs specified within the template.
 void setCompressor(YUICssCompressor compressor)
           
 void setFreeMarkerConfig(freemarker.template.Configuration configuration)
           
 void setIniFileLocation(Resource resource)
           
 void setServletContext(ServletContext servletContext)
           
 void setStamper(ResourceStamper stamper)
          Sets the ResourceStamper that should be used to add timestamps to URLs specified within the template.
 
Methods inherited from class org.riotfamily.cachius.spring.AbstractCacheableController
appendCacheKey, bypassCache, getBeanName, getCacheKey, getCacheKeyInternal, getTimeToLive, setAddUriToCacheKey, setBeanName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

KEY_PROPERTY

public static final String KEY_PROPERTY
See Also:
Constant Field Values

CONTEXT_PATH_PROPERTY

public static final String CONTEXT_PATH_PROPERTY
See Also:
Constant Field Values
Constructor Detail

CssTemplateController

public CssTemplateController()
Method Detail

setCompressor

public void setCompressor(YUICssCompressor compressor)
Parameters:
compressor - the compressor to set

setServletContext

public void setServletContext(ServletContext servletContext)
Specified by:
setServletContext in interface ServletContextAware

setFreeMarkerConfig

public void setFreeMarkerConfig(freemarker.template.Configuration configuration)

setStamper

public void setStamper(ResourceStamper stamper)
Sets the ResourceStamper that should be used to add timestamps to URLs specified within the template.

Since:
6.4
See Also:
ResourceStamper

setAddContextPathToUrls

public void setAddContextPathToUrls(boolean addContextPathToUrls)
Sets whether the contextPath should be added to absolute URLs specified within the template. Defaults to false.

Since:
6.4

setIniFileLocation

public void setIniFileLocation(Resource resource)
                        throws IOException
Throws:
IOException

afterPropertiesSet

public void afterPropertiesSet()
                        throws Exception
Specified by:
afterPropertiesSet in interface InitializingBean
Throws:
Exception

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

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

handleRequest

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

lookup

protected CssTemplateController.DynamicStylesheet lookup(HttpServletRequest request)