1 package fr.ifremer.coser.web;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 import fr.ifremer.coser.bean.ZoneMap;
25 import org.apache.commons.lang3.StringUtils;
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28
29 import javax.servlet.ServletContextEvent;
30 import javax.servlet.ServletContextListener;
31 import java.util.Date;
32 import java.util.Map;
33
34
35
36
37
38
39
40
41
42
43
44 public class CoserApplicationListener implements ServletContextListener {
45
46
47 protected static final Log log =
48 LogFactory.getLog(CoserApplicationListener.class);
49
50 @Override
51 public void contextInitialized(ServletContextEvent sce) {
52
53 if (log.isInfoEnabled()) {
54 log.info("Application starting at " + new Date() + "...");
55 }
56 CoserWebApplicationContext.init();
57
58 CoserWebApplicationContext coserWebApplicationContext = CoserWebApplicationContext.get();
59
60 checkConfiguration(coserWebApplicationContext);
61 }
62
63 @Override
64 public void contextDestroyed(ServletContextEvent sce) {
65 if (log.isInfoEnabled()) {
66 log.info("Application is ending at " + new Date() + "...");
67 }
68 CoserWebApplicationContext.close();
69 }
70
71 protected void checkConfiguration(CoserWebApplicationContext coserWebApplicationContext) {
72
73
74
75 ZoneMap zoneMap = coserWebApplicationContext.getZoneMap();
76
77 Map<String, String> zonePictures = zoneMap.getZonePictures();
78 for (Map.Entry<String, String> entry : zonePictures.entrySet()) {
79
80 if (StringUtils.isBlank(entry.getValue())) {
81
82 if (log.isErrorEnabled()) {
83 log.error(String.format("Zone with no picture: %s", entry.getKey()));
84 }
85 }
86 }
87
88 }
89 }