-/*\r
- * Copyright (C) 2001, 2002 The Mir-coders group\r
- *\r
- * This file is part of Mir.\r
- *\r
- * Mir is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 2 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * Mir is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with Mir; if not, write to the Free Software\r
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
- *\r
- * In addition, as a special exception, The Mir-coders gives permission to link\r
- * the code of this program with the com.oreilly.servlet library, any library\r
- * licensed under the Apache Software License, The Sun (tm) Java Advanced\r
- * Imaging library (JAI), The Sun JIMI library (or with modified versions of\r
- * the above that use the same license as the above), and distribute linked\r
- * combinations including the two. You must obey the GNU General Public\r
- * License in all respects for all of the code used other than the above\r
- * mentioned libraries. If you modify this file, you may extend this exception\r
- * to your version of the file, but you are not obligated to do so. If you do\r
- * not wish to do so, delete this exception statement from your version.\r
- */\r
-\r
-package mircoders.servlet;\r
-\r
-import java.util.Map;\r
-\r
-import javax.servlet.http.HttpServletRequest;\r
-import javax.servlet.http.HttpServletResponse;\r
-\r
-import mir.log.LoggerWrapper;\r
-import mir.module.ModuleException;\r
-import mir.servlet.*;\r
-import mir.storage.StorageObjectFailure;\r
-import mir.util.HTTPRequestParser;\r
-import mircoders.module.ModuleUsers;\r
-import mircoders.storage.DatabaseUsers;\r
-import freemarker.template.SimpleHash;\r
-\r
-/*\r
- * ServletModuleUsers -\r
- * liefert HTML fuer Users\r
- *\r
- *\r
- * @author RK\r
- */\r
-\r
-public class ServletModuleUsers extends ServletModule\r
-{\r
- private static ServletModuleUsers instance = new ServletModuleUsers();\r
- public static ServletModule getInstance() { return instance; }\r
-\r
- private ServletModuleUsers() {\r
- super();\r
- logger = new LoggerWrapper("ServletModule.Users");\r
-\r
- templateListString = configuration.getString("ServletModule.Users.ListTemplate");\r
- templateObjektString = configuration.getString("ServletModule.Users.ObjektTemplate");\r
- templateConfirmString = configuration.getString("ServletModule.Users.ConfirmTemplate");\r
-\r
- try {\r
- mainModule = new ModuleUsers(DatabaseUsers.getInstance());\r
- }\r
- catch (StorageObjectFailure e) {\r
- logger.debug("initialization of ServletModuleUsers failed!: " + e.getMessage());\r
- }\r
- }\r
-\r
- public void edit(HttpServletRequest req, HttpServletResponse res) throws ServletModuleExc\r
- {\r
- String idParam = req.getParameter("id");\r
-\r
- if (idParam == null)\r
- throw new ServletModuleExc("ServletModuleUser.edit: invalid call: (id) not specified");\r
-\r
- try {\r
- deliver(req, res, mainModule.getById(idParam), templateObjektString);\r
- }\r
- catch (Throwable e) {\r
- throw new ServletModuleFailure(e);\r
- }\r
- }\r
-\r
- public void add(HttpServletRequest req, HttpServletResponse res)\r
- throws ServletModuleExc\r
- {\r
- try {\r
- SimpleHash mergeData = new SimpleHash();\r
- mergeData.put("new", "1");\r
- deliver(req, res, mergeData, templateObjektString);\r
- }\r
- catch (Throwable e) {\r
- throw new ServletModuleFailure(e);\r
- }\r
- }\r
-\r
- public String checkPassword(HTTPRequestParser aRequestParser) throws ServletModuleExc, ServletModuleUserExc, ServletModuleFailure\r
- {\r
- if ( (aRequestParser.getParameter("newpassword") != null &&\r
- aRequestParser.getParameter("newpassword").length() > 0) ||\r
- (aRequestParser.getParameter("newpassword2") != null &&\r
- aRequestParser.getParameter("newpassword2").length() > 0)\r
- ) {\r
- String newPassword = aRequestParser.getParameterWithDefault("newpassword", "");\r
- String newPassword2 = aRequestParser.getParameterWithDefault("newpassword2", "");\r
-\r
- if (newPassword.length() == 0 || newPassword2.length() == 0) {\r
- throw new ServletModuleUserExc("The new password must be entered twice!");\r
- }\r
-\r
- if (!newPassword.equals(newPassword2)) {\r
- throw new ServletModuleUserExc("New password differes from confirmation");\r
- }\r
-\r
- return newPassword;\r
- }\r
- else\r
- return null;\r
- }\r
-\r
- public void insert(HttpServletRequest aRequest, HttpServletResponse aResponse)\r
- throws ServletModuleExc, ServletModuleUserExc, ServletModuleFailure\r
- {\r
- try {\r
- HTTPRequestParser requestParser = new HTTPRequestParser(aRequest);\r
- Map withValues = getIntersectingValues(aRequest, mainModule.getStorageObject());\r
-\r
- String newPassword=checkPassword(requestParser);\r
- if (newPassword!=null)\r
- withValues.put("password", newPassword);\r
- else\r
- throw new ServletModuleUserExc("Password is empty");\r
-\r
- String id = mainModule.add(withValues);\r
- if (requestParser.hasParameter("returnurl"))\r
- redirect(aResponse, requestParser.getParameter("returnurl"));\r
- else\r
- list(aRequest, aResponse);\r
- }\r
- catch (Throwable e) {\r
- throw new ServletModuleFailure(e);\r
- }\r
- }\r
-\r
- public void update(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc, ServletModuleUserExc, ServletModuleFailure\r
- {\r
- try {\r
- HTTPRequestParser requestParser = new HTTPRequestParser(aRequest);\r
-\r
- Map withValues = getIntersectingValues(aRequest, mainModule.getStorageObject());\r
-\r
- String newPassword=checkPassword(requestParser);\r
- if (newPassword!=null)\r
- withValues.put("password", newPassword);\r
-\r
- mainModule.set(withValues);\r
-\r
- if (requestParser.hasParameter("returnurl"))\r
- redirect(aResponse, requestParser.getParameter("returnurl"));\r
- else\r
- list(aRequest, aResponse);\r
- }\r
- catch (Throwable e) {\r
- throw new ServletModuleFailure(e);\r
- }\r
- }\r
-\r
-\r
-}\r
+/*
+ * Copyright (C) 2001, 2002 The Mir-coders group
+ *
+ * This file is part of Mir.
+ *
+ * Mir is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Mir is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Mir; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * In addition, as a special exception, The Mir-coders gives permission to link
+ * the code of this program with the com.oreilly.servlet library, any library
+ * licensed under the Apache Software License, The Sun (tm) Java Advanced
+ * Imaging library (JAI), The Sun JIMI library (or with modified versions of
+ * the above that use the same license as the above), and distribute linked
+ * combinations including the two. You must obey the GNU General Public
+ * License in all respects for all of the code used other than the above
+ * mentioned libraries. If you modify this file, you may extend this exception
+ * to your version of the file, but you are not obligated to do so. If you do
+ * not wish to do so, delete this exception statement from your version.
+ */
+
+package mircoders.servlet;
+
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import mir.log.LoggerWrapper;
+import mir.servlet.ServletModule;
+import mir.servlet.ServletModuleExc;
+import mir.servlet.ServletModuleFailure;
+import mir.servlet.ServletModuleUserExc;
+import mir.storage.StorageObjectFailure;
+import mir.util.HTTPRequestParser;
+import mircoders.module.ModuleUsers;
+import mircoders.storage.DatabaseUsers;
+import freemarker.template.SimpleHash;
+
+/*
+ * ServletModuleUsers -
+ * liefert HTML fuer Users
+ *
+ *
+ * @author RK
+ */
+
+public class ServletModuleUsers extends ServletModule
+{
+ private static ServletModuleUsers instance = new ServletModuleUsers();
+ public static ServletModule getInstance() { return instance; }
+
+ private ServletModuleUsers() {
+ super();
+ logger = new LoggerWrapper("ServletModule.Users");
+
+ templateListString = configuration.getString("ServletModule.Users.ListTemplate");
+ templateObjektString = configuration.getString("ServletModule.Users.ObjektTemplate");
+ templateConfirmString = configuration.getString("ServletModule.Users.ConfirmTemplate");
+
+ try {
+ mainModule = new ModuleUsers(DatabaseUsers.getInstance());
+ }
+ catch (StorageObjectFailure e) {
+ logger.debug("initialization of ServletModuleUsers failed!: " + e.getMessage());
+ }
+ }
+
+ public void edit(HttpServletRequest req, HttpServletResponse res) throws ServletModuleExc
+ {
+ String idParam = req.getParameter("id");
+
+ if (idParam == null)
+ throw new ServletModuleExc("ServletModuleUser.edit: invalid call: (id) not specified");
+
+ try {
+ deliver(req, res, mainModule.getById(idParam), templateObjektString);
+ }
+ catch (Throwable e) {
+ throw new ServletModuleFailure(e);
+ }
+ }
+
+ public void add(HttpServletRequest req, HttpServletResponse res)
+ throws ServletModuleExc
+ {
+ try {
+ SimpleHash mergeData = new SimpleHash();
+ mergeData.put("new", "1");
+ deliver(req, res, mergeData, templateObjektString);
+ }
+ catch (Throwable e) {
+ throw new ServletModuleFailure(e);
+ }
+ }
+
+ public String checkPassword(HTTPRequestParser aRequestParser) throws ServletModuleExc, ServletModuleUserExc, ServletModuleFailure
+ {
+ if ( (aRequestParser.getParameter("newpassword") != null &&
+ aRequestParser.getParameter("newpassword").length() > 0) ||
+ (aRequestParser.getParameter("newpassword2") != null &&
+ aRequestParser.getParameter("newpassword2").length() > 0)
+ ) {
+ String newPassword = aRequestParser.getParameterWithDefault("newpassword", "");
+ String newPassword2 = aRequestParser.getParameterWithDefault("newpassword2", "");
+
+ if (newPassword.length() == 0 || newPassword2.length() == 0) {
+ throw new ServletModuleUserExc("The new password must be entered twice!");
+ }
+
+ if (!newPassword.equals(newPassword2)) {
+ throw new ServletModuleUserExc("New password differes from confirmation");
+ }
+
+ return newPassword;
+ }
+ else
+ return null;
+ }
+
+ public void insert(HttpServletRequest aRequest, HttpServletResponse aResponse)
+ throws ServletModuleExc, ServletModuleUserExc, ServletModuleFailure
+ {
+ try {
+ HTTPRequestParser requestParser = new HTTPRequestParser(aRequest);
+ Map withValues = getIntersectingValues(aRequest, mainModule.getStorageObject());
+
+ String newPassword=checkPassword(requestParser);
+ if (newPassword!=null)
+ withValues.put("password", newPassword);
+ else
+ throw new ServletModuleUserExc("Password is empty");
+
+ String id = mainModule.add(withValues);
+ if (requestParser.hasParameter("returnurl"))
+ redirect(aResponse, requestParser.getParameter("returnurl"));
+ else
+ list(aRequest, aResponse);
+ }
+ catch (Throwable e) {
+ throw new ServletModuleFailure(e);
+ }
+ }
+
+ public void update(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc, ServletModuleUserExc, ServletModuleFailure
+ {
+ try {
+ HTTPRequestParser requestParser = new HTTPRequestParser(aRequest);
+
+ Map withValues = getIntersectingValues(aRequest, mainModule.getStorageObject());
+
+ String newPassword=checkPassword(requestParser);
+ if (newPassword!=null)
+ withValues.put("password", newPassword);
+
+ mainModule.set(withValues);
+
+ if (requestParser.hasParameter("returnurl"))
+ redirect(aResponse, requestParser.getParameter("returnurl"));
+ else
+ list(aRequest, aResponse);
+ }
+ catch (Throwable e) {
+ throw new ServletModuleFailure(e);
+ }
+ }
+
+
+}