1 26 package org.snipsnap.net.admin; 27 28 import org.snipsnap.config.Configuration; 29 30 import javax.servlet.http.HttpServletRequest ; 31 import javax.servlet.http.HttpServletResponse ; 32 import java.util.Map ; 33 import java.net.InetAddress ; 34 import java.net.Socket ; 35 import java.net.InetSocketAddress ; 36 import java.net.UnknownHostException ; 37 import java.io.IOException ; 38 39 public class SetupMoblog implements SetupHandler { 40 public String getName() { 41 return "moblog"; 42 } 43 44 public Map setup(HttpServletRequest request, HttpServletResponse response, Configuration config, Map errors) { 45 String pop3Host = request.getParameter(Configuration.APP_MAIL_POP3_HOST); 46 config.setMailPop3Host(pop3Host); 47 if (null != pop3Host && !"".equals(pop3Host)) { 48 try { 49 final InetAddress address = InetAddress.getByName(pop3Host); 51 Socket socket = new Socket (); 52 try { 53 socket.connect(new InetSocketAddress (address, 110), 5 * 1000); 54 socket.close(); 55 } catch (IOException e) { 56 errors.put(Configuration.APP_MAIL_POP3_HOST, Configuration.APP_MAIL_POP3_HOST + ".connect"); 57 } 58 } catch (UnknownHostException e) { 59 errors.put(Configuration.APP_MAIL_POP3_HOST, Configuration.APP_MAIL_POP3_HOST + ".unknown"); 60 } 61 } 62 63 String pop3User = request.getParameter(Configuration.APP_MAIL_POP3_USER); 64 config.setMailPop3User(pop3User); 65 String pop3Pass = request.getParameter(Configuration.APP_MAIL_POP3_PASSWORD); 66 config.setMailPop3Password(pop3Pass); 67 String blogPass = request.getParameter(Configuration.APP_MAIL_BLOG_PASSWORD); 68 config.setMailBlogPassword(blogPass); 69 String 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 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 |