bjoern@3476: package de.intevation.flys.client.server.features; bjoern@3476: bjoern@3476: import java.io.IOException; bjoern@3476: bjoern@3476: import javax.servlet.ServletContext; bjoern@3476: import javax.servlet.ServletContextEvent; bjoern@3476: import javax.servlet.ServletContextListener; bjoern@3476: bjoern@3476: import org.apache.log4j.Logger; bjoern@3476: bjoern@3476: import de.intevation.flys.client.server.LoggingConfigurator; bjoern@3476: bjoern@3476: /** bjoern@3476: * ServletContextListenter to initalize the Features globally for bjoern@3476: * all Servlets bjoern@3476: */ bjoern@3476: public class FeatureServletContextListener implements ServletContextListener { bjoern@3476: bjoern@3476: public static final String LOG4J_PROPERTIES = "FLYS_CLIENT_LOG4J_PROPERIES"; bjoern@3476: bjoern@3476: public static final Logger logger = Logger.getLogger(FeatureServletContextListener.class); bjoern@3476: bjoern@3476: @Override bjoern@3476: public void contextInitialized(ServletContextEvent sce) { bjoern@3476: ServletContext sc = sce.getServletContext(); bjoern@3476: bjoern@3476: this.initLogging(sc); bjoern@3476: bjoern@3476: String filename = sc.getInitParameter("features-file"); bjoern@3476: bjoern@3476: logger.debug("Initializing ServletContext"); bjoern@3476: try { bjoern@3476: XMLFileFeatures features = new XMLFileFeatures(sc.getRealPath(filename)); bjoern@3476: sc.setAttribute(Features.CONTEXT_ATTRIBUTE, features); bjoern@3476: } catch(IOException e) { bjoern@3476: logger.error(e); bjoern@3476: } bjoern@3476: } bjoern@3476: bjoern@3476: @Override bjoern@3476: public void contextDestroyed(ServletContextEvent sce) { bjoern@3476: //DO NOTHING bjoern@3476: } bjoern@3476: bjoern@3476: bjoern@3476: private void initLogging(ServletContext sc) { bjoern@3476: String log4jProperties = System.getenv(LOG4J_PROPERTIES); bjoern@3476: bjoern@3476: if (log4jProperties == null || log4jProperties.length() == 0) { bjoern@3476: String file = sc.getInitParameter("log4j-properties"); bjoern@3476: bjoern@3476: if (file != null && file.length() > 0) { bjoern@3476: log4jProperties = sc.getRealPath(file); bjoern@3476: } bjoern@3476: } bjoern@3476: System.out.println(log4jProperties); bjoern@3476: bjoern@3476: LoggingConfigurator.init(log4jProperties); bjoern@3476: } bjoern@3476: }