org.chwf.servlet.filter
Class ResourceMapper

java.lang.Object
  |
  +--org.chwf.servlet.filter.FilterSupport
        |
        +--org.chwf.servlet.filter.ResourceMapper
All Implemented Interfaces:
javax.servlet.Filter

public class ResourceMapper
extends FilterSupport

Filter that maps one file extension to another file extension. It is used as a generic terminal filter.

Author:
Paul Strack

Field Summary
static java.lang.String TARGET_URI
          Key used to cache the target URI in the request.
 
Constructor Summary
ResourceMapper()
           
 
Method Summary
 void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain)
          The ResourceMapping invokes to the mapped resource using the RequestDispatcher.include() method.
static java.lang.String getContextFreeURI(javax.servlet.http.HttpServletRequest request)
          Retrieves the request URI with the context-path remove.
static ResourceMapper getFilter(javax.servlet.http.HttpServletRequest request)
          Get the resource mapper.
static java.lang.String getMappedURI(javax.servlet.http.HttpServletRequest request)
          Retrieve the mapped URI, or the original URI if it is not mapped.
static java.lang.String getTargetURI(javax.servlet.http.HttpServletRequest request)
          Retrieve the original context-free URI from the request, if cached.
 void init(javax.servlet.FilterConfig config)
          Initialize the resource mapping.
static void init(javax.servlet.ServletContext context)
          Initialize the resource mapping.
 
Methods inherited from class org.chwf.servlet.filter.FilterSupport
destroy, doHttpFilter, getConfig
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TARGET_URI

public static final java.lang.String TARGET_URI
Key used to cache the target URI in the request.
Constructor Detail

ResourceMapper

public ResourceMapper()
Method Detail

getContextFreeURI

public static java.lang.String getContextFreeURI(javax.servlet.http.HttpServletRequest request)
Retrieves the request URI with the context-path remove.

Parameters:
request - The request.
Returns:
The context-free URI.

getFilter

public static ResourceMapper getFilter(javax.servlet.http.HttpServletRequest request)
Get the resource mapper.
Parameters:
request - The request.
Returns:
The Resource Mapper (a singleton).

getTargetURI

public static java.lang.String getTargetURI(javax.servlet.http.HttpServletRequest request)
Retrieve the original context-free URI from the request, if cached. Otherwise it returns (and caches) the current context-free URI.
Parameters:
request - The request.
Returns:
The context-relative URI.

getMappedURI

public static java.lang.String getMappedURI(javax.servlet.http.HttpServletRequest request)
Retrieve the mapped URI, or the original URI if it is not mapped.
Parameters:
request - The request.
Returns:
The mapped uri.

init

public static void init(javax.servlet.ServletContext context)
                 throws javax.servlet.ServletException
Initialize the resource mapping. Loads the resource configuration from the "WEB-INF/filter.xml" file.
Parameters:
context - The servlet context.
Throws:
javax.servlet.ServletException - If the filter configuration cannot be loaded.

init

public void init(javax.servlet.FilterConfig config)
          throws javax.servlet.ServletException
Initialize the resource mapping. Delegates to the init(ServletContext) method.
Overrides:
init in class FilterSupport
Parameters:
config - The filter configuration.
Throws:
javax.servlet.ServletException - If the filter configuration cannot be loaded.

doFilter

public void doFilter(javax.servlet.ServletRequest request,
                     javax.servlet.ServletResponse response,
                     javax.servlet.FilterChain chain)
              throws java.io.IOException,
                     javax.servlet.ServletException
The ResourceMapping invokes to the mapped resource using the RequestDispatcher.include() method. If the resource is not mapped, it either (a) generates an error [Servlet 2.2] or (b) invokes the resource at the end of the filter chain [Servlet 2.3+].
Overrides:
doFilter in class FilterSupport
Parameters:
request - The request.
response - The response.
chain - The filter chain.
Throws:
javax.servlet.ServletException - For servlet errors.
java.io.IOException - For I/O errors.


Copyright © 2002-2004, Paul Strack. All Rights Reserved.