com.scooterframework.web.controller
Class ActionContext

java.lang.Object
  extended by com.scooterframework.web.controller.ActionContext
Direct Known Subclasses:
AppActionContext, WebActionContext

public abstract class ActionContext
extends java.lang.Object

ActionContext class holds context data in different scopes.

There are six supported scopes: thread, parameter, request, session, context and global. The first scope supports data held in current thread, the next four scopes map to the corresponding scopes in Servlet and JSP for web environment. The global scope provides a place for the whole application to access data that can be used for all users in a static way.


Field Summary
protected  java.util.Map<java.lang.String,java.lang.Object> errors
          Errors map.
static java.lang.String KEY_FLASH_MESSAGE
           
static java.lang.String SCOPE_CONTEXT
          String constant for context scope.
static java.lang.String SCOPE_GLOBAL
          String constant for global scope.
static java.lang.String SCOPE_PARAMETER
          String constant for parameter scope.
static java.lang.String SCOPE_REQUEST
          String constant for request scope.
static java.lang.String SCOPE_SESSION
          String constant for session scope.
static java.lang.String SCOPE_THREAD
          String constant for thread scope.
 
Constructor Summary
ActionContext()
           
 
Method Summary
 java.lang.String currentCycle(java.lang.String name)
          Returns current item in the named cycle.
 java.lang.String cycle(java.lang.String items)
          Returns an item from a list of items.
 java.lang.String cycle(java.lang.String items, java.lang.String name)
          Returns an item from a list of items.
 java.lang.Object get(java.lang.String key)
          Gets data represented by the key from the first scope it is found.
 java.lang.Object get(java.lang.String key, java.lang.String scope)
          Gets data represented by the key from the specific scope.
 java.util.List<Message> getAllFlashMessages(java.lang.String type)
          Gets all messages represented by the type from the flash.
 java.util.Map<java.lang.String,java.lang.Object> getAllRequestDataAsMap()
          Gets data in both parameter scope and request scope as a map.
 java.util.Map<java.lang.String,java.lang.Object> getAllRequestDataAsMap(java.lang.String keyPrefix)
          Gets data in both parameter scope and request scope as a map.
abstract  java.util.Map<java.lang.String,java.lang.Object> getContextDataAsMap()
          Gets data in context scope as a map.
protected abstract  java.lang.Object getCycleFromCycleMap(java.lang.String name)
          Returns a named cycle from cycle map.
 java.lang.Object getError(java.lang.String key)
          Gets an error object represented by a key to error map.
 java.util.Map<java.lang.String,java.lang.Object> getErrorAsMap()
          Returns errors as Map.
 java.lang.String getFirstFlashMessage(java.lang.String type)
          Gets the first message represented by the type from the flash.
 java.lang.Object getFromAllRequestData(java.lang.String key)
          Gets data represented by the key from the first scope it is found in parameter scope and request scope.
abstract  java.lang.Object getFromContextData(java.lang.String key)
          Gets data represented by the key from the context scope.
static java.lang.Object getFromGlobalData(java.lang.String key)
          Gets data represented by the key from the global scope.
abstract  java.lang.Object getFromParameterData(java.lang.String key)
          Gets data represented by the key from the parameter scope.
 java.lang.Object getFromParameterDataIgnoreCase(java.lang.String key)
          Gets data represented by the key from the parameter scope.
abstract  java.lang.Object getFromRequestData(java.lang.String key)
          Gets data represented by the key from the request scope.
abstract  java.lang.Object getFromSessionData(java.lang.String key)
          Gets data represented by the key from the session scope.
static java.lang.Object getFromThreadData(java.lang.String key)
          Gets data represented by the key from the thread scope.
static java.util.Map<java.lang.String,java.lang.Object> getGlobalDataAsMap()
          Gets data in global scope as a map.
static java.util.Locale getGlobalLocale()
          Gets a locale object that can be used by all users.
 java.lang.String getLatestFlashMessage(java.lang.String type)
          Gets the latest message represented by the type from the flash.
 java.util.Locale getLocale()
          Returns Locale object from the first scope it is found.
 java.util.Locale getLocale(java.lang.String scope)
          Returns Locale of a scope.
