Spring Framework

org.springframework.web.servlet.support
Class DefaultFlashMapManager

java.lang.Object
  extended by org.springframework.web.servlet.support.DefaultFlashMapManager
All Implemented Interfaces:
FlashMapManager

public class DefaultFlashMapManager
extends java.lang.Object
implements FlashMapManager

A default FlashMapManager implementation that stores FlashMap instances in the HTTP session.

Since:
3.1
Author:
Rossen Stoyanchev

Field Summary
 
Fields inherited from interface org.springframework.web.servlet.FlashMapManager
INPUT_FLASH_MAP_ATTRIBUTE, OUTPUT_FLASH_MAP_ATTRIBUTE
 
Constructor Summary
DefaultFlashMapManager()
           
 
Method Summary
 int getFlashMapTimeout()
          Return the amount of time in seconds before a FlashMap expires.
 UrlPathHelper getUrlPathHelper()
          Return the UrlPathHelper implementation for the request URI.
protected  boolean isFlashMapForRequest(FlashMap flashMap, javax.servlet.http.HttpServletRequest request)
          Whether the given FlashMap matches the current request.
protected  void onSaveFlashMap(FlashMap flashMap, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Update a FlashMap before it is stored in the underlying storage.
protected  void removeExpiredFlashMaps(javax.servlet.http.HttpServletRequest request)
          Check and remove expired FlashMaps instances.
 void requestCompleted(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Start the expiration period of the "output" FlashMap save it in the underlying storage.
 void requestStarted(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Perform the following tasks unless the FlashMapManager.OUTPUT_FLASH_MAP_ATTRIBUTE request attribute exists: Find the "input" FlashMap, expose it under the request attribute FlashMapManager.INPUT_FLASH_MAP_ATTRIBUTE, and remove it from underlying storage.
protected  java.util.List<FlashMap> retrieveFlashMaps(javax.servlet.http.HttpServletRequest request, boolean allowCreate)
          Retrieve all FlashMap instances from the current HTTP session.
protected  void saveFlashMap(FlashMap flashMap, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Save the FlashMap in the underlying storage.
 void setFlashMapTimeout(int flashMapTimeout)
          Set the amount of time in seconds after a FlashMap is saved (at request completion) and before it expires.
 void setUrlPathHelper(UrlPathHelper urlPathHelper)
          Set the UrlPathHelper to use to obtain the request URI.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultFlashMapManager

public DefaultFlashMapManager()
Method Detail

setFlashMapTimeout

public void setFlashMapTimeout(int flashMapTimeout)
Set the amount of time in seconds after a FlashMap is saved (at request completion) and before it expires.

The default value is 180 seconds.


getFlashMapTimeout

public int getFlashMapTimeout()
Return the amount of time in seconds before a FlashMap expires.


setUrlPathHelper

public void setUrlPathHelper(UrlPathHelper urlPathHelper)
Set the UrlPathHelper to use to obtain the request URI.


getUrlPathHelper

public UrlPathHelper getUrlPathHelper()
Return the UrlPathHelper implementation for the request URI.


requestStarted

public final void requestStarted(javax.servlet.http.HttpServletRequest request,
                                 javax.servlet.http.HttpServletResponse response)
Perform the following tasks unless the FlashMapManager.OUTPUT_FLASH_MAP_ATTRIBUTE request attribute exists:
  1. Find the "input" FlashMap, expose it under the request attribute FlashMapManager.INPUT_FLASH_MAP_ATTRIBUTE, and remove it from underlying storage.
  2. Create the "output" FlashMap and expose it under the request attribute FlashMapManager.OUTPUT_FLASH_MAP_ATTRIBUTE.
  3. Clean expired FlashMap instances.

An HTTP session is never created by this method.

Specified by:
requestStarted in interface FlashMapManager
Parameters:
request - the current request
response - the current response

isFlashMapForRequest

protected boolean isFlashMapForRequest(FlashMap flashMap,
                                       javax.servlet.http.HttpServletRequest request)
Whether the given FlashMap matches the current request. The default implementation uses the target request path and query params saved in the FlashMap.


retrieveFlashMaps

protected java.util.List<FlashMap> retrieveFlashMaps(javax.servlet.http.HttpServletRequest request,
                                                     boolean allowCreate)
Retrieve all FlashMap instances from the current HTTP session. If allowCreate is "true" and no flash maps exist yet, a new list is created and stored as a session attribute.

Parameters:
request - the current request
allowCreate - whether to create the session if necessary
Returns:
a List to add FlashMap instances to or null assuming allowCreate is "false".

removeExpiredFlashMaps

protected void removeExpiredFlashMaps(javax.servlet.http.HttpServletRequest request)
Check and remove expired FlashMaps instances.


requestCompleted

public void requestCompleted(javax.servlet.http.HttpServletRequest request,
                             javax.servlet.http.HttpServletResponse response)
Start the expiration period of the "output" FlashMap save it in the underlying storage.

The "output" FlashMap should not be saved if it is empty or if it was not created by the current FlashMapManager instance.

An HTTP session is never created if the "output" FlashMap is empty.

Specified by:
requestCompleted in interface FlashMapManager
Parameters:
request - the current request
response - the current response

onSaveFlashMap

protected void onSaveFlashMap(FlashMap flashMap,
                              javax.servlet.http.HttpServletRequest request,
                              javax.servlet.http.HttpServletResponse response)
Update a FlashMap before it is stored in the underlying storage.

The default implementation starts the expiration period and ensures the target request path is decoded and normalized if it is relative.

Parameters:
flashMap - the flash map to be saved
request - the current request
response - the current response

saveFlashMap

protected void saveFlashMap(FlashMap flashMap,
                            javax.servlet.http.HttpServletRequest request,
                            javax.servlet.http.HttpServletResponse response)
Save the FlashMap in the underlying storage.

Parameters:
flashMap - the FlashMap to save
request - the current request
response - the current response

Spring Framework