org.apache.velocity.tools.struts
Class StrutsUtils

java.lang.Object
  extended byorg.apache.velocity.tools.struts.StrutsUtils

public class StrutsUtils
extends java.lang.Object

A utility class to expose the Struts shared resources. All methods are static.

This class is provided for use by Velocity view tools that need access to Struts resources. By having all Struts- specific code in this utility class, maintenance is simplified and reuse fostered.

It is the aim, that sooner or later the functionality in this class is integrated into Struts itself. See Bug #16814 for more on that.

Version:
$Id: StrutsUtils.html,v 1.8.2.1 2004/05/17 17:09:43 nbubna Exp $
Author:
Marino A. Jonsson, Nathan Bubna, Gabe Sidler based on code by Ted Husted

Constructor Summary
StrutsUtils()
           
 
Method Summary
static java.lang.String errorMarkup(java.lang.String property, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpSession session, javax.servlet.ServletContext application)
          Returns a formatted error message.
static java.lang.String errorMarkup(java.lang.String property, java.lang.String bundle, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpSession session, javax.servlet.ServletContext application)
          Returns a formatted error message.
static org.apache.struts.action.ActionErrors getActionErrors(javax.servlet.http.HttpServletRequest request)
          Deprecated. use getErrors(HttpServletRequest request).
static org.apache.struts.action.ActionForm getActionForm(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpSession session)
          Returns the ActionForm bean associated with this request of null if none exists.
static org.apache.struts.action.ActionFormBeans getActionFormBeans(javax.servlet.ServletContext app)
          Deprecated. This will be removed in VelocityTools 1.2
static org.apache.struts.action.ActionForward getActionForward(java.lang.String name, javax.servlet.ServletContext app)
          Deprecated. This will be removed in VelocityTools 1.2
static org.apache.struts.action.ActionForwards getActionForwards(javax.servlet.ServletContext app)
          Deprecated. This will be removed in VelocityTools 1.2
static org.apache.struts.action.ActionMapping getActionMapping(java.lang.String path, javax.servlet.ServletContext app)
          Deprecated. This will be removed in VelocityTools 1.2
static java.lang.String getActionMappingName(java.lang.String action)
          Deprecated. This will be removed in VelocityTools 1.2
static org.apache.struts.action.ActionMappings getActionMappings(javax.servlet.ServletContext app)
          Deprecated. This will be removed in VelocityTools 1.2
static java.lang.String getActionMappingURL(javax.servlet.ServletContext application, javax.servlet.http.HttpServletRequest request, java.lang.String action)
          Returns the form action converted into a server-relative URI reference.
static org.apache.struts.action.ActionMessages getActionMessages(javax.servlet.http.HttpServletRequest request)
          Deprecated. use getMessages(HttpServletRequest request).
static java.lang.String getCancelName()
          Deprecated. This will be removed in VelocityTools 1.2
static javax.sql.DataSource getDataSource(javax.servlet.ServletContext app)
          Deprecated. This will be removed in VelocityTools 1.2
static org.apache.struts.action.ActionMessages getErrors(javax.servlet.http.HttpServletRequest request)
          Returns the Struts errors for this request or null if none exist.
static java.lang.Throwable getException(javax.servlet.http.HttpServletRequest request)
          Deprecated. This will be removed in VelocityTools 1.2
static org.apache.struts.config.FormBeanConfig getFormBean(java.lang.String name, javax.servlet.ServletContext app)
          Deprecated. This will be removed in VelocityTools 1.2
static java.lang.String getForwardURL(javax.servlet.http.HttpServletRequest request, javax.servlet.ServletContext app, java.lang.String forward)
          Returns the action forward name converted into a server-relative URI reference.
static java.lang.String getGlobalErrorName()
          Deprecated. This will be removed in VelocityTools 1.2
static java.util.Locale getLocale(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpSession session)
          Returns the java.util.Locale for the user.
static org.apache.struts.util.MessageResources getMessageResources(javax.servlet.http.HttpServletRequest request, javax.servlet.ServletContext app)
          Returns the message resources for this application or null if not found.
static org.apache.struts.util.MessageResources getMessageResources(javax.servlet.http.HttpServletRequest request, javax.servlet.ServletContext app, java.lang.String bundle)
          Returns the message resources with the specified bundle name for this application or null if not found.
static org.apache.struts.util.MessageResources getMessageResources(javax.servlet.ServletContext app)
          Deprecated. This will be removed in VelocityTools 1.2
static org.apache.struts.action.ActionMessages getMessages(javax.servlet.http.HttpServletRequest request)
          Returns the Struts messages for this request or null if none exist.
static org.apache.struts.upload.MultipartRequestWrapper getMultipartRequestWrapper(javax.servlet.http.HttpServletRequest request)
          Deprecated. This will be removed in VelocityTools 1.2