abstract  java.util.Map<java.lang.String,java.lang.Object> getParameterDataAsMap()
          Gets data in parameter scope as a map.
 java.util.Map<java.lang.String,java.lang.Object> getParameterDataAsMap(java.lang.String keyPrefix)
          Gets data in parameter scope as a map.
abstract  java.util.Map<java.lang.String,java.lang.Object> getRequestDataAsMap()
          Gets data in request scope as a map.
 java.util.Map<java.lang.String,java.lang.Object> getRequestDataAsMap(java.lang.String keyPrefix)
          Gets data in request scope as a map.
abstract  java.util.Map<java.lang.String,java.lang.Object> getSessionDataAsMap()
          Gets data in session scope as a map.
 boolean isRequiredField(java.lang.String name)
          Checks if the value of a field is required.
 void remove(java.lang.String key)
          Removes data represented by the key from all scopes except the parameter scope.
abstract  void removeAllSessionData()
          Removes all data represented by the key from session scope.
abstract  void removeFromContextData(java.lang.String key)
          Removes data represented by the key from context scope.
static void removeFromGlobalData(java.lang.String key)
          Removes data represented by the key from global scope.
abstract  void removeFromRequestData(java.lang.String key)
          Removes data represented by the key from request scope.
abstract  void removeFromSessionData(java.lang.String key)
          Removes data represented by the key from session scope.
static void removeFromThreadData(java.lang.String key)
          Removes data represented by the key from thread scope.
 void resetCycle(java.lang.String name)
          Resets the cycle
 void resetFlashMessage()
          Removes FlashMessage data from session and stores it in the incoming request.
 java.util.Map<java.lang.String,java.lang.Object> retrievePrimaryKeyDataMapFromRequest(java.lang.String[] pkNames)
          Retrieves a map of primary key and values.
 java.util.Map<java.lang.String,java.lang.Object> retrievePrimaryKeyDataMapFromRequest(java.lang.String keyPrefix, java.lang.String[] pkNames)
          Retrieves a map of primary key and values.
protected abstract  void setCycleToCycleMap(java.lang.String name, java.lang.Object cycle)
          Sets a named cycle in cycle map.
 void setError(java.lang.String key, java.lang.Object error)
          Sets an error object represented by a key to error map.
 void setErrors(java.util.Map<java.lang.String,java.lang.Object> errors)
          Sets a map of error to error map.
 void setFlashMessage(java.lang.String type, Message message)
          Sets message for a type.
 void setFlashMessage(java.lang.String type, java.lang.String message)
          Sets message for a type.
static void setGlobalLocale(java.util.Locale locale)
          Sets locale object to be used by all users.
 void setLocale(java.util.Locale locale, java.lang.String scope)
          Stores locale object in a scope.
 void setRequestLocale(java.util.Locale locale)
          Sets locale object to be used by a single user request.
 void setSessionLocale(java.util.Locale locale)
          Sets locale object to be used by a single user session.
abstract  void storeToContext(java.lang.String key, java.lang.Object object)
          Stores the object represented by the key to context scope.
static void storeToGlobal(java.lang.String key, java.lang.Object value)
          Stores the object represented by the key to global scope.
abstract  void storeToRequest(java.lang.String key, java.lang.Object value)
          Stores the object represented by the key to request scope.
abstract  void storeToSession(java.lang.String key, java.lang.Object value)
          Stores the object represented by the key to session scope.
static void storeToThread(java.lang.String key, java.lang.Object value)
          Stores the object represented by the key to thread scope.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

KEY_FLASH_MESSAGE

public static final java.lang.String KEY_FLASH_MESSAGE
See Also:
Constant Field Values

SCOPE_THREAD

public static final java.lang.String SCOPE_THREAD
String constant for thread scope.

See Also:
Constant Field Values

SCOPE_PARAMETER

public static final java.lang.String SCOPE_PARAMETER
String constant for parameter scope.

See Also:
Constant Field Values

SCOPE_REQUEST

public static final java.lang.String SCOPE_REQUEST
String constant for request scope.

See Also:
Constant Field Values

SCOPE_SESSION

public static final java.lang.String SCOPE_SESSION
String constant for session scope.

See Also:
Constant Field Values

SCOPE_CONTEXT

public static final java.lang.String SCOPE_CONTEXT
String constant for context scope.

