Class ChainListener
- java.lang.Object
-
- 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.ServletContextListenerServletContextListenerthat automatically scans chain configuration files in the current web application at startup time, and exposes the result in aCatalogunder a specified servlet context attribute. The following context init parameters are utilized:- org.apache.commons.chain.CONFIG_CLASS_RESOURCE -
comma-delimited list of chain configuration resources to be loaded
via
ClassLoader.getResource()calls. If not specified, no class loader resources will be loaded. - org.apache.commons.chain.CONFIG_WEB_RESOURCE - comma-delimited list of chain configuration webapp resources to be loaded. If not specified, no web application resources will be loaded.
- org.apache.commons.chain.CONFIG_ATTR -
Name of the servlet context attribute under which the
resulting
Catalogwill be created or updated. If not specified, it is expected that parsed resources will contain<catalog>elements (which will cause registration of the createdCatalogs into theCatalogFactoryfor this application, and no servet context attribute will be created. NOTE - This parameter is deprecated. - org.apache.commons.chain.RULE_SET -
Fully qualified class name of a Digester
RuleSetimplementation to use for parsing configuration resources (this class must have a public zero-args constructor). If not defined, the standardRuleSetimplementation will be used.
When a web application that has configured this listener is started, it will acquire the
Catalogunder the specified servlet context attribute key, creating a new one if there is none already there. ThisCatalogwill then be populated by scanning configuration resources from the following sources (loaded in this order):- Resources loaded from any
META-INF/chain-config.xmlresource found in a JAR file in/WEB-INF/lib. - Resources loaded from specified resource paths from the
webapp's class loader (via
ClassLoader.getResource()). - Resources loaded from specified resource paths in the web application
archive (via
ServetContext.getResource()).
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 theCatalogFactoryfor this web application.This class requires Servlet 2.3 or later. If you are running on Servlet 2.2 system, consider using
ChainServletinstead. Note thatChainServletuses 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: 658426 $ $Date: 2008-05-20 21:55:38 +0100 (Tue, 20 May 2008) $
- Author:
- Craig R. McClanahan, Ted Husted
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringCONFIG_ATTRThe name of the context init parameter containing the name of the servlet context attribute under which our resultingCatalogwill be stored.static java.lang.StringCONFIG_CLASS_RESOURCEThe name of the context init parameter containing a comma-delimited list of class loader resources to be scanned.static java.lang.StringCONFIG_WEB_RESOURCEThe name of the context init parameter containing a comma-delimited list of web applicaton resources to be scanned.static java.lang.StringRULE_SETThe name of the context init parameter containing the fully qualified class name of theRuleSetimplementation for configuring ourConfigParser.
-
Constructor Summary
Constructors Constructor Description ChainListener()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidcontextDestroyed(javax.servlet.ServletContextEvent event)Remove the configuredCatalogfrom the servlet context attributes for this web application.voidcontextInitialized(javax.servlet.ServletContextEvent event)Scan the required chain configuration resources, assemble the configured chains into aCatalog, and expose it as a servlet context attribute under the specified key.private voidparseJarResources(javax.servlet.ServletContext context, ConfigParser parser, org.apache.commons.logging.Log log)Parse resources found in JAR files in the/WEB-INF/libsubdirectory (if any).private voidparseJarResources(Catalog catalog, javax.servlet.ServletContext context, ConfigParser parser, org.apache.commons.logging.Log log)Deprecated.Use the variant that does not take a catalog, on a configuration resource containing "catalog" element(s)private java.lang.Stringtranslate(java.lang.String value)Translate space character into&pct;20to avoid problems with paths that contain spaces on some JVMs.
-
-
-
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
Catalogwill 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
RuleSetimplementation for configuring ourConfigParser.- See Also:
- Constant Field Values
-
-
Method Detail
-
contextDestroyed
public void contextDestroyed(javax.servlet.ServletContextEvent event)
Remove the configured
Catalogfrom the servlet context attributes for this web application.- Specified by:
contextDestroyedin interfacejavax.servlet.ServletContextListener- Parameters:
event-ServletContextEventto 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:
contextInitializedin interfacejavax.servlet.ServletContextListener- Parameters:
event-ServletContextEventto be processed
-
parseJarResources
private void parseJarResources(javax.servlet.ServletContext context, ConfigParser parser, org.apache.commons.logging.Log log)Parse resources found in JAR files in the
/WEB-INF/libsubdirectory (if any).- Parameters:
context-ServletContextfor this web applicationparser-ConfigParserto use for parsing
-
parseJarResources
private void parseJarResources(Catalog catalog, javax.servlet.ServletContext context, ConfigParser parser, org.apache.commons.logging.Log log)
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/libsubdirectory (if any).- Parameters:
catalog-Catalogwe are populatingcontext-ServletContextfor this web applicationparser-ConfigParserto use for parsing
-
translate
private java.lang.String translate(java.lang.String value)
Translate space character into
&pct;20to avoid problems with paths that contain spaces on some JVMs.- Parameters:
value- Value to translate
-
-