1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package davmail.web;
20
21 import davmail.BundleMessage;
22 import davmail.DavGateway;
23 import davmail.Settings;
24 import davmail.ui.tray.DavGatewayTray;
25
26 import javax.servlet.ServletContextEvent;
27 import javax.servlet.ServletContextListener;
28 import java.io.IOException;
29 import java.io.InputStream;
30
31
32
33
34 public class DavGatewayServletContextListener implements ServletContextListener {
35 public void contextInitialized(ServletContextEvent event) {
36 InputStream settingInputStream = null;
37 try {
38 settingInputStream = DavGatewayServletContextListener.class.getClassLoader().getResourceAsStream("davmail.properties");
39 Settings.load(settingInputStream);
40 DavGateway.start();
41 } catch (IOException e) {
42 DavGatewayTray.error(new BundleMessage("LOG_ERROR_LOADING_SETTINGS"), e);
43 } finally {
44 if (settingInputStream != null) {
45 try {
46 settingInputStream.close();
47 } catch (IOException e) {
48 DavGatewayTray.debug(new BundleMessage("LOG_ERROR_CLOSING_CONFIG_FILE"), e);
49 }
50 }
51 }
52 DavGatewayTray.debug(new BundleMessage("LOG_DAVMAIL_STARTED"));
53 }
54
55 public void contextDestroyed(ServletContextEvent event) {
56 DavGatewayTray.debug(new BundleMessage("LOG_STOPPING_DAVMAIL"));
57 DavGateway.stop();
58 }
59 }