站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > Spring Framework 2.0.5 API 文档英文版

PortletUtils (Spring Framework API 2.0) - Spring Framework 2.0.5 API 文档英文版

The Spring Framework

org.springframework.web.portlet.util
Class PortletUtils

java.lang.Object
  extended by org.springframework.web.portlet.util.PortletUtils

public abstract class PortletUtils
extends Object

Miscellaneous utilities for portlet applications. Used by various framework classes.

Since:
2.0
Author:
Juergen Hoeller, William G. Thompson, Jr., John A. Lewis

Constructor Summary
PortletUtils()
           
 
Method Summary
static void clearAllRenderParameters(ActionResponse response)
          Clear all the render parameters from the ActionResponse.
static void exposeRequestAttributes(PortletRequest request, Map attributes)
          Expose the given Map as request attributes, using the keys as attribute names and the values as corresponding attribute values.
static Object getOrCreateSessionAttribute(PortletSession session, String name, Class clazz)
          Get the specified session attribute under the PortletSession.PORTLET_SCOPE, creating and setting a new attribute if no existing found.
static Object getOrCreateSessionAttribute(PortletSession session, String name, Class clazz, int scope)
          Get the specified session attribute in the given scope, creating and setting a new attribute if no existing found.
static Map getParametersStartingWith(PortletRequest request, String prefix)
          Return a map containing all parameters with the given prefix.
static String getRealPath(PortletContext portletContext, String path)
          Return the real path of the given path within the web application, as provided by the portlet container.
static Object getRequiredSessionAttribute(PortletRequest request, String name)
          Check the given request for a session attribute of the given name under the PortletSession.PORTLET_SCOPE.
static Object getRequiredSessionAttribute(PortletRequest request, String name, int scope)
          Check the given request for a session attribute of the given name in the given scope.
static Object getSessionAttribute(PortletRequest request, String name)
          Check the given request for a session attribute of the given name under the PortletSession.PORTLET_SCOPE.
static Object getSessionAttribute(PortletRequest request, String name, int scope)
          Check the given request for a session attribute of the given name in the given scope.
static Object getSessionMutex(PortletSession session)
          Return the best available mutex for the given session: that is, an object to synchronize on for the given session.
static String getSubmitParameter(PortletRequest request, String name)
          Return the full name of a specific input type="submit" parameter if it was sent in the request, either via a button (directly with name) or via an image (name + ".x" or name + ".y").
static File getTempDir(PortletContext portletContext)
          Return the temporary directory for the current web application, as provided by the portlet container.
static boolean hasSubmitParameter(PortletRequest request, String name)
          Check if a specific input type="submit" parameter was sent in the request, either via a button (directly with name) or via an image (name + ".x" or name + ".y").
static void passAllParametersToRenderPhase(ActionRequest request, ActionResponse response)
          Pass all the action request parameters to the render phase by putting them into the action response object.
static void setSessionAttribute(PortletRequest request, String name, Object value)
          Set the session attribute with the given name to the given value under the PortletSession.PORTLET_SCOPE.
static void setSessionAttribute(PortletRequest request, String name, Object value, int scope)
          Set the session attribute with the given name to the given value in the given scope.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PortletUtils

public PortletUtils()
Method Detail

getTempDir

public static File getTempDir(PortletContext portletContext)
Return the temporary directory for the current web application, as provided by the portlet container.

Parameters:
portletContext - the portlet context of the web application
Returns:
the File representing the temporary directory
Throws:
IllegalArgumentException - if the supplied portletContext is null

getRealPath

public static String getRealPath(PortletContext portletContext,
                                 String path)
                          throws FileNotFoundException
Return the real path of the given path within the web application, as provided by the portlet container.

