KickJava   Java API By Example, From Geeks To Geeks.

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


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 SetupMoblog implements SetupHandler {
40   public String JavaDoc getName() {
41     return "moblog";
42   }
43
44   public Map JavaDoc setup(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response, Configuration config, Map JavaDoc errors) {
45     String JavaDoc pop3Host = request.getParameter(Configuration.APP_MAIL_POP3_HOST);
46     config.setMailPop3Host(pop3Host);
47     if (null != pop3Host && !"".equals(pop3Host)) {
48       try {
49         // check host name/address
50
final InetAddress JavaDoc address = InetAddress.getByName(pop3Host);
51         Socket JavaDoc socket = new Socket JavaDoc();
52         try {
53           socket.connect(new InetSocketAddress JavaDoc(address, 110), 5 * 1000);
54           socket.close();
55         } catch (IOException JavaDoc e) {
56           errors.put(Configuration.APP_MAIL_POP3_HOST, Configuration.APP_MAIL_POP3_HOST + ".connect");
57         }
58       } catch (UnknownHostException JavaDoc e) {
59         errors.put(Configuration.APP_MAIL_POP3_HOST, Configuration.APP_MAIL_POP3_HOST + ".unknown");
60       }
61     }
62
63     String JavaDoc pop3User = request.getParameter(Configuration.APP_MAIL_POP3_USER);
64     config.setMailPop3User(pop3User);
65     String JavaDoc pop3Pass = request.getParameter(Configuration.APP_MAIL_POP3_PASSWORD);
66     config.setMailPop3Password(pop3Pass);
67     String JavaDoc blogPass = request.getParameter(Configuration.APP_MAIL_BLOG_PASSWORD);
68     config.setMailBlogPassword(blogPass);
69     String JavaDoc pop3Interval = request.getParameter(Configuration.APP_MAIL_POP3_INTERVAL);
70     config.setMailPop3Interval(pop3Interval);
71
72     if (config.getMailPop3Host() != null && !"".equals(config.getMailPop3Host())) {
73       if (pop3User == null || "".equals(pop3User)) {
74         errors.put(Configuration.APP_MAIL_POP3_USER, Configuration.APP_MAIL_POP3_USER);
75       }
76
77       if (blogPass == null || "".equals(blogPass) || blogPass.length() < 3) {
78         errors.put(Configuration.APP_MAIL_BLOG_PASSWORD, Configuration.APP_MAIL_BLOG_PASSWORD);
79       }
80
81       try {
82         int interval = Integer.parseInt(pop3Interval);
83         if (interval < 5) {
84           errors.put(Configuration.APP_MAIL_POP3_INTERVAL, Configuration.APP_MAIL_POP3_INTERVAL);
85         }
86       } catch (NumberFormatException JavaDoc e) {
87         errors.put(Configuration.APP_MAIL_POP3_INTERVAL, Configuration.APP_MAIL_POP3_INTERVAL + ".format");
88       }
89     }
90
91     return errors;
92   }
93 }
94
Popular Tags