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
private static java.lang.String FLASH_MAPS_SESSION_ATTRIBUTE
           
private  int flashTimeout
           
private static Log logger
           
private  UrlPathHelper urlPathHelper
           
 
Fields inherited from interface org.springframework.web.servlet.FlashMapManager
INPUT_FLASH_MAP_ATTRIBUTE, OUTPUT_FLASH_MAP_ATTRIBUTE
 
Constructor Summary
DefaultFlashMapManager()
           
 
Method Summary
private  java.lang.String decodeAndNormalizePath(java.lang.String path, HttpServletRequest request)
           
protected  boolean isFlashMapForRequest(FlashMap flashMap, HttpServletRequest request)
          Whether the given FlashMap matches the current request.
private  FlashMap lookupFlashMap(HttpServletRequest request)
          Find the "input" FlashMap for the current request target by matching it to the target request information of all stored FlashMap instances.
protected  void onSaveFlashMap(FlashMap flashMap, HttpServletRequest request)
          Update a FlashMap before it is stored in the HTTP Session.
private  void removeExpiredFlashMaps(HttpServletRequest request)
          Iterate all flash maps and remove expired ones.
 void requestCompleted(HttpServletRequest request)
          Start the expiration period of the "output" FlashMap save it in the underlying storage.
 void requestStarted(HttpServletRequest request)
          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(HttpServletRequest request, boolean allowCreate)
          Retrieve all FlashMap instances from the current HTTP session.
 void setFlashMapTimeout(int flashTimeout)
          Set the amount of time in seconds after a FlashMap is saved (at request completion) and before it expires.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FLASH_MAPS_SESSION_ATTRIBUTE

private static final java.lang.String FLASH_MAPS_SESSION_ATTRIBUTE

logger

private static final Log logger

flashTimeout

private int flashTimeout

urlPathHelper

private final UrlPathHelper urlPathHelper
Constructor Detail

DefaultFlashMapManager

public DefaultFlashMapManager()
Method Detail

setFlashMapTimeout

public void setFlashMapTimeout(int flashTimeout)
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.


requestStarted

public void requestStarted(HttpServletRequest request)
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

lookupFlashMap

private FlashMap lookupFlashMap(HttpServletRequest request)
Find the "input" FlashMap for the current request target by matching it to the target request information of all stored FlashMap instances.

Returns:
a FlashMap instance or null

isFlashMapForRequest

protected boolean isFlashMapForRequest(FlashMap flashMap,
                                       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(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

private void removeExpiredFlashMaps(HttpServletRequest request)
Iterate all flash maps and remove expired ones.


requestCompleted

public void requestCompleted(HttpServletRequest request)
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

onSaveFlashMap

protected void onSaveFlashMap(FlashMap flashMap,
                              HttpServletRequest request)
Update a FlashMap before it is stored in the HTTP Session.

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

decodeAndNormalizePath

private java.lang.String decodeAndNormalizePath(java.lang.String path,
                                                HttpServletRequest request)