Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.struts.util
Class RequestUtils

    java.lang.Object
      |
      +--org.apache.struts.util.RequestUtils

public class RequestUtils
extends java.lang.Object

General purpose utility methods related to processing a servlet request in the Struts controller framework.

Version:
  $Revision: 1.1 $ $Date: 2001/09/17 20:13:29 $
Author:
  Craig R. McClanahan

Field Summary
`private static java.util.Locale` | `defaultLocale` The default Locale for our server.
`private static MessageResources` | `messages` The message resources for this package.

Constructor Summary
`RequestUtils()`

Method Summary
`static java.net.URL` | `absoluteURL(javax.servlet.http.HttpServletRequest request, java.lang.String path)` Create and return an absolute URL for the specified context-relative path, based on the server and context information in the specified request.
`static java.util.Map` | `computeParameters(javax.servlet.jsp.PageContext pageContext, java.lang.String paramId, java.lang.String paramName, java.lang.String paramProperty, java.lang.String paramScope, java.lang.String name, java.lang.String property, java.lang.String scope, boolean transaction)` Compute a set of query parameters that will be dynamically added to a generated URL.
`static java.lang.String` | `computeURL(javax.servlet.jsp.PageContext pageContext, java.lang.String forward, java.lang.String href, java.lang.String page, java.util.Map params, java.lang.String anchor, boolean redirect)` Compute a hyperlink URL based on the `forward`, `href`, or `page` parameter that is not null.
`static java.lang.Object` | `lookup(javax.servlet.jsp.PageContext pageContext, java.lang.String name, java.lang.String scope)` Locate and return the specified bean, from an optionally specified scope, in the specified page context.
`static java.lang.Object` | `lookup(javax.servlet.jsp.PageContext pageContext, java.lang.String name, java.lang.String property, java.lang.String scope)` Locate and return the specified property of the specified bean, from an optionally specified scope, in the specified page context.
`static java.lang.String` | `message(javax.servlet.jsp.PageContext pageContext, java.lang.String bundle, java.lang.String locale, java.lang.String key)` Look up and return a message string, based on the specified parameters.
`static java.lang.String` | `message(javax.servlet.jsp.PageContext pageContext, java.lang.String bundle, java.lang.String locale, java.lang.String key, java.lang.Object[] args)` Look up and return a message string, based on the specified parameters.
`static void` | `populate(java.lang.Object bean, javax.servlet.http.HttpServletRequest request)` 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.
`static void` | `populate(java.lang.Object bean, java.lang.String prefix, java.lang.String suffix, javax.servlet.http.HttpServletRequest request)` 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.
`static boolean` | `present(javax.servlet.jsp.PageContext pageContext, java.lang.String bundle, java.lang.String locale, java.lang.String key)` Return true if a message string for the specified message key is present for the specified Locale.
`static java.lang.String` | `printableURL(java.net.URL url)` Compute the printable representation of a URL, leaving off the scheme/host/port part if no host is specified.
`static java.net.URL` | `requestURL(javax.servlet.http.HttpServletRequest request)` Return the URL representing the current request.
`static void` | `saveException(javax.servlet.jsp.PageContext pageContext, java.lang.Throwable exception)` Save the specified exception as a request attribute for later use.
`static java.net.URL` | `serverURL(javax.servlet.http.HttpServletRequest request)` Return the URL representing the scheme, server, and port number of the current request.

Methods inherited from class java.lang.Object
`, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait`

Field Detail

### defaultLocale

    private static final java.util.Locale defaultLocale

  The default Locale for our server.

### messages

    private static MessageResources messages

  The message resources for this package.

Constructor Detail

### RequestUtils

    public RequestUtils()

Method Detail

### absoluteURL

    public static java.net.URL absoluteURL(javax.servlet.http.HttpServletRequest request,
                                           java.lang.String path)
                                    throws java.net.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 processing
    `path` - The context-relative path (must start with '/')
  Throws:
    `java.net.MalformedURLException` - if we cannot create an absolute URL

