javawebparts.filter
Class FilterHelpers

java.lang.Object
  |
  +--javawebparts.filter.FilterHelpers

public final class FilterHelpers
extends java.lang.Object

This class contains static methods that are used by a number of different filters.

Author:
Frank W. Zammetti.

Field Summary
private static org.apache.commons.logging.Log log
          Log instance.
 
Constructor Summary
private FilterHelpers()
          This is a utility class, so we want a private noarg constructor so instances cannot be created.
 
Method Summary
static void checkRedirectForwardTo(java.lang.String filterName, java.lang.String redirectTo, java.lang.String forwardTo)
          For filters that support the redirectTo and forwardTo init parameters, only one or the other can be specified, never both, and at least one must be specified.
static boolean filterPath(javax.servlet.ServletRequest request, java.util.ArrayList pathList, java.lang.String inPathSpec)
          Determines whether a filter should do its work.
static java.lang.String initForwardTo(javax.servlet.FilterConfig filterConfig)
          Gets the forwardTo init parameter that is common to many filters.
static java.util.ArrayList initPathList(java.lang.String filterName, javax.servlet.FilterConfig filterConfig)
          This is a common function used by a number of filters to get the list of paths the filter will function or not function on.
static java.lang.String initPathSpec(java.lang.String filterName, javax.servlet.FilterConfig filterConfig)
          This is a common function used by a number of filters to get the init parameter that describes the path list.
static java.lang.String initRedirectTo(javax.servlet.FilterConfig filterConfig)
          Gets the redirectTo init parameter that is common to many filters.
static void redirectOrForward(java.lang.String redirectTo, java.lang.String forwardTo, javax.servlet.ServletRequest request, javax.servlet.ServletResponse response)
          This is called by any filter after it determines that a request should be aborted.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static org.apache.commons.logging.Log log
Log instance.

Constructor Detail

FilterHelpers

private FilterHelpers()
This is a utility class, so we want a private noarg constructor so instances cannot be created.

Method Detail

initPathSpec

public static java.lang.String initPathSpec(java.lang.String filterName,
                                            javax.servlet.FilterConfig filterConfig)
                                     throws javax.servlet.ServletException
This is a common function used by a number of filters to get the init parameter that describes the path list.

Parameters:
filterName - The name of the filter calling this function. This is for logging purposes.
filterConfig - The filterConfig instance associated with the filter.
Returns:
The pathSpec value.
Throws:
javax.servlet.ServletException - If anything goes wrong.

initPathList

public static java.util.ArrayList initPathList(java.lang.String filterName,
                                               javax.servlet.FilterConfig filterConfig)
This is a common function used by a number of filters to get the list of paths the filter will function or not function on.

Parameters:
filterName - The name of the filter calling this function. This is for logging purposes.
filterConfig - The filterConfig instance associated with the filter.
Returns:
The list of paths configured for the filter.

initRedirectTo

public static java.lang.String initRedirectTo(javax.servlet.FilterConfig filterConfig)
Gets the redirectTo init parameter that is common to many filters.

Parameters:
filterConfig - The filterConfig instance associated with the filter.
Returns:
The value of the redirectTo init param.

initForwardTo

public static java.lang.String initForwardTo(javax.servlet.FilterConfig filterConfig)
Gets the forwardTo init parameter that is common to many filters.

Parameters:
filterConfig - The filterConfig instance associated with the filter.
Returns:
The value of the forwardTo init param.

checkRedirectForwardTo

public static void checkRedirectForwardTo(java.lang.String filterName,
                                          java.lang.String redirectTo,
                                          java.lang.String forwardTo)
                                   throws javax.servlet.ServletException
For filters that support the redirectTo and forwardTo init parameters, only one or the other can be specified, never both, and at least one must be specified. This method performs that check.

Parameters:
filterName - The name of the filter calling this check.
redirectTo - The value of the redirectTo init param.
forwardTo - The value of the forwardTo init param.
Throws:
javax.servlet.ServletException - If the tests are not passed.

filterPath

public static boolean filterPath(javax.servlet.ServletRequest request,
                                 java.util.ArrayList pathList,
                                 java.lang.String inPathSpec)
Determines whether a filter should do its work. It is passed an ArrayList containing a list of paths, with wildcard support, and whether those paths should be included or excluded by the filter.

Parameters:
request - ServlerRequest object.
pathList - The ArrayList containing the lists of paths to either include or exclude.
inPathSpec - Whether the paths are included or excluded.
Returns:
True if the calling filter should apply itself to the request, false if not.

redirectOrForward

public static void redirectOrForward(java.lang.String redirectTo,
                                     java.lang.String forwardTo,
                                     javax.servlet.ServletRequest request,
                                     javax.servlet.ServletResponse response)
                              throws javax.servlet.ServletException,
                                     java.io.IOException
This is called by any filter after it determines that a request should be aborted. It determines whether to do a forward or redirect as specified in the filter's config, and does it.

Parameters:
redirectTo - The URL to redirect to, if specified.
forwardTo - The URL to forward to, if specified.
request - The current request.
response - The current response.
Throws:
javax.servlet.ServletException - If anything goes wrong.
java.io.IOException - If anything goes wrong.


Copyright © 2005 Frank W. Zammetti