de.neteye.actioncache
Class ExampleAction

java.lang.Object
  |
  +--org.apache.struts.action.Action
        |
        +--de.neteye.actioncache.AbstractCacheableAction
              |
              +--de.neteye.actioncache.ExampleAction
All Implemented Interfaces:
CacheableAction

public class ExampleAction
extends AbstractCacheableAction

Example that demonstrates how to implement cacheable actions. It displays the current time using the locale specified by the request parameter locale or the user's default locale if the parameter is omitted. The timeToLive is set to 5 seconds.

Version:
$Revision: 1.2 $
Author:
Felix Gnass

Field Summary
 
Fields inherited from class de.neteye.actioncache.AbstractCacheableAction
DEFAULT_TTL
 
Fields inherited from class org.apache.struts.action.Action
ACTION_SERVLET_KEY, APPLICATION_KEY, DATA_SOURCE_KEY, defaultLocale, ERROR_KEY, EXCEPTION_KEY, FORM_BEANS_KEY, FORWARDS_KEY, LOCALE_KEY, MAPPING_KEY, MAPPINGS_KEY, MESSAGE_KEY, MESSAGES_KEY, MULTIPART_KEY, PLUG_INS_KEY, REQUEST_PROCESSOR_KEY, servlet, SERVLET_KEY, TRANSACTION_TOKEN_KEY
 
Constructor Summary
ExampleAction()
           
 
Method Summary
 org.apache.struts.action.ActionForward execute(org.apache.struts.action.ActionMapping mapping, org.apache.struts.action.ActionForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Writes the current time formatted for the requested locale to the output.
 java.lang.String getCacheKey(org.apache.struts.action.ActionMapping mapping, org.apache.struts.action.ActionForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Returns the cacheKey containing the acttion's class name and the requested locale.
 long getLastModified(org.apache.struts.action.ActionMapping mapping, org.apache.struts.action.ActionForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Returns System.currentTimeMillis() to force a refresh when the timeToLive has elapsed.
protected  java.util.Locale getLocale(javax.servlet.http.HttpServletRequest request)
          Returns the locale specified by the request parameter locale or the user's default locale in case the parameter is omitted.
 int getTimeToLive(org.apache.struts.action.ActionMapping mapping, org.apache.struts.action.ActionForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Returns 5000 which means that result will be cached for 5 seconds.
 
Methods inherited from class de.neteye.actioncache.AbstractCacheableAction
getLastModified
 
Methods inherited from class org.apache.struts.action.Action
execute, generateToken, getDataSource, getDataSource, getResources, getResources, getResources, getServlet, isCancelled, isTokenValid, isTokenValid, perform, perform, resetToken, saveErrors, saveMessages, saveToken, setLocale, setServlet, toHex
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ExampleAction

public ExampleAction()
Method Detail

getCacheKey

public java.lang.String getCacheKey(org.apache.struts.action.ActionMapping mapping,
                                    org.apache.struts.action.ActionForm form,
                                    javax.servlet.http.HttpServletRequest request,
                                    javax.servlet.http.HttpServletResponse response)
Returns the cacheKey containing the acttion's class name and the requested locale.

Specified by:
getCacheKey in interface CacheableAction
Overrides:
getCacheKey in class AbstractCacheableAction

getLastModified

public long getLastModified(org.apache.struts.action.ActionMapping mapping,
                            org.apache.struts.action.ActionForm form,
                            javax.servlet.http.HttpServletRequest request,
                            javax.servlet.http.HttpServletResponse response)
                     throws java.io.IOException,
                            javax.servlet.ServletException
Returns System.currentTimeMillis() to force a refresh when the timeToLive has elapsed.

Overrides:
getLastModified in class AbstractCacheableAction
java.io.IOException
javax.servlet.ServletException

getTimeToLive

public int getTimeToLive(org.apache.struts.action.ActionMapping mapping,
                         org.apache.struts.action.ActionForm form,
                         javax.servlet.http.HttpServletRequest request,
                         javax.servlet.http.HttpServletResponse response)
Returns 5000 which means that result will be cached for 5 seconds.

Overrides:
getTimeToLive in class AbstractCacheableAction

execute

public org.apache.struts.action.ActionForward execute(org.apache.struts.action.ActionMapping mapping,
                                                      org.apache.struts.action.ActionForm form,
                                                      javax.servlet.http.HttpServletRequest request,
                                                      javax.servlet.http.HttpServletResponse response)
                                               throws java.io.IOException,
                                                      javax.servlet.ServletException
Writes the current time formatted for the requested locale to the output. For simplicity's sake no forward is returned.

Specified by:
execute in class AbstractCacheableAction
java.io.IOException
javax.servlet.ServletException

getLocale

protected java.util.Locale getLocale(javax.servlet.http.HttpServletRequest request)
Returns the locale specified by the request parameter locale or the user's default locale in case the parameter is omitted.

Overrides:
getLocale in class org.apache.struts.action.Action