Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
org.apache.struts.util.RequestUtils
public class RequestUtils
extends java.lang.Object
Field Summary | |
protected static Log |
|
Method Summary | |
static URL |
|
static String |
|
static Class |
|
static Object |
|
private static boolean |
|
static Map |
|
static String |
|
static String |
|
static String |
|
static ActionForm |
|
static ActionForm |
|
static StringBuffer |
|
static StringBuffer |
|
static String |
|
static String |
|
static String |
|
static ActionErrors |
|
static String |
|
static String |
|
static ActionMessages |
|
private static Map |
|
static ModuleConfig |
|
static ModuleConfig |
|
static String |
|
static String |
|
static String[] |
|
private static MultipartRequestHandler |
|
static ModuleConfig |
|
static int |
|
static Locale |
|
static boolean |
|
static Object |
|
static Object |
|
private static ActionForm |
|
static String |
|
static String |
|
static String |
|
static void |
|
static void |
|
static boolean |
|
static String |
|
static StringBuffer |
|
static StringBuffer |
|
static URL |
|
static Locale |
|
static void |
|
static void |
|
static void |
|
static URL |
|
public static URL absoluteURL(HttpServletRequest request, String path) throws MalformedURLException
Create and return an absolute URL for the specified context-relative path, based on the server and context information in the specified request.
- Parameters:
request
- The servlet request we are processingpath
- The context-relative path (must start with '/')
- Returns:
- absolute URL based on context-relative path
public static String actionURL(HttpServletRequest request, ActionConfig action, String pattern)
Return the context-relative URL that corresponds to the specifiedActionConfig
, relative to the module associated with the current modules'sModuleConfig
.
- Parameters:
request
- The servlet request we are processingaction
- ActionConfig to be evaluatedpattern
- URL pattern used to map the controller servlet
- Returns:
- context-relative URL relative to the module
- Since:
- Struts 1.1
public static Class applicationClass(String className) throws ClassNotFoundException
Return theClass
object for the specified fully qualified class name, from this web application's class loader.
- Parameters:
className
- Fully qualified class name to be loaded
- Returns:
- Class object
public static Object applicationInstance(String className) throws ClassNotFoundException, IllegalAccessException, InstantiationException
Return a new instance of the specified fully qualified class name, after loading the class from this web application's class loader. The specified class MUST have a public zero-arguments constructor.
- Parameters:
className
- Fully qualified class name to use
- Returns:
- new instance of class
private static boolean canReuseActionForm(ActionForm instance, FormBeanConfig config) throws ClassNotFoundException
Determine whetherinstance
ofActionForm
is suitable for re-use as an instance of the form described byconfig
.
- Parameters:
instance
- an instance ofActionForm
which was found, probably in either request or session scope.config
- the configuration for the ActionForm which is needed.
- Returns:
- true if the instance found is "compatible" with the type required in the
FormBeanConfig
; false if not, or ifinstance
is null.
public static Map computeParameters(PageContext pageContext, String paramId, String paramName, String paramProperty, String paramScope, String name, String property, String scope, boolean transaction) throws JspException
Deprecated. This will be removed after Struts 1.2. Use
TagUtils.computeParameters(PageContext,String,String,String,String,String,String,String,boolean)
instead.Compute a set of query parameters that will be dynamically added to a generated URL. The returned Map is keyed by parameter name, and the values are either null (no value specified), a String (single value specified), or a String[] array (multiple values specified). Parameter names correspond to the corresponding attributes of the<html:link>
tag. If no query parameters are identified, returnnull
.
- Parameters:
pageContext
- PageContext we are operating inparamId
- Single-value request parameter name (if any)paramName
- Bean containing single-value parameter valueparamProperty
- Property (of bean named byparamName
containing single-value parameter valueparamScope
- Scope containing bean named byparamName
name
- Bean containing multi-value parameters Map (if any)property
- Property (of bean named byname
containing multi-value parameters Mapscope
- Scope containing bean named byname
transaction
- Should we add our transaction control token?
- Returns:
- Map of query parameters
public static String computeURL(PageContext pageContext, String forward, String href, String page, Map params, String anchor, boolean redirect) throws MalformedURLException
Deprecated. This will be removed after Struts 1.2 Use
computeURL(PageContext,String,String,String,String,Map,String,boolean)
instead.Compute a hyperlink URL based on theforward
,href
orpage
parameter that is not null.
- Parameters:
pageContext
- PageContext for the tag making this callforward
- Logical forward name for which to look up the context-relative URI (if specified)href
- URL to be utilized unmodified (if specified)page
- Module-relative page for which a URL should be created (if specified)params
- Map of parameters to be dynamically included (if any)anchor
- Anchor to be dynamically included (if any)redirect
- Is this URL for aresponse.sendRedirect()
?
- Returns:
- URL with session identifier
public static String computeURL(PageContext pageContext, String forward, String href, String page, String action, Map params, String anchor, boolean redirect) throws MalformedURLException
Deprecated. This will be removed after Struts 1.2. Use
TagUtils.computeURL(PageContext,String,String,String,String,String,Map,String,boolean)
instead.Compute a hyperlink URL based on theforward
,href
,action
orpage
parameter that is not null. The returned URL will have already been passed toresponse.encodeURL()
for adding a session identifier.
- Parameters:
pageContext
- PageContext for the tag making this callforward
- Logical forward name for which to look up the context-relative URI (if specified)href
- URL to be utilized unmodified (if specified)page
- Module-relative page for which a URL should be created (if specified)action
- Logical action name for which to look up the context-relative URI (if specified)params
- Map of parameters to be dynamically included (if any)anchor
- Anchor to be dynamically included (if any)redirect
- Is this URL for aresponse.sendRedirect()
?
- Returns:
- URL with session identifier
public static String computeURL(PageContext pageContext, String forward, String href, String page, String action, Map params, String anchor, boolean redirect, boolean encodeSeparator) throws MalformedURLException
Deprecated. This will be removed after Struts 1.2. Use
TagUtils.computeURL(PageContext,String,String,String,String,String,Map,String,boolean,boolean)
instead.Compute a hyperlink URL based on theforward
,href
,action
orpage
parameter that is not null. The returned URL will have already been passed toresponse.encodeURL()
for adding a session identifier.
- Parameters:
pageContext
- PageContext for the tag making this callforward
- Logical forward name for which to look up the context-relative URI (if specified)href
- URL to be utilized unmodified (if specified)page
- Module-relative page for which a URL should be created (if specified)action
- Logical action name for which to look up the context-relative URI (if specified)params
- Map of parameters to be dynamically included (if any)anchor
- Anchor to be dynamically included (if any)redirect
- Is this URL for aresponse.sendRedirect()
?encodeSeparator
- This is only checked if redirect is set to false (never encoded for a redirect). If true, query string parameter separators are encoded as >amp;, else & is used.
- Returns:
- URL with session identifier
public static ActionForm createActionForm(HttpServletRequest request, ActionMapping mapping, ModuleConfig moduleConfig, ActionServlet servlet)
Create (if necessary) and return anActionForm
instance appropriate for this request. If noActionForm
instance is required, returnnull
.
- Parameters:
request
- The servlet request we are processingmapping
- The action mapping for this requestmoduleConfig
- The configuration for this moduleservlet
- The action servlet
- Returns:
- ActionForm instance associated with this request
public static ActionForm createActionForm(FormBeanConfig config, ActionServlet servlet)
Create and return anActionForm
instance appropriate to the information inconfig
. Does not perform any checks to see if an existing ActionForm exists which could be reused.
- Parameters:
config
- The configuration for the Form bean which is to be created.servlet
- The action servlet
- Returns:
- ActionForm instance associated with this request
public static StringBuffer createServerStringBuffer(String scheme, String server, int port)
ReturnStringBuffer
representing the scheme, server, and port number of the current request.
- Parameters:
scheme
- The scheme name to useserver
- The server name to useport
- The port value to use
- Returns:
- StringBuffer in the form scheme: server: port
- Since:
- Struts 1.2.0
public static StringBuffer createServerUriStringBuffer(String scheme, String server, int port, String uri)
ReturnStringBuffer
representing the scheme, server, and port number of the current request.
- Parameters:
scheme
- The scheme name to useserver
- The server name to useport
- The port value to useuri
- The uri value to use
- Returns:
- StringBuffer in the form scheme: server: port
- Since:
- Struts 1.2.0
public static String encodeURL(String url)
Deprecated. Use
TagUtils.encodeURL(String)
instead. This will be removed after Struts 1.2.Use the newURLEncoder.encode
method from Java 1.4 if available, else use the old deprecated version. This method uses reflection to find the appropriate method; if the reflection operations throw exceptions, this will return the url encoded with the oldURLEncoder.encode
method.
- Returns:
- String - the encoded url.
public static String forwardURL(HttpServletRequest request, ForwardConfig forward)
Return the context-relative URL that corresponds to the specifiedForwardConfig
. The URL is calculated based on the properties of theForwardConfig
instance as follows:
- If the
contextRelative
property is set, it is assumed that thepath
property contains a path that is already context-relative:- If the
path
property value starts with a slash, it is returned unmodified.- If the
path
property value does not start with a slash, a slash is prepended.Acquire the forwardPattern
property from theControllerConfig
for the application module used to process this request. If no pattern was configured, default to a pattern of$M$P
, which is compatible with the hard-coded mapping behavior in Struts 1.0.Process the acquired forwardPattern
, performing the following substitutions:
- $M - Replaced by the module prefix for the application module processing this request.
- $P - Replaced by the
path
property of the specifiedForwardConfig
, prepended with a slash if it does not start with one.- $$ - Replaced by a single dollar sign character.
- $x (where "x" is any charater not listed above) - Silently omit these two characters from the result value. (This has the side effect of causing all other $+letter combinations to be reserved.)
- Parameters:
request
- The servlet request we are processingforward
- ForwardConfig to be evaluated
- Returns:
- context-relative URL
- Since:
- Struts 1.1
public static String forwardURL(HttpServletRequest request, ForwardConfig forward, ModuleConfig moduleConfig)
Return the context-relative URL that corresponds to the specifiedForwardConfig
. The URL is calculated based on the properties of theForwardConfig
instance as follows:
- If the
contextRelative
property is set, it is assumed that thepath
property contains a path that is already context-relative:- If the
path
property value starts with a slash, it is returned unmodified.- If the
path
property value does not start with a slash, a slash is prepended.Acquire the forwardPattern
property from theControllerConfig
for the application module used to process this request. If no pattern was configured, default to a pattern of$M$P
, which is compatible with the hard-coded mapping behavior in Struts 1.0.Process the acquired forwardPattern
, performing the following substitutions:
- $M - Replaced by the module prefix for the application module processing this request.
- $P - Replaced by the
path
property of the specifiedForwardConfig
, prepended with a slash if it does not start with one.- $$ - Replaced by a single dollar sign character.
- $x (where "x" is any charater not listed above) - Silently omit these two characters from the result value. (This has the side effect of causing all other $+letter combinations to be reserved.)
- Parameters:
request
- The servlet request we are processingforward
- ForwardConfig to be evaluatedmoduleConfig
- Base forward on this module config.
- Returns:
- context-relative URL
- Since:
- Struts 1.2
public static ActionErrors getActionErrors(PageContext pageContext, String paramName) throws JspException
Deprecated. Use
TagUtils.getActionErrors(PageContext,String)
instead. This will be removed after Struts 1.2.Retrieves the value from request scope and if it isn't already anErrorMessages
some classes are converted to one.
- Parameters:
pageContext
- The PageContext for the current pageparamName
- Key for parameter value
- Returns:
- ActionErrors from request scope
public static String getActionMappingName(String action)
Deprecated. This will be removed after Struts 1.2. Use
TagUtils.getActionMappingName(String)
instead.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.
public static String getActionMappingURL(String action, PageContext pageContext)
Deprecated. This will be removed after Struts 1.2. Use
TagUtils.getActionMappingURL(String,PageContext)
instead.Return the form action converted into a server-relative URL.
public static ActionMessages getActionMessages(PageContext pageContext, String paramName) throws JspException
Deprecated. Use
TagUtils.getActionMessages(PageContext,String)
instead. This will be removed after Struts 1.2.Retrieves the value from request scope and if it isn't already anActionMessages
some classes are converted to one.
- Parameters:
pageContext
- The PageContext for the current pageparamName
- Key for parameter value
- Returns:
- ActionErros in page context.
private static Map getAllParametersForMultipartRequest(HttpServletRequest request, MultipartRequestHandler multipartHandler)
Create aMap
containing all of the parameters supplied for a multipart request, keyed by parameter name. In addition to text and file elements from the multipart body, query string parameters are included as well.
- Parameters:
request
- The (wrapped) HTTP request whose parameters are to be added to the map.multipartHandler
- The multipart handler used to parse the request.
- Returns:
- the map containing all parameters for this multipart request.
public static ModuleConfig getModuleConfig(HttpServletRequest request, ServletContext context)
Deprecated. Use
ModuleUtils.getModuleConfig(HttpServletRequest,ServletContext)
instead. This will be removed after Struts 1.2.Return the ModuleConfig object is it exists, null otherwise.
- Parameters:
request
- The servlet request we are processingcontext
- The ServletContext for this web application
- Returns:
- the ModuleConfig object
- Since:
- Struts 1.1
public static ModuleConfig getModuleConfig(PageContext pageContext)
Deprecated. Use
TagUtils.getModuleConfig(PageContext)
instead. This will be removed after Struts 1.2.Return theModuleConfig
object if it exists, null if otherwise.
- Parameters:
pageContext
- The page context.
- Returns:
- the ModuleConfig object
- Since:
- Struts 1.1
public static String getModuleName(HttpServletRequest request, ServletContext context)
Deprecated. Use Use
ModuleUtils.getModuleName(HttpServletRequest,ServletContext)
instead. This will be removed after Struts 1.2.Get the module name to which the specified request belong.
- Parameters:
request
- The servlet request we are processingcontext
- The ServletContext for this web application
- Returns:
- The module prefix or ""
public static String getModuleName(String matchPath, ServletContext context)
Deprecated. Use
ModuleUtils.getModuleName(String,ServletContext)
instead. This will be removed after Struts 1.2.Get the module name to which the specified uri belong.
- Parameters:
matchPath
- The uri from which we want the module name.context
- The ServletContext for this web application
- Returns:
- The module prefix or ""
public static String[] getModulePrefixes(ServletContext context)
Deprecated. Use
ModuleUtils.getModulePrefixes(ServletContext)
instead. This will be removed after Struts 1.2.Return the list of module prefixes that are defined for this web application. NOTE - the "" prefix for the default module is not included in this list.
- Parameters:
context
- The ServletContext for this web application.
- Returns:
- An array of module prefixes.
- Since:
- Struts 1.1
private static MultipartRequestHandler getMultipartHandler(HttpServletRequest request) throws ServletException
Try to locate a multipart request handler for this request. First, look for a mapping-specific handler stored for us under an attribute. If one is not present, use the global multipart handler, if there is one.
- Parameters:
request
- The HTTP request for which the multipart handler should be found.
- Returns:
- the multipart handler to use, or null if none is found.
public static ModuleConfig getRequestModuleConfig(HttpServletRequest request)
Deprecated. Use
ModuleUtils.getModuleConfig(HttpServletRequest)
instead. This will be removed after Struts 1.2.Return the currentModuleConfig
object stored in request, if it exists, null otherwise. This method can be used by aPlugIn
to retrieve the current module config object. If no moduleConfig is found, this means that the request hasn't hit the server through the Struts servlet. The appropriate module config can be set and found with.
selectModule(HttpServletRequest,ServletContext)
- Parameters:
request
- The servlet request we are processing
- Returns:
- the ModuleConfig object from request, or null if none is set in the request.
- Since:
- Struts 1.1
public static int getScope(String scopeName) throws JspException
Deprecated. This will be removed after Struts 1.2. Use
TagUtils.getScope(String)
instead.Converts the scope name into its corresponding PageContext constant value.
- Parameters:
scopeName
- Can be "page", "request", "session", or "application" in any case
- Returns:
- The constant representing the scope (ie. PageContext.REQUEST_SCOPE).
- Since:
- Struts 1.1
public static Locale getUserLocale(HttpServletRequest request, String locale)
Look up and return current user locale, based on the specified parameters.
- Parameters:
request
- The request used to lookup the Localelocale
- Name of the session attribute for our user's Locale. If this isnull
, the default locale key is used for the lookup.
- Returns:
- current user locale
- Since:
- Struts 1.2
public static boolean isXhtml(PageContext pageContext)
Deprecated. Use
TagUtils.isXhtml(PageContext)
instead. This will be removed after Struts 1.2.Returns true if the custom tags are in XHTML mode.
- Since:
- Struts 1.1
public static Object lookup(PageContext pageContext, String name, String scopeName) throws JspException
Deprecated. This will be removed after Struts 1.2. Use
TagUtils.lookup(PageContext,String,String)
instead.Locate and return the specified bean, from an optionally specified scope, in the specified page context. If no such bean is found, returnnull
instead. If an exception is thrown, it will have already been saved via a call tosaveException
.
- Parameters:
pageContext
- Page context to be searchedname
- Name of the bean to be retrievedscopeName
- Scope to be searched (page, request, session, application) ornull
to usefindAttribute()
instead
- Returns:
- JavaBean in the specified page context
public static Object lookup(PageContext pageContext, String name, String property, String scope) throws JspException
Deprecated. This will be removed after Struts 1.2. Use
TagUtils.lookup(PageContext,String,String,String)
instead.Locate and return the specified property of the specified bean, from an optionally specified scope, in the specified page context. If an exception is thrown, it will have already been saved via a call tosaveException
.
- Parameters:
pageContext
- Page context to be searchedname
- Name of the bean to be retrievedproperty
- Name of the property to be retrieved, ornull
to retrieve the bean itselfscope
- Scope to be searched (page, request, session, application) ornull
to usefindAttribute()
instead
- Returns:
- property of specified JavaBean
private static ActionForm lookupActionForm(HttpServletRequest request, String attribute, String scope)
public static String message(PageContext pageContext, String bundle, String locale, String key) throws JspException
Deprecated. Use
TagUtils.message(PageContext,String,String,String)
instead. This will be removed after Struts 1.2.Look up and return a message string, based on the specified parameters.
- Parameters:
pageContext
- The PageContext associated with this requestbundle
- Name of the servlet context attribute for our message resources bundlelocale
- Name of the session attribute for our user's Localekey
- Message key to be looked up and returned
- Returns:
- message string
public static String message(PageContext pageContext, String bundle, String locale, String key, args[] ) throws JspException
Deprecated. Use
org.apache.struts.taglib.TagUtils.message(PageContext,String,String,String,Object[])
instead. This will be removed after Struts 1.2.Look up and return a message string, based on the specified parameters.
- Parameters:
pageContext
- The PageContext associated with this requestbundle
- Name of the servlet context attribute for our message resources bundlelocale
- Name of the session attribute for our user's Localekey
- Message key to be looked up and returned
- Returns:
- message string
public static String pageURL(HttpServletRequest request, String page)
Deprecated. Use
org.apache.struts.taglib.TagUtils.pageURL(HttpServletRequest request, String page, ModuleConfig moduleConfig)
instead. This will be removed after Struts 1.2.Return the context-relative URL that corresponds to the specifiedpage
attribute value, calculated based on thepagePattern
property of the current module'sModuleConfig
.
- Parameters:
request
- The servlet request we are processingpage
- The module-relative URL to be substituted in to thepagePattern
pattern for the current module (MUST start with a slash)
- Returns:
- context-relative URL
- Since:
- Struts 1.1
public static void populate(Object bean, HttpServletRequest request) throws ServletException
Populate the properties of the specified JavaBean from the specified HTTP request, based on matching each parameter name against the corresponding JavaBeans "property setter" methods in the bean's class. Suitable conversion is done for argument types as described underconvert()
.
- Parameters:
bean
- The JavaBean whose properties are to be setrequest
- The HTTP request whose parameters are to be used to populate bean properties
public static void populate(Object bean, String prefix, String suffix, HttpServletRequest request) throws ServletException
Populate the properties of the specified JavaBean from the specified HTTP request, based on matching each parameter name (plus an optional prefix and/or suffix) against the corresponding JavaBeans "property setter" methods in the bean's class. Suitable conversion is done for argument types as described undersetProperties
. If you specify a non-nullprefix
and a non-nullsuffix
, the parameter name must match both conditions for its value(s) to be used in populating bean properties. If the request's content type is "multipart/form-data" and the method is "POST", theHttpServletRequest
object will be wrapped in aMultipartRequestWrapper
- Parameters:
bean
- The JavaBean whose properties are to be setprefix
- The prefix (if any) to be prepend to bean property names when looking for matching parameterssuffix
- The suffix (if any) to be appended to bean property names when looking for matching parametersrequest
- The HTTP request whose parameters are to be used to populate bean properties
public static boolean present(PageContext pageContext, String bundle, String locale, String key) throws JspException
Deprecated. Use
TagUtils.present(PageContext,String,String,String)
instead. This will be removed after Struts 1.2.Return true if a message string for the specified message key is present for the specified Locale.
- Parameters:
pageContext
- The PageContext associated with this requestbundle
- Name of the servlet context attribute for our message resources bundlelocale
- Name of the session attribute for our user's Localekey
- Message key to be looked up and returned
- Returns:
- true if a message string for message key exists
public static String printableURL(URL url)
Compute the printable representation of a URL, leaving off the scheme/host/port part if no host is specified. This will typically be the case for URLs that were originally created from relative or context-relative URIs.
- Parameters:
url
- URL to render in a printable representation
- Returns:
- printable representation of a URL
public static StringBuffer requestToServerStringBuffer(HttpServletRequest request)
ReturnStringBuffer
representing the scheme, server, and port number of the current request. Server-relative URLs can be created by simply appending the server-relative path (starting with '/') to this.
- Parameters:
request
- The servlet request we are processing
- Returns:
- URL representing the scheme, server, and port number of the current request
- Since:
- Struts 1.2.0
public static StringBuffer requestToServerUriStringBuffer(HttpServletRequest request)
Return the string representing the scheme, server, and port number of the current request. Server-relative URLs can be created by simply appending the server-relative path (starting with '/') to this.
- Parameters:
request
- The servlet request we are processing
- Returns:
- URL representing the scheme, server, and port number of the current request
- Since:
- Struts 1.2.0
public static URL requestURL(HttpServletRequest request) throws MalformedURLException
Return the URL representing the current request. This is equivalent toHttpServletRequest.getRequestURL
in Servlet 2.3.
- Parameters:
request
- The servlet request we are processing
- Returns:
- URL representing the current request
public static Locale retrieveUserLocale(PageContext pageContext, String locale)
Deprecated. This will be removed after Struts 1.2. Use
TagUtils.getUserLocale(PageContext,String)
instead.Look up and return current user locale, based on the specified parameters.
- Parameters:
pageContext
- The PageContext associated with this requestlocale
- Name of the session attribute for our user's Locale. If this isnull
, the default locale key is used for the lookup.
- Returns:
- current user locale
public static void saveException(PageContext pageContext, Throwable exception)
Deprecated. Use
TagUtils.saveException(PageContext,Throwable)
instead. This will be removed after Struts 1.2.Save the specified exception as a request attribute for later use.
- Parameters:
pageContext
- The PageContext for the current pageexception
- The exception to be saved
public static void selectModule(HttpServletRequest request, ServletContext context)
Deprecated. Use
ModuleUtils.selectModule(HttpServletRequest,ServletContext)
instead. This will be removed after Struts 1.2.Select the module to which the specified request belongs, and add corresponding request attributes to this request.
- Parameters:
request
- The servlet request we are processingcontext
- The ServletContext for this web application
public static void selectModule(String prefix, HttpServletRequest request, ServletContext context)
Deprecated. Use
ModuleUtils.selectModule(String,HttpServletRequest,ServletContext)
instead. This will be removed after Struts 1.2.Select the module to which the specified request belongs, and add corresponding request attributes to this request.
- Parameters:
prefix
- The module prefix of the desired modulerequest
- The servlet request we are processingcontext
- The ServletContext for this web application
- Since:
- Struts 1.1
public static URL serverURL(HttpServletRequest request) throws MalformedURLException
Return the URL representing the scheme, server, and port number of the current request. Server-relative URLs can be created by simply appending the server-relative path (starting with '/') to this.
- Parameters:
request
- The servlet request we are processing
- Returns:
- URL representing the scheme, server, and port number of the current request