Package org.apache.velocity.tools.struts
Class StrutsUtils
- java.lang.Object
-
- org.apache.velocity.tools.struts.StrutsUtils
-
public class StrutsUtils extends 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$
- Author:
- Marino A. Jonsson, Nathan Bubna, Gabe Sidler based on code by Ted Husted
-
-
Field Summary
Fields Modifier and Type Field Description static StrutsUtilsINSTANCE
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static StringerrorMarkup(String property, String bundle, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpSession session, javax.servlet.ServletContext application)Returns a formatted error message.static StringerrorMarkup(String property, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpSession session, javax.servlet.ServletContext application)Returns a formatted error message.static org.apache.struts.action.ActionFormgetActionForm(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpSession session)Returns theActionFormbean associated with this request ofnullif none exists.static StringgetActionFormName(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpSession session)Returns the ActionForm name associated with this request ofnullif none exists.static StringgetActionMappingName(String action)Return the form action converted into an action mapping path.static StringgetActionMappingURL(javax.servlet.ServletContext application, javax.servlet.http.HttpServletRequest request, String action)Returns the form action converted into a server-relative URI reference.static org.apache.struts.action.ActionMessagesgetErrors(javax.servlet.http.HttpServletRequest request)Returns the Struts errors for this request ornullif none exist.static StringgetForwardURL(javax.servlet.http.HttpServletRequest request, javax.servlet.ServletContext app, String forward)Returns the action forward name converted into a server-relative URI reference.StrutsUtilsgetInstance()static LocalegetLocale(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpSession session)Returns thejava.util.Localefor the user.static org.apache.struts.util.MessageResourcesgetMessageResources(javax.servlet.http.HttpServletRequest request, javax.servlet.ServletContext app)Returns the message resources for this application ornullif not found.static org.apache.struts.util.MessageResourcesgetMessageResources(javax.servlet.http.HttpServletRequest request, javax.servlet.ServletContext app, String bundle)Returns the message resources with the specified bundle name for this application ornullif not found.static org.apache.struts.action.ActionMessagesgetMessages(javax.servlet.http.HttpServletRequest request)Returns the Struts messages for this request ornullif none exist.static StringgetToken(javax.servlet.http.HttpSession session)Returns the transaction token stored in this session ornullif not used.static org.apache.struts.config.ModuleConfigselectModule(String urlPath, javax.servlet.ServletContext app)Select the module to which the specified request belongs, and add return the corresponding ModuleConfig.
-
-
-
Field Detail
-
INSTANCE
public static final StrutsUtils INSTANCE
-
-
Method Detail
-
getInstance
public StrutsUtils getInstance()
-
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 ornullif 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, String bundle)Returns the message resources with the specified bundle name for this application ornullif not found.- Parameters:
app- the servlet contextbundle- The bundle name to look for. If this isnull, the default bundle name is used.- Since:
- VelocityTools 1.1
-
selectModule
public static org.apache.struts.config.ModuleConfig selectModule(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 URLapp- The ServletContext for this web application- Returns:
- The ModuleConfig for the given URL path
- Since:
- VelocityTools 1.1
-
getLocale
public static Locale getLocale(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpSession session)
Returns thejava.util.Localefor the user. If a locale object is not found in the user's session, the system default locale is returned.- Parameters:
request- the servlet requestsession- the HTTP session
-
getToken
public static String getToken(javax.servlet.http.HttpSession session)
Returns the transaction token stored in this session ornullif 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 ornullif 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.- 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 ornullif 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.- Parameters:
request- the servlet request- Since:
- VelocityTools 1.1
-
getActionForm
public static org.apache.struts.action.ActionForm getActionForm(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpSession session)Returns theActionFormbean associated with this request ofnullif none exists.- Parameters:
request- the servlet requestsession- the HTTP session
-
getActionFormName
public static String getActionFormName(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpSession session)
Returns the ActionForm name associated with this request ofnullif none exists.- Parameters:
request- the servlet requestsession- the HTTP session
-
getActionMappingName
public static String getActionMappingName(String action)
Return the form action converted into an action mapping path. The value of theactionproperty 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(javax.servlet.ServletContext application, javax.servlet.http.HttpServletRequest request, String action)
Returns the form action converted into a server-relative URI reference.- Parameters:
application- the servlet contextrequest- the servlet requestaction- the name of an action as per struts-config.xml
-
getForwardURL
public static String getForwardURL(javax.servlet.http.HttpServletRequest request, javax.servlet.ServletContext app, String forward)
Returns the action forward name converted into a server-relative URI reference.- Parameters:
app- the servlet contextrequest- the servlet requestforward- the name of a forward as per struts-config.xml
-
errorMarkup
public static String errorMarkup(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 returnrequest- the servlet requestsession- the HTTP sessionapplication- the servlet context- Returns:
- The formatted error message. If no error messages are queued, an empty string is returned.
-
errorMarkup
public static String errorMarkup(String property, 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 returnbundle- the message resource bundle to userequest- the servlet requestsession- the HTTP sessionapplication- the servlet context- Returns:
- The formatted error message. If no error messages are queued, an empty string is returned.
- Since:
- VelocityTools 1.1
-
-