info.magnolia.cms.servlets
Class MgnlServletContextListener

java.lang.Object
  extended by info.magnolia.cms.servlets.MgnlServletContextListener
All Implemented Interfaces:
EventListener, javax.servlet.ServletContextListener

public class MgnlServletContextListener
extends Object
implements javax.servlet.ServletContextListener

Magnolia main listener: reads initialization parameter from a properties file. The name of the file can be defined as a context parameter in web.xml. Multiple path, comma separated, are supported (the first existing file in the list will be used), and the following variables will be used:

If no magnolia.initialization.file context parameter is set, the following default is assumed:

 <context-param>
   <param-name>magnolia.initialization.file</param-name>
   <param-value>
      WEB-INF/config/${servername}/${webapp}/magnolia.properties,
      WEB-INF/config/${servername}/magnolia.properties,
      WEB-INF/config/${webapp}/magnolia.properties,
      WEB-INF/config/default/magnolia.properties,
      WEB-INF/config/magnolia.properties
   </param-value>
 </context-param>
 

The ${servername} variable will be resolved to the full name obtained by using InetAddress.getLocalHost().getHostName(), which may also contain the server domain, depending on your server configuration/operating system. You can set the optional context parameter "magnolia.unqualified.server.name" to true if you prefer using the unqualified name (the server "server.domain.com" will be simply resolved as "server")

 <context-param>
   <param-name>magnolia.unqualified.server.name</param-name>
   <param-value>true</param-value>
 </context-param>
 
The following parameters are needed in the properties file:

Advance use: deployment service

Using the ${servername} and ${webapp} properties you can easily bundle in the same webapp different set of configurations which are automatically applied dependending on the server name (useful for switching between development, test and production instances where the repository configuration need to be different) or the webapp name (useful to bundle both the public and admin log4j/jndi/bootstrap configuration in the same war). By default the initializer will try to search for the file in different location with different combination of servername and webapp: the default fallback directory will be used if no other environment-specific directory has been added.

Author:
Fabrizio Giustina

Field Summary
static String MAGNOLIA_INITIALIZATION_FILE
          Context parameter name.
static String MAGNOLIA_UNQUALIFIED_SERVER_NAME
          Context parameter name.
 
Constructor Summary
MgnlServletContextListener()
           
 
Method Summary
 void contextDestroyed(javax.servlet.ServletContextEvent sce)
           
 void contextInitialized(javax.servlet.ServletContextEvent sce)
           
protected  String getPropertiesFilesString(javax.servlet.ServletContext context, String servername, String webapp)
           
protected  String initRootPath(javax.servlet.ServletContext context)
          Initializes the application real root path.
protected  String initServername(boolean unqualified)
           
protected  String initWebappName(String rootPath)
           
protected  void startServer(javax.servlet.ServletContext context)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAGNOLIA_INITIALIZATION_FILE

public static final String MAGNOLIA_INITIALIZATION_FILE
Context parameter name.

See Also:
Constant Field Values

MAGNOLIA_UNQUALIFIED_SERVER_NAME

public static final String MAGNOLIA_UNQUALIFIED_SERVER_NAME
Context parameter name. If set to true in web.xml the server name resolved by magnolia will never contain the domain (the server "server.domain.com" will be simply resolved as "server").

See Also:
Constant Field Values
Constructor Detail

MgnlServletContextListener

public MgnlServletContextListener()
Method Detail

contextDestroyed

public void contextDestroyed(javax.servlet.ServletContextEvent sce)
Specified by:
contextDestroyed in interface javax.servlet.ServletContextListener

contextInitialized

public void contextInitialized(javax.servlet.ServletContextEvent sce)
Specified by:
contextInitialized in interface javax.servlet.ServletContextListener
See Also:
ServletContextListener.contextInitialized(javax.servlet.ServletContextEvent)

startServer

protected void startServer(javax.servlet.ServletContext context)

getPropertiesFilesString

protected String getPropertiesFilesString(javax.servlet.ServletContext context,
                                          String servername,
                                          String webapp)

initWebappName

protected String initWebappName(String rootPath)

initRootPath

protected String initRootPath(javax.servlet.ServletContext context)
Initializes the application real root path.

Parameters:
context - Servlet context.
Returns:
Real path.

initServername

protected String initServername(boolean unqualified)


Copyright © 2003-2011 Magnolia International Ltd.. All Rights Reserved.