类 StrutsUtils
java.lang.Object
org.apache.velocity.tools.struts.StrutsUtils
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.
- 版本:
- $Id: StrutsUtils.java 670093 2008-06-20 23:10:11Z nbubna $
- 作者:
- Marino A. Jonsson, Nathan Bubna, Gabe Sidler based on code by Ted Husted
-
字段概要
字段 -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明static String
errorMarkup
(String property, HttpServletRequest request, HttpSession session, ServletContext application) Returns a formatted error message.static String
errorMarkup
(String property, String bundle, HttpServletRequest request, HttpSession session, ServletContext application) Returns a formatted error message.static ActionForm
getActionForm
(HttpServletRequest request, HttpSession session) Returns theActionForm
bean associated with this request ofnull
if none exists.static String
getActionFormName
(HttpServletRequest request, HttpSession session) Returns the ActionForm name associated with this request ofnull
if none exists.static String
getActionMappingName
(String action) Return the form action converted into an action mapping path.static String
getActionMappingURL
(ServletContext application, HttpServletRequest request, String action) Returns the form action converted into a server-relative URI reference.static ActionMessages
getErrors
(HttpServletRequest request) Returns the Struts errors for this request ornull
if none exist.static String
getForwardURL
(HttpServletRequest request, ServletContext app, String forward) Returns the action forward name converted into a server-relative URI reference.static Locale
getLocale
(HttpServletRequest request, HttpSession session) Returns thejava.util.Locale
for the user.static MessageResources
getMessageResources
(HttpServletRequest request, ServletContext app) Returns the message resources for this application ornull
if not found.static MessageResources
getMessageResources
(HttpServletRequest request, ServletContext app, String bundle) Returns the message resources with the specified bundle name for this application ornull
if not found.static ActionMessages
getMessages
(HttpServletRequest request) Returns the Struts messages for this request ornull
if none exist.static String
getToken
(HttpSession session) Returns the transaction token stored in this session ornull
if not used.static ModuleConfig
selectModule
(String urlPath, ServletContext app) Select the module to which the specified request belongs, and add return the corresponding ModuleConfig.
-
字段详细资料
-
INSTANCE
-
-
构造器详细资料
-
StrutsUtils
private StrutsUtils()
-
-
方法详细资料
-
getInstance
-
getMessageResources
public static MessageResources getMessageResources(HttpServletRequest request, ServletContext app) Returns the message resources for this application ornull
if not found.- 参数:
app
- the servlet context- 从以下版本开始:
- VelocityTools 1.1
-
getMessageResources
public static MessageResources getMessageResources(HttpServletRequest request, ServletContext app, String bundle) Returns the message resources with the specified bundle name for this application ornull
if not found.- 参数:
app
- the servlet contextbundle
- The bundle name to look for. If this isnull
, the default bundle name is used.- 从以下版本开始:
- VelocityTools 1.1
-
selectModule
Select the module to which the specified request belongs, and add return the corresponding ModuleConfig.- 参数:
urlPath
- The requested URLapp
- The ServletContext for this web application- 返回:
- The ModuleConfig for the given URL path
- 从以下版本开始:
- VelocityTools 1.1
-
getLocale
Returns thejava.util.Locale
for the user. If a locale object is not found in the user's session, the system default locale is returned.- 参数:
request
- the servlet requestsession
- the HTTP session
-
getToken
Returns the transaction token stored in this session ornull
if not used.- 参数:
session
- the HTTP session
-
getErrors
public static ActionMessages getErrors(HttpServletRequest request) Returns the Struts errors for this request ornull
if none exist. Since VelocityTools 1.2, this will also check the session (if there is one) for errors if there are no errors in the request.- 参数:
request
- the servlet request- 从以下版本开始:
- VelocityTools 1.1
-
getMessages
public static ActionMessages getMessages(HttpServletRequest request) Returns the Struts messages for this request ornull
if none exist. Since VelocityTools 1.2, this will also check the session (if there is one) for messages if there are no messages in the request.- 参数:
request
- the servlet request- 从以下版本开始:
- VelocityTools 1.1
-
getActionForm
public static ActionForm getActionForm(HttpServletRequest request, HttpSession session) Returns theActionForm
bean associated with this request ofnull
if none exists.- 参数:
request
- the servlet requestsession
- the HTTP session
-
getActionFormName
Returns the ActionForm name associated with this request ofnull
if none exists.- 参数:
request
- the servlet requestsession
- the HTTP session
-
getActionMappingName
Return the form action converted into an action mapping path. The value of theaction
property is manipulated as follows in computing the name of the requested mapping:- Any filename extension is removed (on the theory that extension mapping is being used to select the controller servlet).
- If the resulting value does not start with a slash, then a slash is prepended.
-
getActionMappingURL
public static String getActionMappingURL(ServletContext application, HttpServletRequest request, String action) Returns the form action converted into a server-relative URI reference.- 参数:
application
- the servlet contextrequest
- the servlet requestaction
- the name of an action as per struts-config.xml
-
getForwardURL
Returns the action forward name converted into a server-relative URI reference.- 参数:
app
- the servlet contextrequest
- the servlet requestforward
- the name of a forward as per struts-config.xml
-
errorMarkup
public static String errorMarkup(String property, HttpServletRequest request, HttpSession session, 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.- 参数:
property
- the category of errors to markup and returnrequest
- the servlet requestsession
- the HTTP sessionapplication
- the servlet context- 返回:
- The formatted error message. If no error messages are queued, an empty string is returned.
-
errorMarkup
public static String errorMarkup(String property, String bundle, HttpServletRequest request, HttpSession session, 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.- 参数:
property
- the category of errors to markup and returnbundle
- the message resource bundle to userequest
- the servlet requestsession
- the HTTP sessionapplication
- the servlet context- 返回:
- The formatted error message. If no error messages are queued, an empty string is returned.
- 从以下版本开始:
- VelocityTools 1.1
-