2 * Copyright (C) 2001, 2002 The Mir-coders group
\r
4 * This file is part of Mir.
\r
6 * Mir is free software; you can redistribute it and/or modify
\r
7 * it under the terms of the GNU General Public License as published by
\r
8 * the Free Software Foundation; either version 2 of the License, or
\r
9 * (at your option) any later version.
\r
11 * Mir is distributed in the hope that it will be useful,
\r
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 * GNU General Public License for more details.
\r
16 * You should have received a copy of the GNU General Public License
\r
17 * along with Mir; if not, write to the Free Software
\r
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
20 * In addition, as a special exception, The Mir-coders gives permission to link
\r
21 * the code of this program with the com.oreilly.servlet library, any library
\r
22 * licensed under the Apache Software License, The Sun (tm) Java Advanced
\r
23 * Imaging library (JAI), The Sun JIMI library (or with modified versions of
\r
24 * the above that use the same license as the above), and distribute linked
\r
25 * combinations including the two. You must obey the GNU General Public
\r
26 * License in all respects for all of the code used other than the above
\r
27 * mentioned libraries. If you modify this file, you may extend this exception
\r
28 * to your version of the file, but you are not obligated to do so. If you do
\r
29 * not wish to do so, delete this exception statement from your version.
\r
32 package mircoders.servlet;
\r
34 import java.util.List;
\r
36 import javax.servlet.http.HttpServletRequest;
\r
37 import javax.servlet.http.HttpServletResponse;
\r
38 import javax.servlet.http.HttpSession;
\r
40 import mir.entity.adapter.EntityAdapter;
\r
41 import mir.log.LoggerWrapper;
\r
42 import mir.servlet.ServletModule;
\r
43 import mir.servlet.ServletModuleExc;
\r
44 import mir.servlet.ServletModuleFailure;
\r
45 import mir.util.StringRoutines;
\r
46 import mircoders.entity.EntityComment;
\r
47 import mircoders.entity.EntityContent;
\r
48 import mircoders.entity.EntityUsers;
\r
49 import mircoders.global.MirGlobal;
\r
50 import mircoders.localizer.MirAdminInterfaceLocalizer;
\r
51 import mircoders.module.ModuleComment;
\r
52 import mircoders.module.ModuleContent;
\r
53 import mircoders.storage.DatabaseComment;
\r
54 import mircoders.storage.DatabaseContent;
\r
56 public class ServletModuleLocalizer extends ServletModule {
\r
57 private static ServletModuleLocalizer instance = new ServletModuleLocalizer();
\r
58 public static ServletModule getInstance() { return instance; }
\r
60 private ModuleContent contentModule;
\r
61 private ModuleComment commentModule;
\r
63 private ServletModuleLocalizer() {
\r
65 contentModule = new ModuleContent(DatabaseContent.getInstance());
\r
66 commentModule = new ModuleComment(DatabaseComment.getInstance());
\r
68 logger = new LoggerWrapper("ServletModule.Localizer");
\r
70 catch (Exception e) {
\r
71 logger.error("ServletModuleLocalizer could not be initialized: " + e.getMessage());
\r
75 private EntityAdapter getActiveUser(HttpServletRequest aRequest) throws ServletModuleExc {
\r
77 HttpSession session = aRequest.getSession(false);
\r
78 return MirGlobal.localizer().dataModel().adapterModel().makeEntityAdapter
\r
79 ("user", (EntityUsers) session.getAttribute("login.uid"));
\r
81 catch (Throwable e) {
\r
82 throw new ServletModuleFailure("ServletModuleLocalizer.getActiveUser: " + e.getMessage(), e);
\r
86 public void performCommentOperation(EntityAdapter aUser, String anId, String anOperation) {
\r
87 MirAdminInterfaceLocalizer.MirSimpleEntityOperation operation;
\r
88 EntityAdapter comment;
\r
89 EntityComment entity;
\r
92 entity = (EntityComment) commentModule.getById(anId);
\r
94 if (entity != null) {
\r
95 comment = MirGlobal.localizer().dataModel().adapterModel().makeEntityAdapter("comment", entity);
\r
96 operation = MirGlobal.localizer().adminInterface().simpleCommentOperationForName(anOperation);
\r
97 operation.perform(aUser, comment);
\r
98 logger.info("Operation " + anOperation + " successfully performed on comment " + anId);
\r
100 logger.error("Error while performing " + anOperation + " on comment " + anId + ": comment is null");
\r
102 catch (Throwable e) {
\r
103 logger.error("Error while performing " + anOperation + " on comment " + anId + ": " + e.getMessage());
\r
107 public void commentoperation(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc {
\r
108 String commentIdString = aRequest.getParameter("id");
\r
109 String operationString = aRequest.getParameter("operation");
\r
110 String returnUrlString = aRequest.getParameter("returnurl");
\r
112 performCommentOperation(getActiveUser(aRequest), commentIdString, operationString);
\r
114 redirect(aResponse, returnUrlString);
\r
117 public void commentoperationbatch(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc {
\r
118 String returnUrlString = aRequest.getParameter("returnurl");
\r
120 String[] operations = aRequest.getParameterValues("operation");
\r
122 for (int i=0; i<operations.length; i++) {
\r
123 if (operations[i].length()>0) {
\r
124 List parts = StringRoutines.splitString(operations[i], ";");
\r
126 if (parts.size() != 2) {
\r
127 logger.error("commentoperationbatch: operation string invalid: " +
\r
131 String commentIdString = (String) parts.get(0);
\r
132 String operationString = (String) parts.get(1);
\r
134 performCommentOperation(getActiveUser(aRequest), commentIdString, operationString);
\r
139 redirect(aResponse, returnUrlString);
\r
142 public void performArticleOperation(EntityAdapter aUser, String anId, String anOperation) {
\r
143 MirAdminInterfaceLocalizer.MirSimpleEntityOperation operation;
\r
144 EntityAdapter article;
\r
145 EntityContent entity;
\r
148 entity = (EntityContent) contentModule.getById(anId);
\r
150 if (entity != null) {
\r
151 article = MirGlobal.localizer().dataModel().adapterModel().
\r
152 makeEntityAdapter("content", entity);
\r
153 operation = MirGlobal.localizer().adminInterface().
\r
154 simpleArticleOperationForName(anOperation);
\r
155 operation.perform(aUser, article);
\r
156 logger.info("Operation " + anOperation + " successfully performed on article " + anId);
\r
158 logger.error("Error while performing " + anOperation + " on article " + anId + ": article is null");
\r
160 catch (Throwable e) {
\r
161 logger.error("Error while performing " + anOperation + " on article " + anId + ": " + e.getMessage());
\r
165 public void articleoperation(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc {
\r
166 String articleIdString = aRequest.getParameter("articleid");
\r
167 String operationString = aRequest.getParameter("operation");
\r
168 String returnUrlString = aRequest.getParameter("returnurl");
\r
170 performArticleOperation(getActiveUser(aRequest), articleIdString, operationString);
\r
171 redirect(aResponse, returnUrlString);
\r
174 public void articleoperationbatch(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc {
\r
175 String returnUrlString = aRequest.getParameter("returnurl");
\r
177 String[] operations = aRequest.getParameterValues("operation");
\r
179 for (int i=0; i<operations.length; i++) {
\r
180 if (operations[i].length()>0) {
\r
181 List parts = StringRoutines.splitString(operations[i], ";");
\r
183 if (parts.size() != 2) {
\r
184 logger.error("articleoperationbatch: operation string invalid: " +
\r
188 String articleIdString = (String) parts.get(0);
\r
189 String operationString = (String) parts.get(1);
\r
191 performArticleOperation(getActiveUser(aRequest), articleIdString, operationString);
\r
196 redirect(aResponse, returnUrlString);
\r