See Also:
Constant Field Values

SCOPE_GLOBAL

public static final java.lang.String SCOPE_GLOBAL
String constant for global scope.

See Also:
Constant Field Values

errors

protected java.util.Map<java.lang.String,java.lang.Object> errors
Errors map.

Constructor Detail

ActionContext

public ActionContext()
Method Detail

getParameterDataAsMap

public abstract java.util.Map<java.lang.String,java.lang.Object> getParameterDataAsMap()

Gets data in parameter scope as a map.

Return guaranteed: An empty map will be returned if there is no data.

Returns:
Map

getRequestDataAsMap

public abstract java.util.Map<java.lang.String,java.lang.Object> getRequestDataAsMap()

Gets data in request scope as a map.

Return guaranteed: An empty map will be returned if there is no data.

Returns:
Map

getAllRequestDataAsMap

public java.util.Map<java.lang.String,java.lang.Object> getAllRequestDataAsMap()

Gets data in both parameter scope and request scope as a map.

Return guaranteed: An empty map will be returned if there is no data.

Returns:
Map

getParameterDataAsMap

public java.util.Map<java.lang.String,java.lang.Object> getParameterDataAsMap(java.lang.String keyPrefix)

Gets data in parameter scope as a map. Only those keys with a specific keyPrefix will be processed.

Return guaranteed: An empty map will be returned if there is no data.

Returns:
Map

getRequestDataAsMap

public java.util.Map<java.lang.String,java.lang.Object> getRequestDataAsMap(java.lang.String keyPrefix)

Gets data in request scope as a map. Only those keys with a specific keyPrefix will be processed.

Return guaranteed: An empty map will be returned if there is no data.

Returns:
Map

getAllRequestDataAsMap

public java.util.Map<java.lang.String,java.lang.Object> getAllRequestDataAsMap(java.lang.String keyPrefix)

Gets data in both parameter scope and request scope as a map. Only those keys with a specific keyPrefix will be processed.

Return guaranteed: An empty map will be returned if there is no data.

Returns:
Map

getSessionDataAsMap

public abstract java.util.Map<java.lang.String,java.lang.Object> getSessionDataAsMap()

Gets data in session scope as a map.

Return guaranteed: An empty map will be returned if there is no data.

Returns:
Map

getContextDataAsMap

public abstract java.util.Map<java.lang.String,java.lang.Object> getContextDataAsMap()
Gets data in context scope as a map.

Returns:
Map

getGlobalDataAsMap

public static java.util.Map<java.lang.String,java.lang.Object> getGlobalDataAsMap()
Gets data in global scope as a map.

Returns:
Map

getFromThreadData

public static java.lang.Object getFromThreadData(java.lang.String key)

Gets data represented by the key from the thread scope.

Note: The result of this method is sensitive to the case of key string.

Parameters:
key -
Returns:
Object

getFromParameterData

public abstract java.lang.Object getFromParameterData(java.lang.String key)

Gets data represented by the key from the parameter scope.

Note: The result of this method is sensitive to the case of key string.

Parameters:
key -
Returns:
Object

getFromParameterDataIgnoreCase

public java.lang.Object getFromParameterDataIgnoreCase(java.lang.String key)

Gets data represented by the key from the parameter scope. Ignore the case of the key string.

Note: The result of this method is sensitive to the case of key string.

Parameters:
key -
Returns:
Object

getFromRequestData

public abstract java.lang.Object getFromRequestData(java.lang.String key)

Gets data represented by the key from the request scope.

Note: The result of this method is sensitive to the case of key string.

Parameters:
key -
Returns:
Object

getFromSessionData

public abstract java.lang.Object getFromSessionData(java.lang.String key)

Gets data represented by the key from the session scope.

Note: The result of this method is sensitive to the case of key string.

Parameters:
key -
Returns:
Object

getFromContextData

public abstract java.lang.Object getFromContextData(java.lang.String key)

Gets data represented by the key from the context scope.

Note: The result of this method is sensitive to the case of key string.

Parameters:
key -
Returns:
Object

getFromGlobalData

public static java.lang.Object getFromGlobalData(java.lang.String key)

Gets data represented by the key from the global scope.

Note: The result of this method is sensitive to the case of key string.

