Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/server/BaseServletContextListener.java @ 3478:763789a9acca
Rename FeatureServletContextListener and move it out of the features package
flys-client/trunk@5173 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Bjoern Ricks <bjoern.ricks@intevation.de> |
---|---|
date | Wed, 08 Aug 2012 13:04:07 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
3477:2c63994ceffb | 3478:763789a9acca |
---|---|
1 package de.intevation.flys.client.server; | |
2 | |
3 import java.io.IOException; | |
4 | |
5 import javax.servlet.ServletContext; | |
6 import javax.servlet.ServletContextEvent; | |
7 import javax.servlet.ServletContextListener; | |
8 | |
9 import org.apache.log4j.Logger; | |
10 | |
11 import de.intevation.flys.client.server.LoggingConfigurator; | |
12 import de.intevation.flys.client.server.features.Features; | |
13 import de.intevation.flys.client.server.features.XMLFileFeatures; | |
14 | |
15 /** | |
16 * ServletContextListenter to initalize the Features globally for | |
17 * all Servlets | |
18 */ | |
19 public class BaseServletContextListener implements ServletContextListener { | |
20 | |
21 public static final String LOG4J_PROPERTIES = "FLYS_CLIENT_LOG4J_PROPERIES"; | |
22 | |
23 public static final Logger logger = Logger.getLogger(BaseServletContextListener.class); | |
24 | |
25 @Override | |
26 public void contextInitialized(ServletContextEvent sce) { | |
27 ServletContext sc = sce.getServletContext(); | |
28 | |
29 this.initLogging(sc); | |
30 | |
31 String filename = sc.getInitParameter("features-file"); | |
32 | |
33 logger.debug("Initializing ServletContext"); | |
34 try { | |
35 XMLFileFeatures features = new XMLFileFeatures(sc.getRealPath(filename)); | |
36 sc.setAttribute(Features.CONTEXT_ATTRIBUTE, features); | |
37 } catch(IOException e) { | |
38 logger.error(e); | |
39 } | |
40 } | |
41 | |
42 @Override | |
43 public void contextDestroyed(ServletContextEvent sce) { | |
44 //DO NOTHING | |
45 } | |
46 | |
47 | |
48 private void initLogging(ServletContext sc) { | |
49 String log4jProperties = System.getenv(LOG4J_PROPERTIES); | |
50 | |
51 if (log4jProperties == null || log4jProperties.length() == 0) { | |
52 String file = sc.getInitParameter("log4j-properties"); | |
53 | |
54 if (file != null && file.length() > 0) { | |
55 log4jProperties = sc.getRealPath(file); | |
56 } | |
57 } | |
58 System.out.println(log4jProperties); | |
59 | |
60 LoggingConfigurator.init(log4jProperties); | |
61 } | |
62 } |