### computeParameters

    public static java.util.Map computeParameters(javax.servlet.jsp.PageContext pageContext,
                                                  java.lang.String paramId,
                                                  java.lang.String paramName,
                                                  java.lang.String paramProperty,
                                                  java.lang.String paramScope,
                                                  java.lang.String name,
                                                  java.lang.String property,
                                                  java.lang.String scope,
                                                  boolean transaction)
                                           throws javax.servlet.jsp.JspException

  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, return `null`.
  Parameters:
    `pageContext` - PageContext we are operating in
    `paramId` - Single-value request parameter name (if any)
    `paramName` - Bean containing single-value parameter value
    `paramProperty` - Property (of bean named by `paramName` containing single-value parameter value
    `paramScope` - Scope containing bean named by `paramScope`
    `name` - Bean containing multi-value parameters Map (if any)
    `property` - Property (of bean named by `name` containing multi-value parameters Map
    `scope` - Scope containing bean named by `name`
    `transaction` - Should we add our transaction control token?
  Throws:
    `javax.servlet.jsp.JspException` - if we cannot look up the required beans
    `javax.servlet.jsp.JspException` - if a class cast exception occurs on a looked-up bean or property

### computeURL

    public static java.lang.String computeURL(javax.servlet.jsp.PageContext pageContext,
                                              java.lang.String forward,
                                              java.lang.String href,
                                              java.lang.String page,
                                              java.util.Map params,
                                              java.lang.String anchor,
                                              boolean redirect)
                                       throws java.net.MalformedURLException

  Compute a hyperlink URL based on the `forward`, `href`, or `page` parameter that is not null. The returned URL will have already been passed to `response.encodeURL()` for adding a session identifier.
  Parameters:
    `pageContext` - PageContext for the tag making this call
    `forward` - Logical forward name for which to look up the context-relative URI (if specified)
    `href` - URL to be utilized unmodified (if specified)
    `page` - Context-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 a `response.sendRedirect()`?
  Throws:
    `java.net.MalformedURLException` - if a URL cannot be created for the specified parameters

### lookup

    public static java.lang.Object lookup(javax.servlet.jsp.PageContext pageContext,
                                          java.lang.String name,
                                          java.lang.String scope)
                                   throws javax.servlet.jsp.JspException

  Locate and return the specified bean, from an optionally specified scope, in the specified page context. If no such bean is found, return `null` instead. If an exception is thrown, it will have already been saved via a call to `saveException()`.
  Parameters:
    `pageContext` - Page context to be searched
    `name` - Name of the bean to be retrieved
    `scope` - Scope to be searched (page, request, session, application) or `null` to use `findAttribute()` instead
  Throws:
    `javax.servlet.jsp.JspException` - if an invalid scope name is requested

### lookup

    public static java.lang.Object lookup(javax.servlet.jsp.PageContext pageContext,
                                          java.lang.String name,
                                          java.lang.String property,
                                          java.lang.String scope)
                                   throws javax.servlet.jsp.JspException

  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 to `saveException()`.
  Parameters:
    `pageContext` - Page context to be searched
    `name` - Name of the bean to be retrieved
    `property` - Name of the property to be retrieved, or `null` to retrieve the bean itself
    `scope` - Scope to be searched (page, request, session, application) or `null` to use `findAttribute()` instead
  Throws:
    `javax.servlet.jsp.JspException` - if an invalid scope name is requested
    `javax.servlet.jsp.JspException` - if the specified bean is not found
    `javax.servlet.jsp.JspException` - if accessing this property causes an IllegalAccessException, IllegalArgumentException, InvocationTargetException, or NoSuchMethodException

### message

    public static java.lang.String message(javax.servlet.jsp.PageContext pageContext,
                                           java.lang.String bundle,
                                           java.lang.String locale,
                                           java.lang.String key)
                                    throws javax.servlet.jsp.JspException

  Look up and return a message string, based on the specified parameters.
  Parameters:
    `pageContext` - The PageContext associated with this request
    `bundle` - Name of the servlet context attribute for our message resources bundle
    `locale` - Name of the session attribute for our user's Locale
    `key` - Message key to be looked up and returned
  Throws:
    `javax.servlet.jsp.JspException` - if a lookup error occurs (will have been saved in the request already)

### message

    public static java.lang.String message(javax.servlet.jsp.PageContext pageContext,
                                           java.lang.String bundle,
                                           java.lang.String locale,
                                           java.lang.String key,
                                           java.lang.Object[] args)
                                    throws javax.servlet.jsp.JspException

  Look up and return a message string, based on the specified parameters.
  Parameters:
    `pageContext` - The PageContext associated with this request
    `bundle` - Name of the servlet context attribute for our message resources bundle
    `locale` - Name of the session attribute for our user's Locale
    `key` - Message key to be looked up and returned
    `args` - Replacement parameters for this message
  Throws:
    `javax.servlet.jsp.JspException` - if a lookup error occurs (will have been saved in the request already)

### populate

    public static void populate(java.lang.Object bean,
                                javax.servlet.http.HttpServletRequest request)
                         throws javax.servlet.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 under `convert()`.
  Parameters:
    `bean` - The JavaBean whose properties are to be set
    `request` - The HTTP request whose parameters are to be used to populate bean properties
  Throws:
    `javax.servlet.ServletException` - if an exception is thrown while setting property values

### populate

    public static void populate(java.lang.Object bean,
                                java.lang.String prefix,
                                java.lang.String suffix,
                                javax.servlet.http.HttpServletRequest request)
                         throws javax.servlet.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 under `setProperties()`.

  If you specify a non-null `prefix` and a non-null `suffix`, 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", the HttpServletRequest object will be wrapped in a MultipartRequestWrapper object.

  Parameters:
    `bean` - The JavaBean whose properties are to be set
    `prefix` - The prefix (if any) to be prepend to bean property names when looking for matching parameters
    `suffix` - The suffix (if any) to be appended to bean property names when looking for matching parameters
    `request` - The HTTP request whose parameters are to be used to populate bean properties
  Throws:
    `javax.servlet.ServletException` - if an exception is thrown while setting property values

### present

    public static boolean present(javax.servlet.jsp.PageContext pageContext,
                                  java.lang.String bundle,
                                  java.lang.String locale,
                                  java.lang.String key)
                           throws javax.servlet.jsp.JspException

  Return true if a message string for the specified message key is present for the specified Locale.
  Parameters:
    `pageContext` - The PageContext associated with this request
    `bundle` - Name of the servlet context attribute for our message resources bundle
    `locale` - Name of the session attribute for our user's Locale
    `key` - Message key to be looked up and returned
  Throws:
    `javax.servlet.jsp.JspException` - if a lookup error occurs (will have been saved in the request already)

### printableURL

    public static java.lang.String printableURL(java.net.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

### requestURL

    public static java.net.URL requestURL(javax.servlet.http.HttpServletRequest request)
                                   throws java.net.MalformedURLException

  Return the URL representing the current request. This is equivalent to `HttpServletRequest.getRequestURL()` in Servlet 2.3.
  Parameters:
    `request` - The servlet request we are processing
  Throws:
    `java.net.MalformedURLException` - if a URL cannot be created

### serverURL

    public static java.net.URL serverURL(javax.servlet.http.HttpServletRequest request)
                                  throws java.net.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
  Throws:
    `java.net.MalformedURLException` - if a URL cannot be created

### saveException

    public static void saveException(javax.servlet.jsp.PageContext pageContext,
                                     java.lang.Throwable exception)

  Save the specified exception as a request attribute for later use.
  Parameters:
    `pageContext` - The PageContext for the current page
    `exception` - The exception to be saved

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2000-2001 - Apache Software Foundation