Prepends a slash if the path does not already start with a slash, and throws a FileNotFoundException if the path cannot be resolved to a resource (in contrast to PortletContext's getRealPath, which simply returns null).

Parameters:
portletContext - the portlet context of the web application
path - the relative path within the web application
Returns:
the corresponding real path
Throws:
FileNotFoundException - if the path cannot be resolved to a resource
IllegalArgumentException - if the supplied portletContext is null
NullPointerException - if the supplied path is null
See Also:
PortletContext.getRealPath(java.lang.String)

getSessionAttribute

public static Object getSessionAttribute(PortletRequest request,
                                         String name)
Check the given request for a session attribute of the given name under the PortletSession.PORTLET_SCOPE. Returns null if there is no session or if the session has no such attribute in that scope. Does not create a new session if none has existed before!

Parameters:
request - current portlet request
name - the name of the session attribute
Returns:
the value of the session attribute, or null if not found
Throws:
IllegalArgumentException - if the supplied request is null

getSessionAttribute

public static Object getSessionAttribute(PortletRequest request,
                                         String name,
                                         int scope)
Check the given request for a session attribute of the given name in the given scope. Returns null if there is no session or if the session has no such attribute in that scope. Does not create a new session if none has existed before!

Parameters:
request - current portlet request
name - the name of the session attribute
scope - session scope of this attribute
Returns:
the value of the session attribute, or null if not found
Throws:
IllegalArgumentException - if the supplied request is null

getRequiredSessionAttribute

public static Object getRequiredSessionAttribute(PortletRequest request,
                                                 String name)
                                          throws IllegalStateException
Check the given request for a session attribute of the given name under the PortletSession.PORTLET_SCOPE. Throws an exception if there is no session or if the session has no such attribute in that scope. Does not create a new session if none has existed before!

Parameters:
request - current portlet request
name - the name of the session attribute
Returns:
the value of the session attribute
Throws:
IllegalStateException - if the session attribute could not be found
IllegalArgumentException - if the supplied request is null

getRequiredSessionAttribute

public static Object getRequiredSessionAttribute(PortletRequest request,
                                                 String name,
                                                 int scope)
                                          throws IllegalStateException
Check the given request for a session attribute of the given name in the given scope. Throws an exception if there is no session or if the session has no such attribute in that scope. Does not create a new session if none has existed before!

Parameters:
request - current portlet request
name - the name of the session attribute
scope - session scope of this attribute
Returns:
the value of the session attribute
Throws:
IllegalStateException - if the session attribute could not be found
IllegalArgumentException - if the supplied request is null

setSessionAttribute

public static void setSessionAttribute(PortletRequest request,
                                       String name,
                                       Object value)
Set the session attribute with the given name to the given value under the PortletSession.PORTLET_SCOPE. Removes the session attribute if value is null, if a session existed at all. Does not create a new session if not necessary!

Parameters:
request - current portlet request
name - the name of the session attribute
value - the value of the session attribute
Throws:
IllegalArgumentException - if the supplied request is null

setSessionAttribute

public static void setSessionAttribute(PortletRequest request,
                                       String name,
                                       Object value,
                                       int scope)
Set the session attribute with the given name to the given value in the given scope. Removes the session attribute if value is null, if a session existed at all. Does not create a new session if not necessary!

Parameters:
request - current portlet request
name - the name of the session attribute
value - the value of the session attribute
scope - session scope of this attribute
Throws:
IllegalArgumentException - if the supplied request is null

getOrCreateSessionAttribute

public static Object getOrCreateSessionAttribute(PortletSession session,
                                                 String name,
                                                 Class clazz)
                                          throws IllegalArgumentException
Get the specified session attribute under the PortletSession.PORTLET_SCOPE, creating and setting a new attribute if no existing found. The given class needs to have a public no-arg constructor. Useful for on-demand state objects in a web tier, like shopping carts.

Parameters:
session - current portlet session
name - the name of the session attribute
clazz - the class to instantiate for a new attribute
Returns:
the value of the session attribute, newly created if not found
Throws:
IllegalArgumentException - if the session attribute could not be instantiated; or if the supplied session argument is null

getOrCreateSessionAttribute

public static Object getOrCreateSessionAttribute(PortletSession session,
                                                 String name,
                                                 Class clazz,
                                                 int scope)
                                          throws IllegalArgumentException
Get the specified session attribute in the given scope, creating and setting a new attribute if no existing found. The given class needs to have a public no-arg constructor. Useful for on-demand state objects in a web tier, like shopping carts.

Parameters:
session - current portlet session
name - the name of the session attribute
clazz - the class to instantiate for a new attribute
scope - the session scope of this attribute
Returns:
the value of the session attribute, newly created if not found
Throws:
IllegalArgumentException - if the session attribute could not be instantiated; or if the supplied session argument is null

getSessionMutex

public static Object getSessionMutex(PortletSession session)
Return the best available mutex for the given session: that is, an object to synchronize on for the given session.

Returns the session mutex attribute if available; usually, this means that the HttpSessionMutexListener needs to be defined in web.xml. Falls back to the PortletSession itself if no mutex attribute found.

The session mutex is guaranteed to be the same object during the entire lifetime of the session, available under the key defined by the WebUtils.SESSION_MUTEX_ATTRIBUTE constant. It serves as a safe reference to synchronize on for locking on the current session.

In many cases, the PortletSession reference itself is a safe mutex as well, since it will always be the same object reference for the same active logical session. However, this is not guaranteed across different servlet containers; the only 100% safe way is a session mutex.

Parameters:
session - the HttpSession to find a mutex for
Returns:
the mutex object (never null)
See Also:
WebUtils.SESSION_MUTEX_ATTRIBUTE, HttpSessionMutexListener

exposeRequestAttributes

public static void exposeRequestAttributes(PortletRequest request,
                                           Map attributes)
                                    throws IllegalArgumentException
Expose the given Map as request attributes, using the keys as attribute names and the values as corresponding attribute values. Keys must be Strings.

Parameters:
request - current portlet request
attributes - the attributes Map
Throws:
IllegalArgumentException - if an invalid key is found in the Map (i.e. the key is not a String); or if either of the supplied arguments is null

hasSubmitParameter

public static boolean hasSubmitParameter(PortletRequest request,
                                         String name)
Check if a specific input type="submit" parameter was sent in the request, either via a button (directly with name) or via an image (name + ".x" or name + ".y").

Parameters:
request - current portlet request
name - name of the parameter
Returns:
if the parameter was sent
See Also:
WebUtils.SUBMIT_IMAGE_SUFFIXES

getSubmitParameter

public static String getSubmitParameter(PortletRequest request,
                                        String name)
Return the full name of a specific input type="submit" parameter if it was sent in the request, either via a button (directly with name) or via an image (name + ".x" or name + ".y").

Parameters:
request - current portlet request
name - name of the parameter
Returns:
the actual parameter name with suffix if needed - null if not present
See Also:
WebUtils.SUBMIT_IMAGE_SUFFIXES

getParametersStartingWith

public static Map getParametersStartingWith(PortletRequest request,
                                            String prefix)
Return a map containing all parameters with the given prefix. Maps single values to String and multiple values to String array.

For example, with a prefix of "spring_", "spring_param1" and "spring_param2" result in a Map with "param1" and "param2" as keys.

Similar to portlet PortletRequest.getParameterMap(), but more flexible.

Parameters:
request - portlet request in which to look for parameters
prefix - the beginning of parameter names (if this is null or the empty string, all parameters will match)
Returns:
map containing request parameters without the prefix, containing either a String or a String array as values
See Also:
PortletRequest.getParameterNames(), PortletRequest.getParameterValues(java.lang.String), PortletRequest.getParameterMap()

passAllParametersToRenderPhase

public static void passAllParametersToRenderPhase(ActionRequest request,
                                                  ActionResponse response)
Pass all the action request parameters to the render phase by putting them into the action response object. This may not be called when the action will call sendRedirect.

Parameters:
request - the current action request
response - the current action response
See Also:
ActionResponse.setRenderParameter(java.lang.String, java.lang.String)

clearAllRenderParameters

public static void clearAllRenderParameters(ActionResponse response)
Clear all the render parameters from the ActionResponse. This may not be called when the action will call sendRedirect.

Parameters:
response - the current action response
See Also:
ActionResponse.setRenderParameters(java.util.Map)

The Spring Framework

Copyright © 2002-2007 The Spring Framework.