org.apache.commons.chain.web
Class ChainListener

java.lang.Object
  extended by org.apache.commons.chain.web.ChainListener
All Implemented Interfaces:
java.util.EventListener, javax.servlet.ServletContextListener

public class ChainListener
extends java.lang.Object
implements javax.servlet.ServletContextListener

ServletContextListener that automatically scans chain configuration files in the current web application at startup time, and exposes the result in a Catalog under a specified servlet context attribute. The following context init parameters are utilized:

When a web application that has configured this listener is started, it will acquire the Catalog under the specified servlet context attribute key, creating a new one if there is none already there. This Catalog will then be populated by scanning configuration resources from the following sources (loaded in this order):

If no attribute key is specified, on the other hand, parsed configuration resources are expected to contain <catalog> elements, and the catalogs will be registered with the CatalogFactory for this web application.

This class requires Servlet 2.3 or later. If you are running on Servlet 2.2 system, consider using ChainServlet instead. Note that ChainServlet uses parameters of the same names, but they are servlet init parameters instead of context init parameters. Because of this, you can use both facilities in the same application, if desired.

Version:
$Revision: 411893 $ $Date: 2006-06-05 19:59:05 +0100 (Mon, 05 Jun 2006) $
Author:
Craig R. McClanahan, Ted Husted

Field Summary
static java.lang.String CONFIG_ATTR
          The name of the context init parameter containing the name of the servlet context attribute under which our resulting Catalog will be stored.
static java.lang.String CONFIG_CLASS_RESOURCE
          The name of the context init parameter containing a comma-delimited list of class loader resources to be scanned.
static java.lang.String CONFIG_WEB_RESOURCE
          The name of the context init parameter containing a comma-delimited list of web applicaton resources to be scanned.
static java.lang.String RULE_SET
          The name of the context init parameter containing the fully qualified class name of the RuleSet implementation for configuring our ConfigParser.
 
Constructor Summary
ChainListener()
           
 
Method Summary
 void contextDestroyed(javax.servlet.ServletContextEvent event)
          Remove the configured Catalog from the servlet context attributes for this web application.
 void contextInitialized(javax.servlet.ServletContextEvent event)
          Scan the required chain configuration resources, assemble the configured chains into a Catalog, and expose it as a servlet context attribute under the specified key.
private  void parseJarResources(Catalog catalog, javax.servlet.ServletContext context, ConfigParser parser)
          Deprecated. Use the variant that does not take a catalog, on a configuration resource containing "catalog" element(s)
private  void parseJarResources(javax.servlet.ServletContext context, ConfigParser parser)
          Parse resources found in JAR files in the /WEB-INF/lib subdirectory (if any).
private  java.lang.String translate(java.lang.String value)
          Translate space character into &pct;20 to avoid problems with paths that contain spaces on some JVMs.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONFIG_ATTR

public static final java.lang.String CONFIG_ATTR

The name of the context init parameter containing the name of the servlet context attribute under which our resulting Catalog will be stored.

See Also:
Constant Field Values

CONFIG_CLASS_RESOURCE

public static final java.lang.String CONFIG_CLASS_RESOURCE

The name of the context init parameter containing a comma-delimited list of class loader resources to be scanned.

See Also:
Constant Field Values

CONFIG_WEB_RESOURCE

public static final java.lang.String CONFIG_WEB_RESOURCE

The name of the context init parameter containing a comma-delimited list of web applicaton resources to be scanned.

See Also:
Constant Field Values

RULE_SET

public static final java.lang.String RULE_SET

The name of the context init parameter containing the fully qualified class name of the RuleSet implementation for configuring our ConfigParser.

See Also:
Constant Field Values
Constructor Detail

ChainListener

public ChainListener()
Method Detail

contextDestroyed

public void contextDestroyed(javax.servlet.ServletContextEvent event)

Remove the configured Catalog from the servlet context attributes for this web application.

Specified by:
contextDestroyed in interface javax.servlet.ServletContextListener
Parameters:
event - ServletContextEvent to be processed

contextInitialized

public void contextInitialized(javax.servlet.ServletContextEvent event)

Scan the required chain configuration resources, assemble the configured chains into a Catalog, and expose it as a servlet context attribute under the specified key.

Specified by:
contextInitialized in interface javax.servlet.ServletContextListener
Parameters:
event - ServletContextEvent to be processed

parseJarResources

private void parseJarResources(javax.servlet.ServletContext context,
                               ConfigParser parser)

Parse resources found in JAR files in the /WEB-INF/lib subdirectory (if any).

Parameters:
context - ServletContext for this web application
parser - ConfigParser to use for parsing

parseJarResources

private void parseJarResources(Catalog catalog,
                               javax.servlet.ServletContext context,
                               ConfigParser parser)
Deprecated. Use the variant that does not take a catalog, on a configuration resource containing "catalog" element(s)

Parse resources found in JAR files in the /WEB-INF/lib subdirectory (if any).

Parameters:
catalog - Catalog we are populating
context - ServletContext for this web application
parser - ConfigParser to use for parsing

translate

private java.lang.String translate(java.lang.String value)

Translate space character into &pct;20 to avoid problems with paths that contain spaces on some JVMs.

Parameters:
value - Value to translate