org.riotfamily.website.txt2img
Class Txt2ImgController

java.lang.Object
  extended by org.riotfamily.cachius.spring.AbstractCacheableController
      extended by org.riotfamily.website.txt2img.Txt2ImgController
All Implemented Interfaces:
CacheableController, Compressible, BeanNameAware, ApplicationContextAware, Controller, LastModified

public class Txt2ImgController
extends AbstractCacheableController
implements ApplicationContextAware, LastModified, Compressible

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
Txt2ImgController()
           
 
Method Summary
protected  void appendCacheKey(StringBuffer key, HttpServletRequest request)
          Subclasses may overwrite this method to append values to the cache-key.
protected  String getEncodedParam(HttpServletRequest request, String name)
           
 long getLastModified(HttpServletRequest request)
          The default implementation returns System.currentTimeMillis() so that the item is refreshed as soon as it expires.
protected  Locale getLocale(HttpServletRequest request)
          Returns the locale for the given request.
protected  String getText(HttpServletRequest request)
          Returns the text to be rendered.
 boolean gzipResponse(HttpServletRequest request)
          Returns whether the response should be gzipped.
 ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
           
protected  void serveImage(String text, HttpServletRequest request, HttpServletResponse response)
          Serves an image containing the given text.
protected  void servePixelGif(HttpServletResponse response)
          Serves a transparent 1x1 pixel GIF that is needed by the JavaScript to work around the PNG loading in IE < 7.
protected  void serveScript(HttpServletRequest request, HttpServletResponse response)
          Serves a JavaScript file that can be used to replace texts on the client side.
protected  void serveStyleSheet(HttpServletRequest request, HttpServletResponse response)
           
 void setApplicationContext(ApplicationContext applicationContext)
           
 void setCompressor(YUIJavaScriptCompressor compressor)
           
 void setRefererPattern(Pattern refererPattern)
          Sets a regular expression that is used to check the Referer header.
 
Methods inherited from class org.riotfamily.cachius.spring.AbstractCacheableController
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
 

Constructor Detail

Txt2ImgController

public Txt2ImgController()
Method Detail

setApplicationContext

public void setApplicationContext(ApplicationContext applicationContext)
                           throws BeansException
Specified by:
setApplicationContext in interface ApplicationContextAware
Throws:
BeansException

setCompressor

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

appendCacheKey

protected void appendCacheKey(StringBuffer key,
                              HttpServletRequest request)
Description copied from class: AbstractCacheableController
Subclasses may overwrite this method to append values to the cache-key. The default implementation does nothing.

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

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

setRefererPattern

public void setRefererPattern(Pattern refererPattern)
Sets a regular expression that is used to check the Referer header. You may use this setting to prevent other websites from using your ImageGenerator.


handleRequest

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

getLocale

protected Locale getLocale(HttpServletRequest request)
Returns the locale for the given request. The method first checks for a parameter called 'locale' an parses it. If the parameter is not set, Spring's LocaleResolver mechanism is used.


getEncodedParam

protected String getEncodedParam(HttpServletRequest request,
                                 String name)

getText

protected String getText(HttpServletRequest request)
Returns the text to be rendered. The method unescapes HTML entities and optionally converts the String to upper or lower case, if the 'transform' HTTP parameter is set.


serveImage

protected void serveImage(String text,
                          HttpServletRequest request,
                          HttpServletResponse response)
                   throws IOException
Serves an image containing the given text.

Throws:
IOException

serveScript

protected void serveScript(HttpServletRequest request,
                           HttpServletResponse response)
                    throws IOException
Serves a JavaScript file that can be used to replace texts on the client side.

Throws:
IOException

serveStyleSheet

protected void serveStyleSheet(HttpServletRequest request,
                               HttpServletResponse response)
                        throws IOException
Throws:
IOException

servePixelGif

protected void servePixelGif(HttpServletResponse response)
                      throws IOException
Serves a transparent 1x1 pixel GIF that is needed by the JavaScript to work around the PNG loading in IE < 7.

Throws:
IOException