Mercurial > dive4elements > river
annotate gwt-client/src/main/java/org/dive4elements/river/client/server/BaseServletContextListener.java @ 5861:172338b1407f
GWT client: Added copyright header.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Sun, 28 Apr 2013 14:30:15 +0200 |
parents | 5aa05a7a34b7 |
children | 88d6bddbf6cd |
rev | line source |
---|---|
5861
172338b1407f
GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde |
172338b1407f
GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
2 * Software engineering by Intevation GmbH |
172338b1407f
GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
3 * |
172338b1407f
GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
4 * This file is Free Software under the GNU AGPL (>=v3) |
172338b1407f
GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the |
172338b1407f
GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
6 * documentation coming with Dive4Elements River for details. |
172338b1407f
GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
7 */ |
172338b1407f
GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
8 |
5835
821a02bbfb4e
Fixed internal java dependencies
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5834
diff
changeset
|
9 package org.dive4elements.river.client.server; |
3478
763789a9acca
Rename FeatureServletContextListener and move it out of the features package
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
10 |
763789a9acca
Rename FeatureServletContextListener and move it out of the features package
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
11 import java.io.IOException; |
763789a9acca
Rename FeatureServletContextListener and move it out of the features package
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
12 |
763789a9acca
Rename FeatureServletContextListener and move it out of the features package
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
13 import javax.servlet.ServletContext; |
763789a9acca
Rename FeatureServletContextListener and move it out of the features package
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
14 import javax.servlet.ServletContextEvent; |
763789a9acca
Rename FeatureServletContextListener and move it out of the features package
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
15 import javax.servlet.ServletContextListener; |
763789a9acca
Rename FeatureServletContextListener and move it out of the features package
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
16 |
763789a9acca
Rename FeatureServletContextListener and move it out of the features package
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
17 import org.apache.log4j.Logger; |
763789a9acca
Rename FeatureServletContextListener and move it out of the features package
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
18 |
5835
821a02bbfb4e
Fixed internal java dependencies
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5834
diff
changeset
|
19 import org.dive4elements.river.client.server.LoggingConfigurator; |
821a02bbfb4e
Fixed internal java dependencies
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5834
diff
changeset
|
20 import org.dive4elements.river.client.server.features.Features; |
821a02bbfb4e
Fixed internal java dependencies
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5834
diff
changeset
|
21 import org.dive4elements.river.client.server.features.XMLFileFeatures; |
3478
763789a9acca
Rename FeatureServletContextListener and move it out of the features package
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
22 |
763789a9acca
Rename FeatureServletContextListener and move it out of the features package
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
23 /** |
763789a9acca
Rename FeatureServletContextListener and move it out of the features package
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
24 * ServletContextListenter to initalize the Features globally for |
763789a9acca
Rename FeatureServletContextListener and move it out of the features package
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
25 * all Servlets |
763789a9acca
Rename FeatureServletContextListener and move it out of the features package
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
26 */ |
763789a9acca
Rename FeatureServletContextListener and move it out of the features package
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
27 public class BaseServletContextListener implements ServletContextListener { |
763789a9acca
Rename FeatureServletContextListener and move it out of the features package
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
28 |
763789a9acca
Rename FeatureServletContextListener and move it out of the features package
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
29 public static final String LOG4J_PROPERTIES = "FLYS_CLIENT_LOG4J_PROPERIES"; |
763789a9acca
Rename FeatureServletContextListener and move it out of the features package
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
30 |
763789a9acca
Rename FeatureServletContextListener and move it out of the features package
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
31 public static final Logger logger = Logger.getLogger(BaseServletContextListener.class); |
763789a9acca
Rename FeatureServletContextListener and move it out of the features package
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
32 |
763789a9acca
Rename FeatureServletContextListener and move it out of the features package
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
33 @Override |
763789a9acca
Rename FeatureServletContextListener and move it out of the features package
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
34 public void contextInitialized(ServletContextEvent sce) { |
763789a9acca
Rename FeatureServletContextListener and move it out of the features package
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
35 ServletContext sc = sce.getServletContext(); |
763789a9acca
Rename FeatureServletContextListener and move it out of the features package
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
36 |
763789a9acca
Rename FeatureServletContextListener and move it out of the features package
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
37 this.initLogging(sc); |
763789a9acca
Rename FeatureServletContextListener and move it out of the features package
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
38 |
763789a9acca
Rename FeatureServletContextListener and move it out of the features package
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
39 String filename = sc.getInitParameter("features-file"); |
763789a9acca
Rename FeatureServletContextListener and move it out of the features package
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
40 |
763789a9acca
Rename FeatureServletContextListener and move it out of the features package
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
41 logger.debug("Initializing ServletContext"); |
763789a9acca
Rename FeatureServletContextListener and move it out of the features package
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
42 try { |
763789a9acca
Rename FeatureServletContextListener and move it out of the features package
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
43 XMLFileFeatures features = new XMLFileFeatures(sc.getRealPath(filename)); |
763789a9acca
Rename FeatureServletContextListener and move it out of the features package
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
44 sc.setAttribute(Features.CONTEXT_ATTRIBUTE, features); |
763789a9acca
Rename FeatureServletContextListener and move it out of the features package
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
45 } catch(IOException e) { |
763789a9acca
Rename FeatureServletContextListener and move it out of the features package
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
46 logger.error(e); |
763789a9acca
Rename FeatureServletContextListener and move it out of the features package
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
47 } |
763789a9acca
Rename FeatureServletContextListener and move it out of the features package
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
48 } |
763789a9acca
Rename FeatureServletContextListener and move it out of the features package
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
49 |
763789a9acca
Rename FeatureServletContextListener and move it out of the features package
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
50 @Override |
763789a9acca
Rename FeatureServletContextListener and move it out of the features package
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
51 public void contextDestroyed(ServletContextEvent sce) { |
763789a9acca
Rename FeatureServletContextListener and move it out of the features package
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
52 //DO NOTHING |
763789a9acca
Rename FeatureServletContextListener and move it out of the features package
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
53 } |
763789a9acca
Rename FeatureServletContextListener and move it out of the features package
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
54 |
763789a9acca
Rename FeatureServletContextListener and move it out of the features package
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
55 |
763789a9acca
Rename FeatureServletContextListener and move it out of the features package
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
56 private void initLogging(ServletContext sc) { |
763789a9acca
Rename FeatureServletContextListener and move it out of the features package
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
57 String log4jProperties = System.getenv(LOG4J_PROPERTIES); |
763789a9acca
Rename FeatureServletContextListener and move it out of the features package
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
58 |
763789a9acca
Rename FeatureServletContextListener and move it out of the features package
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
59 if (log4jProperties == null || log4jProperties.length() == 0) { |
763789a9acca
Rename FeatureServletContextListener and move it out of the features package
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
60 String file = sc.getInitParameter("log4j-properties"); |
763789a9acca
Rename FeatureServletContextListener and move it out of the features package
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
61 |
763789a9acca
Rename FeatureServletContextListener and move it out of the features package
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
62 if (file != null && file.length() > 0) { |
763789a9acca
Rename FeatureServletContextListener and move it out of the features package
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
63 log4jProperties = sc.getRealPath(file); |
763789a9acca
Rename FeatureServletContextListener and move it out of the features package
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
64 } |
763789a9acca
Rename FeatureServletContextListener and move it out of the features package
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
65 } |
763789a9acca
Rename FeatureServletContextListener and move it out of the features package
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
66 System.out.println(log4jProperties); |
763789a9acca
Rename FeatureServletContextListener and move it out of the features package
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
67 |
763789a9acca
Rename FeatureServletContextListener and move it out of the features package
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
68 LoggingConfigurator.init(log4jProperties); |
763789a9acca
Rename FeatureServletContextListener and move it out of the features package
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
69 } |
763789a9acca
Rename FeatureServletContextListener and move it out of the features package
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
70 } |