View Javadoc
1   /*
2    * DavMail POP/IMAP/SMTP/CalDav/LDAP Exchange Gateway
3    * Copyright (C) 2009  Mickael Guessant
4    *
5    * This program is free software; you can redistribute it and/or
6    * modify it under the terms of the GNU General Public License
7    * as published by the Free Software Foundation; either version 2
8    * of the License, or (at your option) any later version.
9    *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   *
15   * You should have received a copy of the GNU General Public License
16   * along with this program; if not, write to the Free Software
17   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
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   * Context Listener to start/stop DavMail
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  }