01: package org.claros.commons.mail.configuration;
02:
03: import java.io.IOException;
04:
05: import javax.servlet.ServletException;
06: import javax.servlet.http.HttpServlet;
07:
08: import org.apache.commons.digester.Digester;
09: import org.apache.commons.logging.Log;
10: import org.apache.commons.logging.LogFactory;
11: import org.claros.commons.configuration.Paths;
12: import org.xml.sax.SAXException;
13:
14: public class Initiator extends HttpServlet {
15: /**
16: *
17: */
18: private static final long serialVersionUID = -2277013867291644084L;
19: private static Log log = LogFactory.getLog(Initiator.class);
20:
21: /**
22: * Initialization of the servlet. <br>
23: *
24: * @throws ServletException if an error occure
25: */
26: public void init() throws ServletException {
27: try {
28: Digester digester = new Digester();
29: digester.setValidating(false);
30: digester
31: .addObjectCreate("claros-config/servers",
32: "org.claros.commons.mail.models.ConnectionProfileList");
33: digester.addObjectCreate("claros-config/servers/server",
34: "org.claros.commons.mail.models.ConnectionProfile");
35: digester.addCallMethod(
36: "claros-config/servers/server/shortname",
37: "setShortName", 0);
38: digester.addCallMethod(
39: "claros-config/servers/server/fetch-server",
40: "setFetchServer", 0);
41: digester.addCallMethod(
42: "claros-config/servers/server/fetch-server-port",
43: "setFetchPort", 0);
44: digester.addCallMethod(
45: "claros-config/servers/server/fetch-protocol",
46: "setProtocol", 0);
47: digester.addCallMethod(
48: "claros-config/servers/server/fetch-ssl",
49: "setFetchSSL", 0);
50:
51: digester.addCallMethod(
52: "claros-config/servers/server/smtp-server",
53: "setSmtpServer", 0);
54: digester.addCallMethod(
55: "claros-config/servers/server/smtp-server-port",
56: "setSmtpPort", 0);
57: digester.addCallMethod(
58: "claros-config/servers/server/smtp-authenticated",
59: "setSmtpAuthenticated", 0);
60: digester.addCallMethod(
61: "claros-config/servers/server/smtp-ssl",
62: "setSmtpSSL", 0);
63: digester.addCallMethod(
64: "claros-config/servers/server/folder-namespace",
65: "setFolderNameSpace", 0);
66: digester.addSetNext("claros-config/servers/server",
67: "addConnectionProfile",
68: "org.claros.commons.mail.models.ConnectionProfile");
69: digester.parse(Paths.getCfgFolder() + "/config.xml");
70: } catch (IOException e) {
71: log.fatal(
72: "Could not find config.xml file in your config path.("
73: + Paths.getCfgFolder() + ")", e);
74: } catch (SAXException e) {
75: log
76: .fatal(
77: "Could not validate config.xml file or could not read its contents",
78: e);
79: }
80: }
81: }
|