2 * Copyright (C) 2001, 2002 The Mir-coders group
4 * This file is part of Mir.
6 * Mir is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * Mir is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with Mir; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * In addition, as a special exception, The Mir-coders gives permission to link
21 * the code of this program with any library licensed under the Apache Software License,
22 * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
23 * (or with modified versions of the above that use the same license as the above),
24 * and distribute linked combinations including the two. You must obey the
25 * GNU General Public License in all respects for all of the code used other than
26 * the above mentioned libraries. If you modify this file, you may extend this
27 * exception to your version of the file, but you are not obligated to do so.
28 * If you do not wish to do so, delete this exception statement from your version.
30 package mircoders.servlet;
32 import java.util.HashMap;
\r
33 import java.util.List;
\r
34 import java.util.Map;
\r
35 import java.util.Vector;
\r
36 import javax.servlet.http.HttpServletRequest;
\r
37 import javax.servlet.http.HttpServletResponse;
\r
39 import mir.entity.adapter.EntityAdapter;
\r
40 import mir.log.LoggerWrapper;
\r
41 import mir.servlet.ServletModule;
\r
42 import mir.servlet.ServletModuleExc;
\r
43 import mir.util.StringRoutines;
\r
44 import mircoders.entity.EntityComment;
\r
45 import mircoders.entity.EntityContent;
\r
46 import mircoders.entity.EntityUsers;
\r
47 import mircoders.global.MirGlobal;
\r
48 import mircoders.localizer.MirAdminInterfaceLocalizer;
\r
49 import mircoders.module.ModuleComment;
\r
50 import mircoders.module.ModuleContent;
\r
51 import mircoders.storage.DatabaseComment;
\r
52 import mircoders.storage.DatabaseContent;
54 public class ServletModuleLocalizer extends ServletModule {
55 private static ServletModuleLocalizer instance = new ServletModuleLocalizer();
56 public static ServletModule getInstance() { return instance; }
58 private ModuleContent contentModule;
59 private ModuleComment commentModule;
60 private List administerOperations;
62 private ServletModuleLocalizer() {
64 logger = new LoggerWrapper("ServletModule.Localizer");
66 contentModule = new ModuleContent(DatabaseContent.getInstance());
67 commentModule = new ModuleComment(DatabaseComment.getInstance());
69 administerOperations = new Vector();
71 String settings[] = configuration.getStringArray("Mir.Localizer.Admin.AdministerOperations");
74 for (int i = 0; i < settings.length; i++) {
75 String setting = settings[i].trim();
77 if (setting.length() > 0) {
78 List parts = StringRoutines.splitString(setting, ":");
79 if (parts.size() != 2) {
80 logger.error("config error: " + settings[i] + ", 2 parts expected");
83 Map entry = new HashMap();
84 entry.put("name", (String) parts.get(0));
85 entry.put("url", (String) parts.get(1));
86 administerOperations.add(entry);
93 logger.error("ServletModuleLocalizer could not be initialized: " + e.getMessage());
99 public void performCommentOperation(EntityUsers aUser, String anId, String anOperation) {
100 MirAdminInterfaceLocalizer.MirSimpleEntityOperation operation;
101 EntityAdapter comment;
102 EntityComment entity;
105 entity = (EntityComment) commentModule.getById(anId);
107 if (entity != null) {
108 MirGlobal.performCommentOperation(aUser, entity, anOperation);
109 logger.info("Operation " + anOperation + " successfully performed on comment " + anId);
112 logger.error("Error while performing " + anOperation + " on comment " + anId + ": comment is null");
115 catch (Throwable e) {
116 logger.error("Error while performing " + anOperation + " on comment " + anId + ": " + e.getMessage());
120 public void commentoperation(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc {
121 String commentIdString = aRequest.getParameter("id");
122 String operationString = aRequest.getParameter("operation");
123 String returnUrlString = aRequest.getParameter("returnurl");
125 performCommentOperation(ServletHelper.getUser(aRequest), commentIdString, operationString);
127 redirect(aResponse, returnUrlString);
130 public void commentoperationbatch(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc {
131 String returnUrlString = aRequest.getParameter("returnurl");
133 String[] operations = aRequest.getParameterValues("operation");
135 if (operations!=null) {
136 for (int i = 0; i < operations.length; i++) {
137 if (operations[i].length() > 0) {
138 List parts = StringRoutines.splitString(operations[i], ";");
140 if (parts.size() != 2) {
141 logger.error("commentoperationbatch: operation string invalid: " +
145 String commentIdString = (String) parts.get(0);
146 String operationString = (String) parts.get(1);
148 performCommentOperation(ServletHelper.getUser(aRequest), commentIdString, operationString);
154 redirect(aResponse, returnUrlString);
157 public void performArticleOperation(EntityUsers aUser, String anId, String anOperation) {
158 MirAdminInterfaceLocalizer.MirSimpleEntityOperation operation;
159 EntityAdapter article;
160 EntityContent entity;
163 entity = (EntityContent) contentModule.getById(anId);
165 if (entity != null) {
166 MirGlobal.performArticleOperation(aUser, entity, anOperation);
167 logger.info("Operation " + anOperation + " successfully performed on article " + anId);
170 logger.error("Error while performing " + anOperation + " on article " + anId + ": article is null");
173 catch (Throwable e) {
174 logger.error("Error while performing " + anOperation + " on article " + anId + ": " + e.getMessage());
178 public void articleoperation(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc {
179 String articleIdString = aRequest.getParameter("articleid");
180 String operationString = aRequest.getParameter("operation");
181 String returnUrlString = aRequest.getParameter("returnurl");
183 performArticleOperation(ServletHelper.getUser(aRequest), articleIdString, operationString);
184 redirect(aResponse, returnUrlString);
187 public void articleoperationbatch(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc {
188 String returnUrlString = aRequest.getParameter("returnurl");
190 String[] operations = aRequest.getParameterValues("operation");
192 if (operations!=null) {
194 for (int i = 0; i < operations.length; i++) {
195 if (operations[i].length() > 0) {
196 List parts = StringRoutines.splitString(operations[i], ";");
198 if (parts.size() != 2) {
199 logger.error("articleoperationbatch: operation string invalid: " + operations[i]);
202 String articleIdString = (String) parts.get(0);
203 String operationString = (String) parts.get(1);
205 performArticleOperation(ServletHelper.getUser(aRequest), articleIdString, operationString);
211 redirect(aResponse, returnUrlString);
214 public List getAdministerOperations() throws ServletModuleExc {
215 return administerOperations;