KickJava   Java API By Example, From Geeks To Geeks.

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


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.radeox.util.logging.LogHandler;
29 import org.radeox.util.logging.Logger;
30 import org.snipsnap.config.Configuration;
31
32 import javax.servlet.http.HttpServletRequest JavaDoc;
33 import javax.servlet.http.HttpServletResponse JavaDoc;
34 import java.util.Map JavaDoc;
35
36 public class SetupExpert implements SetupHandler {
37   public String JavaDoc getName() {
38     return "expert";
39   }
40
41   public Map JavaDoc setup(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response, Configuration config, Map JavaDoc errors) {
42     config.setAuth(request.getParameter(Configuration.APP_AUTH));
43     String JavaDoc startSnip = request.getParameter(Configuration.APP_START_SNIP);
44     config.setStartSnip(null == startSnip || "".equals(startSnip) ? "start" : startSnip);
45     config.setPermCreateSnip(allowDeny(request.getParameter(Configuration.APP_PERM_CREATESNIP)));
46     String JavaDoc logger = request.getParameter(Configuration.APP_LOGGER);
47     config.setLogger(logger != null && logger.length() > 0 ? logger : "org.radeox.util.logging.NullLogger");
48     // initalize logger before starting to load configurations
49
try {
50       Logger.setHandler((LogHandler) Class.forName(config.getLogger()).newInstance());
51     } catch (Exception JavaDoc e) {
52       System.err.println("InitFilter: LogHandler not found: " + logger);
53     }
54     String JavaDoc cache = request.getParameter(Configuration.APP_CACHE);
55     config.setCache(cache != null && cache.length() > 0 ? cache : "full");
56     String JavaDoc encoding = request.getParameter(Configuration.APP_ENCODING);
57     config.setEncoding(encoding != null && encoding.length() > 0 ? encoding : "UTF-8");
58
59     return errors;
60   }
61
62   private String JavaDoc allowDeny(String JavaDoc value) {
63     if ("allow".equals(value)) {
64       return value;
65     } else {
66       return "deny";
67     }
68   }
69 }
70
Popular Tags