static java.lang.String getServletMapping(javax.servlet.ServletContext app)
          Deprecated. This will be removed in VelocityTools 1.2
static java.lang.String getToken(javax.servlet.http.HttpSession session)
          Returns the transaction token stored in this session or null if not used.
static java.lang.String getTokenName()
          Deprecated. This will be removed in VelocityTools 1.2
static org.apache.struts.config.ModuleConfig selectModule(java.lang.String urlPath, javax.servlet.ServletContext app)
          Select the module to which the specified request belongs, and add return the corresponding ModuleConfig.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StrutsUtils

public StrutsUtils()
Method Detail

getDataSource

public static javax.sql.DataSource getDataSource(javax.servlet.ServletContext app)
Deprecated. This will be removed in VelocityTools 1.2

Returns the default configured data source (which must implement javax.sql.DataSource) or null if not found.

Parameters:
app - the servlet context

getActionFormBeans

public static org.apache.struts.action.ActionFormBeans getActionFormBeans(javax.servlet.ServletContext app)
Deprecated. This will be removed in VelocityTools 1.2

Returns the org.apache.struts.action.ActionFormBeans collection for this application or null if not found.

Parameters:
app - the servlet context

getFormBean

public static org.apache.struts.config.FormBeanConfig getFormBean(java.lang.String name,
                                                                  javax.servlet.ServletContext app)
Deprecated. This will be removed in VelocityTools 1.2

Returns the form bean definition associated with the specified logical name or null if not found.

Parameters:
name - logical name of the requested form bean definition
app - the servlet context

getActionForwards

public static org.apache.struts.action.ActionForwards getActionForwards(javax.servlet.ServletContext app)
Deprecated. This will be removed in VelocityTools 1.2

Returns the org.apache.struts.action.ActionForwards collection for this application or null if not found.

Parameters:
app - the servlet context

getActionForward

public static org.apache.struts.action.ActionForward getActionForward(java.lang.String name,
                                                                      javax.servlet.ServletContext app)
Deprecated. This will be removed in VelocityTools 1.2

Returns the forwarding associated with the specified logical name or null if not found.

Parameters:
name - Logical name of the requested forwarding
app - the servlet context

getActionMappings

public static org.apache.struts.action.ActionMappings getActionMappings(javax.servlet.ServletContext app)
Deprecated. This will be removed in VelocityTools 1.2

Returns the org.apache.struts.action.ActionMappings collection for this application or null if not found.

Parameters:
app - the servlet context

getActionMapping

public static org.apache.struts.action.ActionMapping getActionMapping(java.lang.String path,
                                                                      javax.servlet.ServletContext app)
Deprecated. This will be removed in VelocityTools 1.2

Returns the mapping associated with the specified request path, or null if not found.

Parameters:
path - Request path for which a mapping is requested
app - the servlet context

getMessageResources

public static org.apache.struts.util.MessageResources getMessageResources(javax.servlet.ServletContext app)
Deprecated. This will be removed in VelocityTools 1.2

Returns the message resources for this application or null if not found.

Parameters:
app - the servlet context

getMessageResources

public static org.apache.struts.util.MessageResources getMessageResources(javax.servlet.http.HttpServletRequest request,
                                                                          javax.servlet.ServletContext app)
Returns the message resources for this application or null if not found.

Parameters:
app - the servlet context
Since:
VelocityTools 1.1

getMessageResources

public static org.apache.struts.util.MessageResources getMessageResources(javax.servlet.http.HttpServletRequest request,
                                                                          javax.servlet.ServletContext app,
                                                                          java.lang.String bundle)
Returns the message resources with the specified bundle name for this application or null if not found.

Parameters:
app - the servlet context
bundle - The bundle name to look for. If this is null, the default bundle name is used.
Since:
VelocityTools 1.1

selectModule

public static org.apache.struts.config.ModuleConfig selectModule(java.lang.String urlPath,
                                                                 javax.servlet.ServletContext app)
Select the module to which the specified request belongs, and add return the corresponding ModuleConfig.

Parameters:
urlPath - The requested URL
app - The ServletContext for this web application
Returns:
The ModuleConfig for the given URL path
Since:
VelocityTools 1.1

getServletMapping

public static java.lang.String getServletMapping(javax.servlet.ServletContext app)
Deprecated. This will be removed in VelocityTools 1.2