Parameters:
key -
Returns:
Object

getFirstFlashMessage

public java.lang.String getFirstFlashMessage(java.lang.String type)
Gets the first message represented by the type from the flash.

Parameters:
type -
Returns:
String

getLatestFlashMessage

public java.lang.String getLatestFlashMessage(java.lang.String type)
Gets the latest message represented by the type from the flash.

Parameters:
type -
Returns:
String

getAllFlashMessages

public java.util.List<Message> getAllFlashMessages(java.lang.String type)
Gets all messages represented by the type from the flash.

Parameters:
type - flash message type
Returns:
list of messages

getFromAllRequestData

public java.lang.Object getFromAllRequestData(java.lang.String key)

Gets data represented by the key from the first scope it is found in parameter scope and request scope.

Note: The result of this method is sensitive to the case of key string.

Parameters:
key -
Returns:
Object

get

public java.lang.Object get(java.lang.String key)

Gets data represented by the key from the first scope it is found.

There are six supported scopes: thread, parameter, request, session, context and global. The first scope supports data held in current thread, the next four scopes map to the corresponding scopes in Servlet and JSP for web environment. The global scope provides a place for the whole application to access data that can be used for all users in a static way.

Note: The result of this method is sensitive to the case of key string.

Parameters:
key -
Returns:
Object

get

public java.lang.Object get(java.lang.String key,
                            java.lang.String scope)

Gets data represented by the key from the specific scope.

There are six supported scopes: thread, parameter, request, session, context and global. The first scope supports data held in current thread, the next four scopes map to the corresponding scopes in Servlet and JSP for web environment. The global scope provides a place for the whole application to access data that can be used for all users in a static way.

Note: The result of this method is sensitive to the case of key string.

Parameters:
key -
Returns:
Object

remove

public void remove(java.lang.String key)

Removes data represented by the key from all scopes except the parameter scope. There is no servlet API that can remove data from parameter scope.

Note: The result of this method is sensitive to the case of key string.

Parameters:
key -

removeFromThreadData

public static void removeFromThreadData(java.lang.String key)

Removes data represented by the key from thread scope.

Note: The result of this method is sensitive to the case of key string.

Parameters:
key -

removeFromRequestData

public abstract void removeFromRequestData(java.lang.String key)

Removes data represented by the key from request scope.

Note: The result of this method is sensitive to the case of key string.

Parameters:
key -

removeFromSessionData

public abstract void removeFromSessionData(java.lang.String key)

Removes data represented by the key from session scope.

Note: The result of this method is sensitive to the case of key string.

Parameters:
key -

removeFromContextData

public abstract void removeFromContextData(java.lang.String key)

Removes data represented by the key from context scope.

Note: The result of this method is sensitive to the case of key string.

Parameters:
key -

removeFromGlobalData

public static void removeFromGlobalData(java.lang.String key)

Removes data represented by the key from global scope.

Note: The result of this method is sensitive to the case of key string.

Parameters:
key -

removeAllSessionData

public abstract void removeAllSessionData()
Removes all data represented by the key from session scope.


storeToThread

public static void storeToThread(java.lang.String key,
                                 java.lang.Object value)
Stores the object represented by the key to thread scope.

Parameters:
key - String
value - Object

storeToRequest

public abstract void storeToRequest(java.lang.String key,
                                    java.lang.Object value)
Stores the object represented by the key to request scope.

Parameters:
key - String
value - Object

storeToSession

public abstract void storeToSession(java.lang.String key,
                                    java.lang.Object value)
Stores the object represented by the key to session scope.

Parameters:
key - String
value - Object

storeToContext

public abstract void storeToContext(java.lang.String key,
                                    java.lang.Object object)
Stores the object represented by the key to context scope.

Parameters:
key - String
object - Object

storeToGlobal

public static void storeToGlobal(java.lang.String key,
                                 java.lang.Object value)
Stores the object represented by the key to global scope.

Parameters:
key - String
value - Object

setFlashMessage

public void setFlashMessage(java.lang.String type,
                            java.lang.String message)
Sets message for a type.


setFlashMessage

public void setFlashMessage(java.lang.String type,
                            Message message)
Sets message for a type.


resetFlashMessage

