KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snipsnap > net > admin > SetupMail


1 /*
2  * This file is part of "SnipSnap Wiki/Weblog".
3  *
4  * Copyright (c) 2002,2003 Fraunhofer Gesellschaft
5  * Fraunhofer Institut for Computer Architecture and Software Technology
6  * All Rights Reserved.
7  *
8  * Please visit http://snipsnap.org/ for updates and contact.
9  *
10  * --LICENSE NOTICE--
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24  * --LICENSE NOTICE--
25  */

26 package org.snipsnap.net.admin;
27
28 import org.snipsnap.config.Configuration;
29
30 import javax.servlet.http.HttpServletRequest JavaDoc;
31 import javax.servlet.http.HttpServletResponse JavaDoc;
32 import java.util.Map JavaDoc;
33 import java.net.InetAddress JavaDoc;
34 import java.net.Socket JavaDoc;
35 import java.net.InetSocketAddress JavaDoc;
36 import java.net.UnknownHostException JavaDoc;
37 import java.io.IOException JavaDoc;
38
39 public class SetupMail implements SetupHandler {
40   public String JavaDoc getName() {
41     return "mail";
42   }
43
44   public Map JavaDoc setup(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response, Configuration config, Map JavaDoc errors) {
45     String JavaDoc mailHost = request.getParameter(Configuration.APP_MAIL_HOST);
46     config.setMailHost(mailHost);
47     if (null != mailHost && !"".equals(mailHost)) {
48       try {
49         // check host name/address
50
final InetAddress JavaDoc address = InetAddress.getByName(mailHost);
51         Socket JavaDoc socket = new Socket JavaDoc();
52         try {
53           socket.connect(new InetSocketAddress JavaDoc(address, 25), 5 * 1000);
54           socket.close();
55         } catch (IOException JavaDoc e) {
56           errors.put(Configuration.APP_MAIL_HOST, Configuration.APP_MAIL_HOST + ".connect");
57         }
58       } catch (UnknownHostException JavaDoc e) {
59         errors.put(Configuration.APP_MAIL_HOST, Configuration.APP_MAIL_HOST + ".unknown");
60       }
61     }
62
63     String JavaDoc mailDomain = request.getParameter(Configuration.APP_MAIL_DOMAIN);
64     config.setMailDomain(mailDomain);
65     if (config.getMailHost() != null && !"".equals(config.getMailHost())) {
66       if (mailDomain == null || "".equals(mailDomain) || mailDomain.indexOf('@') != -1) {
67         errors.put(Configuration.APP_MAIL_DOMAIN, Configuration.APP_MAIL_DOMAIN);
68       }
69     }
70
71     return errors;
72   }
73 }
74
Popular Tags