1 13 package info.magnolia.cms.servlets; 14 15 import info.magnolia.cms.beans.config.ConfigLoader; 16 import info.magnolia.logging.Log4jConfigurer; 17 18 import java.util.Enumeration ; 19 import java.util.HashMap ; 20 import java.util.Map ; 21 22 import javax.servlet.ServletContext ; 23 import javax.servlet.ServletContextEvent ; 24 import javax.servlet.ServletContextListener ; 25 26 import org.apache.log4j.Logger; 27 28 29 74 public class Initializer implements ServletContextListener { 75 76 79 private static final long serialVersionUID = 222L; 80 81 84 private static Logger log = Logger.getLogger(Initializer.class); 85 86 97 public void contextInitialized(ServletContextEvent sce) { 98 ServletContext context = sce.getServletContext(); 99 100 Map parameters = new HashMap (); 102 Enumeration configParams = context.getInitParameterNames(); 103 while (configParams.hasMoreElements()) { 104 String paramName = (String ) configParams.nextElement(); 105 parameters.put(paramName, context.getInitParameter(paramName)); 106 } 107 108 Log4jConfigurer.initLogging(context, parameters); 109 110 try { 111 new ConfigLoader(context, parameters); 112 } 113 catch (Exception e) { 114 log.fatal(e.getMessage(), e); 115 } 116 } 117 118 122 public void contextDestroyed(ServletContextEvent sce) { 123 ServletContext context = sce.getServletContext(); 124 125 Map parameters = new HashMap (); 127 Enumeration configParams = context.getInitParameterNames(); 128 while (configParams.hasMoreElements()) { 129 String paramName = (String ) configParams.nextElement(); 130 parameters.put(paramName, context.getInitParameter(paramName)); 131 } 132 133 Log4jConfigurer.shutdownLogging(parameters); 134 } 135 136 } 137 | Popular Tags |