Returns the servlet mapping used for this application or null if not found. The servlet mapping is either a path-mapped pattern (/action/*) or an extension mapped pattern (*.do).

Parameters:
app - the servlet context

getLocale

public static java.util.Locale getLocale(javax.servlet.http.HttpServletRequest request,
                                         javax.servlet.http.HttpSession session)
Returns the java.util.Locale for the user. If a locale object is not found in the user's session, the system default locale is returned.

Parameters:
request - the servlet request
session - the HTTP session

getToken

public static java.lang.String getToken(javax.servlet.http.HttpSession session)
Returns the transaction token stored in this session or null if not used.

Parameters:
session - the HTTP session

getErrors

public static org.apache.struts.action.ActionMessages getErrors(javax.servlet.http.HttpServletRequest request)
Returns the Struts errors for this request or null if none exist.

Parameters:
request - the servlet request
Since:
VelocityTools 1.1

getMessages

public static org.apache.struts.action.ActionMessages getMessages(javax.servlet.http.HttpServletRequest request)
Returns the Struts messages for this request or null if none exist.

Parameters:
request - the servlet request
Since:
VelocityTools 1.1

getActionErrors

public static org.apache.struts.action.ActionErrors getActionErrors(javax.servlet.http.HttpServletRequest request)
Deprecated. use getErrors(HttpServletRequest request).


getActionMessages

public static org.apache.struts.action.ActionMessages getActionMessages(javax.servlet.http.HttpServletRequest request)
Deprecated. use getMessages(HttpServletRequest request).


getException

public static java.lang.Throwable getException(javax.servlet.http.HttpServletRequest request)
Deprecated. This will be removed in VelocityTools 1.2

Returns the runtime Exception that may have been thrown by a Struts view tool or compatible presentation extension, and placed in the request. Returns null if none found.

Parameters:
request - the servlet request

getMultipartRequestWrapper

public static org.apache.struts.upload.MultipartRequestWrapper getMultipartRequestWrapper(javax.servlet.http.HttpServletRequest request)
Deprecated. This will be removed in VelocityTools 1.2

Returns the multipart object for this request or null if none exists.

Parameters:
request - the servlet request

getActionForm

public static org.apache.struts.action.ActionForm getActionForm(javax.servlet.http.HttpServletRequest request,
                                                                javax.servlet.http.HttpSession session)
Returns the ActionForm bean associated with this request of null if none exists.

Parameters:
request - the servlet request
session - the HTTP session

getCancelName

public static java.lang.String getCancelName()
Deprecated. This will be removed in VelocityTools 1.2

Returns the query parameter name under which a cancel button press must be reported if form validation is to be skipped.


getGlobalErrorName

public static java.lang.String getGlobalErrorName()
Deprecated. This will be removed in VelocityTools 1.2

Returns the default "GLOBAL" category name that can be used with messages that are not associated with a particular property.


getTokenName

public static java.lang.String getTokenName()
Deprecated. This will be removed in VelocityTools 1.2

Returns the query parameter name under which a transaction token must be reported.


getActionMappingName

public static java.lang.String getActionMappingName(java.lang.String action)
Deprecated. This will be removed in VelocityTools 1.2

Returns the form action converted into an action mapping path. The value of the action property is manipulated as follows in computing the name of the requested mapping:

Parameters:
action - the name of an action as per struts-config.xml

getActionMappingURL

public static java.lang.String getActionMappingURL(javax.servlet.ServletContext application,
                                                   javax.servlet.http.HttpServletRequest request,
                                                   java.lang.String action)
Returns the form action converted into a server-relative URI reference.

Parameters:
application - the servlet context
request - the servlet request
action - the name of an action as per struts-config.xml

getForwardURL

public static java.lang.String getForwardURL(javax.servlet.http.HttpServletRequest request,
                                             javax.servlet.ServletContext app,
                                             java.lang.String forward)
Returns the action forward name converted into a server-relative URI reference.

Parameters:
app - the servlet context
request - the servlet request
forward - the name of a forward as per struts-config.xml

errorMarkup

public static java.lang.String errorMarkup(java.lang.String property,
                                           javax.servlet.http.HttpServletRequest request,
                                           javax.servlet.http.HttpSession session,
                                           javax.servlet.ServletContext application)
Returns a formatted error message. The error message is assembled from the following three pieces: First, value of message resource "errors.header" is prepended. Then, the list of error messages is rendered. Finally, the value of message resource "errors.footer" is appended.

Parameters:
property - the category of errors to markup and return
request - the servlet request
session - the HTTP session
application - the servlet context
Returns:
The formatted error message. If no error messages are queued, an empty string is returned.

errorMarkup

public static java.lang.String errorMarkup(java.lang.String property,
                                           java.lang.String bundle,
                                           javax.servlet.http.HttpServletRequest request,
                                           javax.servlet.http.HttpSession session,
                                           javax.servlet.ServletContext application)
Returns a formatted error message. The error message is assembled from the following three pieces: First, value of message resource "errors.header" is prepended. Then, the list of error messages is rendered. Finally, the value of message resource "errors.footer" is appended.

Parameters:
property - the category of errors to markup and return
bundle - the message resource bundle to use
request - the servlet request
session - the HTTP session
application - the servlet context
Returns:
The formatted error message. If no error messages are queued, an empty string is returned.
Since:
VelocityTools 1.1


Copyright (c) 2003 Apache Software Foundation