# com.bea.wlw.netui.pageflow.util
URLRewriterService Class

public class URLRewriterService
extends `Object`

Methods for registering URL rewriters, and for rewriting URLs using registered rewriters.

Hierarchy
  `Object`
  `URLRewriterService`

## Constructor Summary

URLRewriterService()

## Method Summary

`public static `String`` | `getActionMappingName`(`String` action) Return the form action converted into an action mapping path.
`public static final `URLRewriter`` | `getDefaultRewriter`() Get the default URLRewriter.
`public static boolean` | `needsSecure`(`ServletRequest` request, `ServletContext` context, `String` uri, boolean stripContextPath) Tell whether a given URI should be written to be secure.
`public static void` | `registerURLRewriter`(`ServletRequest` request, `URLRewriter` rewriter) Register a URLRewriter in the request.
`public static `String`` | `rewriteName`(`ServletContext` servletContext, `ServletRequest` request, `String` name) Rewrite the given parameter name, using the registered URLRewriter.
`public static `String`` | `rewriteURL`(`ServletContext` servletContext, `ServletRequest` request, `ServletResponse` response, `String` url, `String` type) Rewrite the given URL, using the registered URLRewriter.
`public static `String`` | `rewriteURL`(`ServletContext` servletContext, `ServletRequest` request, `ServletResponse` response, `String` url, `String` type, boolean doEncode) Rewrite the given URL, using the registered URLRewriter.
`public static `URLRewriter`` | `unregisterURLRewriter`(`ServletRequest` request) Unregister the URLRewriter from the request.

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

## Constructor Detail

### URLRewriterService

    public URLRewriterService()

## Method Detail

### getActionMappingName(String) Method

    public static String getActionMappingName(String action)

Return 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:

- 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.

#### Parameters

action
  the action name to be converted.

#### Returns

an action path, suitable for lookup in the Struts configuration file.

### getDefaultRewriter() Method

    public static final URLRewriter getDefaultRewriter()

Get the default URLRewriter.

#### Returns

an instance of `DefaultURLRewriter```.

### needsSecure(ServletRequest, ServletContext, String, boolean) Method

    public static boolean needsSecure(ServletRequest request,
                                      ServletContext context,
                                      String uri,
                                      boolean stripContextPath)

Tell whether a given URI should be written to be secure.

#### Parameters

request
  the current HttpServletRequest.

context
  the current ServletContext.

uri
  the URI to check.

stripContextPath
  if `true`, strip the webapp context path from the URI before processing it.

#### Returns

`true` when:

- the given URI is configured in the deployment descriptor to be secure (according to `PageFlowUtils.isSecureResource(String, ServletContext, HttpServletRequest)```), or
- the given URI is not configured in the deployment descriptor, and the current request is secure (`HttpServletRequest.isSecure()``` returns `true`).

`false` when:

- the given URI is configured explicitly in the deployment descriptor to be unsecure (according to `PageFlowUtils.isSecureResource(String, ServletContext, HttpServletRequest)```), or
- the given URI is not configured in the deployment descriptor, and the current request is unsecure (`HttpServletRequest.isSecure()``` returns `false`).

### registerURLRewriter(ServletRequest, URLRewriter) Method

    public static void registerURLRewriter(ServletRequest request,
                                           URLRewriter rewriter)

Register a URLRewriter in the request. This rewriter will be used if `URLRewriterService.rewriteURL(ServletContext, ServletRequest, ServletResponse, String, String)``` is called.

#### Parameters

request
  the current HttpServletRequest.

rewriter
  the URLRewriter to register.

### rewriteName(ServletContext, ServletRequest, String) Method

    public static String rewriteName(ServletContext servletContext,
                                     ServletRequest request,
                                     String name)

Rewrite the given parameter name, using the registered URLRewriter.

#### Parameters

servletContext
  the current ServletContext.

request
  the current HttpServletRequest.

name
  the parameter name to rewrite.

#### Returns

the rewritten parameter name.

### rewriteURL(ServletContext, ServletRequest, ServletResponse, String, String) Method

    public static String rewriteURL(ServletContext servletContext,
                                    ServletRequest request,
                                    ServletResponse response,
                                    String url,
                                    String type)

Rewrite the given URL, using the registered URLRewriter.

#### Parameters

servletContext
  the current ServletContext.

request
  the current HttpServletRequest.

response
  the current HttpServletResponse.

url
  the URL to rewrite.

type
  the type of URL to be rewritten. This is one of the following values:
  - `action`: a standard (non-resource) URL, for which SSL is not required
  - `secure-action`: a standard (non-resource) URL, for which SSL is required
  - `resource`: a resource (e.g., image) URL, for which SSL is not required
  - `secure-resource`: a resource (e.g., image) URL, for which SSL is required

#### Returns

the rewritten URL.

Related Topics

``URLRewriterService.registerURLRewriter(ServletRequest, URLRewriter)``

### rewriteURL(ServletContext, ServletRequest, ServletResponse, String, String, boolean) Method

    public static String rewriteURL(ServletContext servletContext,
                                    ServletRequest request,
                                    ServletResponse response,
                                    String url,
                                    String type,
                                    boolean doEncode)

Rewrite the given URL, using the registered URLRewriter.

#### Parameters

servletContext
  the current ServletContext.

request
  the current HttpServletRequest.

response
  the current HttpServletResponse.

url
  the URL to rewrite.

type
  the type of URL to be rewritten. This is one of the following values:
  - `action`: a standard (non-resource) URL, for which SSL is not required
  - `secure-action`: a standard (non-resource) URL, for which SSL is required
  - `resource`: a resource (e.g., image) URL, for which SSL is not required
  - `secure-resource`: a resource (e.g., image) URL, for which SSL is required

doEncode
  if `true`, the rewritten URL will be encoded using `HttpServletResponse.encodeRedirectURL(String)```.

#### Returns

the rewritten URL.

Related Topics

``URLRewriterService.registerURLRewriter(ServletRequest, URLRewriter)``

### unregisterURLRewriter(ServletRequest) Method

    public static URLRewriter unregisterURLRewriter(ServletRequest request)

Unregister the URLRewriter from the request.

#### Parameters

request
  the current HttpServletRequest.

#### Returns

the URLRewriter that was unregistered, or `null` if there was none registered.

Related Topics

``URLRewriterService.registerURLRewriter(ServletRequest, URLRewriter)``