public void resetFlashMessage()
Removes FlashMessage data from session and stores it in the incoming request.


getErrorAsMap

public java.util.Map<java.lang.String,java.lang.Object> getErrorAsMap()
Returns errors as Map.

Returns:
Map of error

setErrors

public void setErrors(java.util.Map<java.lang.String,java.lang.Object> errors)
Sets a map of error to error map.

Parameters:
errors - Map

getError

public java.lang.Object getError(java.lang.String key)
Gets an error object represented by a key to error map.

Parameters:
key - The key to the error object.
Returns:
error Object

setError

public void setError(java.lang.String key,
                     java.lang.Object error)
Sets an error object represented by a key to error map.

Parameters:
error - An error object.

retrievePrimaryKeyDataMapFromRequest

public java.util.Map<java.lang.String,java.lang.Object> retrievePrimaryKeyDataMapFromRequest(java.lang.String keyPrefix,
                                                                                             java.lang.String[] pkNames)

Retrieves a map of primary key and values.

The result map is restricted to those keys in the input with a specific prefix.

Parameters:
keyPrefix - a prefix string.
pkNames - an array of primary key names.
Returns:
map Map of primary key data.

retrievePrimaryKeyDataMapFromRequest

public java.util.Map<java.lang.String,java.lang.Object> retrievePrimaryKeyDataMapFromRequest(java.lang.String[] pkNames)
Retrieves a map of primary key and values.

Parameters:
pkNames - an array of primary key names.
Returns:
map Map of primary key data.

isRequiredField

public boolean isRequiredField(java.lang.String name)
Checks if the value of a field is required.

Parameters:
name - name of a request parameter.
Returns:
true if required

getLocale

public java.util.Locale getLocale()

Returns Locale object from the first scope it is found. If no locale object is found, Locale.getDefault() is returned.

There are six supported scopes: thread, parameter, request, session, context and global. The first scope supports data held in current thread, the next four scopes map to the corresponding scopes in Servlet and JSP for web environment. The global scope provides a place for the whole application to access data that can be used for all users in a static way.

Returns:
Locale for the scope

getLocale

public java.util.Locale getLocale(java.lang.String scope)
Returns Locale of a scope. If no locale object is found, Locale.getDefault() is returned.

Parameters:
scope - the specific scope
Returns:
Locale for the scope

setLocale

public void setLocale(java.util.Locale locale,
                      java.lang.String scope)
Stores locale object in a scope. The scope is either request or session or context or global.

Parameters:
locale -
scope -

setRequestLocale

public void setRequestLocale(java.util.Locale locale)
Sets locale object to be used by a single user request.

Parameters:
locale -

setSessionLocale

public void setSessionLocale(java.util.Locale locale)
Sets locale object to be used by a single user session.

Parameters:
locale -

setGlobalLocale

public static void setGlobalLocale(java.util.Locale locale)
Sets locale object to be used by all users.

Parameters:
locale -

getGlobalLocale

public static java.util.Locale getGlobalLocale()
Gets a locale object that can be used by all users.


cycle

public java.lang.String cycle(java.lang.String items)
Returns an item from a list of items. Examples:
      class=<%=W.cycle("odd, even")%> 
      -- use "red" class for odd rows and "blue" class for even rows.
 

Parameters:
items - list of items to be cycled
Returns:
an item value

cycle

public java.lang.String cycle(java.lang.String items,
                              java.lang.String name)
Returns an item from a list of items. The items string may contain several items separated by comma.

Parameters:
items - list of items to be cycled
name - the cycle name
Returns:
an item value

currentCycle

public java.lang.String currentCycle(java.lang.String name)
Returns current item in the named cycle.

Parameters:
name - name of the cycle
Returns:
current item in the named cycle.

resetCycle

public void resetCycle(java.lang.String name)
Resets the cycle

Parameters:
name - cycle's name

getCycleFromCycleMap

protected abstract java.lang.Object getCycleFromCycleMap(java.lang.String name)
Returns a named cycle from cycle map.

Parameters:
name -
Returns:
cycle object

setCycleToCycleMap

protected abstract void setCycleToCycleMap(java.lang.String name,
                                           java.lang.Object cycle)
Sets a named cycle in cycle map.

Parameters:
name -
cycle -