org.apache.velocity.tools.struts
Class StrutsUtils

java.lang.Object
  |
  +--org.apache.velocity.tools.struts.StrutsUtils

class StrutsUtils
extends java.lang.Object

A package-internal 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. Ideally, they will yank the JSP-centric code (PageContext, etc.) out of their RequestUtils to allow other view layers to leverage that code.

Version:
$Revision: 1.2 $
Author:
Gabe Sidler, based on code by Ted Husted

Constructor Summary
(package private) StrutsUtils()
           
 
Method Summary
(package private) 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.
(package private) static org.apache.struts.action.ActionErrors getActionErrors(javax.servlet.http.HttpServletRequest request)
          Returns the org.apache.struts.action.ActionErrors object for this request or null if none exists.
(package private) 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.
(package private) static org.apache.struts.action.ActionFormBeans getActionFormBeans(javax.servlet.ServletContext application)
          Returns the org.apache.struts.action.ActionFormBeans collection for this application or null if not found.
(package private) static org.apache.struts.action.ActionForward getActionForward(java.lang.String name, javax.servlet.ServletContext application)
          Returns the forwarding associated with the specified logical name or null if not found.
(package private) static org.apache.struts.action.ActionForwards getActionForwards(javax.servlet.ServletContext application)
          Returns the org.apache.struts.action.ActionForwards collection for this application or null if not found.
(package private) static org.apache.struts.action.ActionMapping getActionMapping(java.lang.String path, javax.servlet.ServletContext application)
          Returns the mapping associated with the specified request path, or null if not found.
(package private) static java.lang.String getActionMappingName(java.lang.String action)
          Returns the form action converted into an action mapping path.
(package private) static org.apache.struts.action.ActionMappings getActionMappings(javax.servlet.ServletContext application)
          Returns the org.apache.struts.action.ActionMappings collection for this application or null if not found.
(package private) 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.
(package private) static java.lang.String getCancelName()
          Returns the query parameter name under which a cancel button press must be reported if form validation is to be skipped.
(package private) static javax.sql.DataSource getDataSource(javax.servlet.ServletContext application)
          Returns the default configured data source (which must implement javax.sql.DataSource) or null if not found.
(package private) static java.lang.Throwable getException(javax.servlet.http.HttpServletRequest request)
          Returns the runtime Exception that may have been thrown by a Struts view tool or compatible presentation extension, and placed in the request.
(package private) static org.apache.struts.action.ActionFormBean getFormBean(java.lang.String name, javax.servlet.ServletContext application)
          Returns the form bean definition associated with the specified logical name or null if not found.
(package private) static java.lang.String getGlobalErrorName()
          Returns the default "GLOBAL" category name that can be used with messages that are not associated with a particular property.
(package private) static java.util.Locale getLocale(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpSession session)
          Returns the java.util.Locale for the user.
(package private) static org.apache.struts.action.ActionMapping getMapping(javax.servlet.http.HttpServletRequest request)
          Returns the org.apache.struts.ActionMapping instance for this request or null if none exists.
(package private) static org.apache.struts.util.MessageResources getMessageResources(javax.servlet.ServletContext application)
          Returns the message resources for this application or null if not found.
(package private) static org.apache.struts.upload.MultipartRequestWrapper getMultipartRequestWrapper(javax.servlet.http.HttpServletRequest request)
          Returns the multipart object for this request or null if none exists.
(package private) static java.lang.String getServletMapping(javax.servlet.ServletContext application)
          Returns the servlet mapping used for this application or null if not found.
(package private) static java.lang.String getToken(javax.servlet.http.HttpSession session)
          Returns the transaction token stored in this session or null if not used.
(package private) static java.lang.String getTokenName()
          Returns the query parameter name under which a transaction token must be reported.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StrutsUtils

StrutsUtils()
Method Detail

getDataSource

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

Parameters:
application - the servlet context

getActionFormBeans

static org.apache.struts.action.ActionFormBeans getActionFormBeans(javax.servlet.ServletContext application)
Returns the org.apache.struts.action.ActionFormBeans collection for this application or null if not found.

Parameters:
application - the servlet context

getFormBean

static org.apache.struts.action.ActionFormBean getFormBean(java.lang.String name,
                                                           javax.servlet.ServletContext application)
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
application - the servlet context

getActionForwards

static org.apache.struts.action.ActionForwards getActionForwards(javax.servlet.ServletContext application)
Returns the org.apache.struts.action.ActionForwards collection for this application or null if not found.

Parameters:
application - the servlet context

getActionForward

static org.apache.struts.action.ActionForward getActionForward(java.lang.String name,
                                                               javax.servlet.ServletContext application)
Returns the forwarding associated with the specified logical name or null if not found.

Parameters:
name - Logical name of the requested forwarding

getActionMappings

static org.apache.struts.action.ActionMappings getActionMappings(javax.servlet.ServletContext application)
Returns the org.apache.struts.action.ActionMappings collection for this application or null if not found.

Parameters:
application - the servlet context

getActionMapping

static org.apache.struts.action.ActionMapping getActionMapping(java.lang.String path,
                                                               javax.servlet.ServletContext application)
Returns the mapping associated with the specified request path, or null if not found.

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

getMessageResources

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

Parameters:
application - the servlet context

getServletMapping

static java.lang.String getServletMapping(javax.servlet.ServletContext application)
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:
application - the servlet context

getLocale

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

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

getActionErrors

static org.apache.struts.action.ActionErrors getActionErrors(javax.servlet.http.HttpServletRequest request)
Returns the org.apache.struts.action.ActionErrors object for this request or null if none exists.

Parameters:
request - the servlet request

getException

static java.lang.Throwable getException(javax.servlet.http.HttpServletRequest request)
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

static org.apache.struts.upload.MultipartRequestWrapper getMultipartRequestWrapper(javax.servlet.http.HttpServletRequest request)
Returns the multipart object for this request or null if none exists.

Parameters:
request - the servlet request

getMapping

static org.apache.struts.action.ActionMapping getMapping(javax.servlet.http.HttpServletRequest request)
Returns the org.apache.struts.ActionMapping instance for this request or null if none exists.

Parameters:
request - the servlet request

getActionForm

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

static java.lang.String getCancelName()
Returns the query parameter name under which a cancel button press must be reported if form validation is to be skipped.


getGlobalErrorName

static java.lang.String getGlobalErrorName()
Returns the default "GLOBAL" category name that can be used with messages that are not associated with a particular property.


getTokenName

static java.lang.String getTokenName()
Returns the query parameter name under which a transaction token must be reported.


getActionMappingName

static java.lang.String getActionMappingName(java.lang.String action)
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

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

errorMarkup

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.


Copyright (c) 2003 Apache Software Foundation