KickJava   Java API By Example, From Geeks To Geeks.

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


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
34 public class SetupAdministrator implements SetupHandler {
35   public String JavaDoc getName() {
36     return "administrator";
37   }
38
39   public Map JavaDoc setup(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response, Configuration config, Map JavaDoc errors) {
40     String JavaDoc login = request.getParameter(Configuration.APP_ADMIN_LOGIN);
41     config.setAdminLogin(login);
42     if (null == login || "".equals(login)) {
43       errors.put(Configuration.APP_ADMIN_LOGIN, Configuration.APP_ADMIN_LOGIN);
44     }
45     String JavaDoc password = request.getParameter(Configuration.APP_ADMIN_PASSWORD);
46     String JavaDoc verify = request.getParameter(Configuration.APP_ADMIN_PASSWORD + ".vrfy");
47     if ((password != null && password.length() > 0) || config.getAdminPassword() == null) {
48       if (password == null || password.length() == 0) {
49         errors.put(Configuration.APP_ADMIN_PASSWORD, Configuration.APP_ADMIN_PASSWORD);
50       } else if (!password.equals(verify)) {
51         errors.put(Configuration.APP_ADMIN_PASSWORD, Configuration.APP_ADMIN_PASSWORD + ".match");
52       } else if (password.length() < 3) {
53         errors.put(Configuration.APP_ADMIN_PASSWORD, Configuration.APP_ADMIN_PASSWORD + ".length");
54       } else {
55         config.setAdminPassword(password);
56       }
57     }
58     config.setAdminEmail(request.getParameter(Configuration.APP_ADMIN_EMAIL));
59
60     return errors;
61   }
62 }
63
Popular Tags