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
36 import javax.servlet.*;
\r
37 import javax.servlet.http.*;
\r
39 import mir.servlet.*;
\r
40 import mir.entity.adapter.*;
\r
44 import mircoders.global.*;
\r
45 import mircoders.localizer.*;
\r
46 import mircoders.storage.*;
\r
47 import mircoders.entity.*;
\r
48 import mircoders.module.*;
\r
50 public class ServletModuleLocalizer extends ServletModule {
\r
51 private static ServletModuleLocalizer instance = new ServletModuleLocalizer();
\r
52 public static ServletModule getInstance() { return instance; }
\r
54 private ModuleContent contentModule;
\r
55 private ModuleComment commentModule;
\r
57 private ServletModuleLocalizer() {
\r
59 contentModule = new ModuleContent(DatabaseContent.getInstance());
\r
60 commentModule = new ModuleComment(DatabaseComment.getInstance());
\r
62 logger = new LoggerWrapper("ServletModule.Localizer");
\r
64 catch (Exception e) {
\r
65 logger.error("ServletModuleLocalizer could not be initialized: " + e.getMessage());
\r
69 private EntityAdapter getActiveUser(HttpServletRequest aRequest) throws ServletModuleException {
\r
71 HttpSession session = aRequest.getSession(false);
\r
72 return MirGlobal.localizer().dataModel().adapterModel().makeEntityAdapter
\r
73 ("user", (EntityUsers) session.getAttribute("login.uid"));
\r
75 catch (Exception e) {
\r
76 throw new ServletModuleException("ServletModuleLocalizer.getActiveUser: " + e.getMessage());
\r
80 public void performCommentOperation(EntityAdapter aUser, String anId, String anOperation) {
\r
81 MirAdminInterfaceLocalizer.MirSimpleEntityOperation operation;
\r
82 EntityAdapter comment;
\r
83 EntityComment entity;
\r
86 entity = (EntityComment) commentModule.getById(anId);
\r
88 if (entity != null) {
\r
89 comment = MirGlobal.localizer().dataModel().adapterModel().makeEntityAdapter("comment", entity);
\r
90 operation = MirGlobal.localizer().adminInterface().simpleCommentOperationForName(anOperation);
\r
91 operation.perform(aUser, comment);
\r
92 logger.info("Operation " + anOperation + " successfully performed on comment " + anId);
\r
94 logger.error("Error while performing " + anOperation + " on comment " + anId + ": comment is null");
\r
96 catch (Throwable e) {
\r
97 logger.error("Error while performing " + anOperation + " on comment " + anId + ": " + e.getMessage());
\r
101 public void commentoperation(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleException {
\r
102 String commentIdString = aRequest.getParameter("id");
\r
103 String operationString = aRequest.getParameter("operation");
\r
104 String returnUrlString = aRequest.getParameter("returnurl");
\r
106 performCommentOperation(getActiveUser(aRequest), commentIdString, operationString);
\r
108 redirect(aResponse, returnUrlString);
\r
111 public void commentoperationbatch(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleException {
\r
112 String returnUrlString = aRequest.getParameter("returnurl");
\r
114 String[] operations = aRequest.getParameterValues("operation");
\r
116 for (int i=0; i<operations.length; i++) {
\r
117 if (operations[i].length()>0) {
\r
118 List parts = StringRoutines.splitString(operations[i], ";");
\r
120 if (parts.size() != 2) {
\r
121 logger.error("commentoperationbatch: operation string invalid: " +
\r
125 String commentIdString = (String) parts.get(0);
\r
126 String operationString = (String) parts.get(1);
\r
128 performCommentOperation(getActiveUser(aRequest), commentIdString, operationString);
\r
133 redirect(aResponse, returnUrlString);
\r
136 public void performArticleOperation(EntityAdapter aUser, String anId, String anOperation) {
\r
137 MirAdminInterfaceLocalizer.MirSimpleEntityOperation operation;
\r
138 EntityAdapter article;
\r
139 EntityContent entity;
\r
142 entity = (EntityContent) contentModule.getById(anId);
\r
144 if (entity != null) {
\r
145 article = MirGlobal.localizer().dataModel().adapterModel().
\r
146 makeEntityAdapter("content", entity);
\r
147 operation = MirGlobal.localizer().adminInterface().
\r
148 simpleArticleOperationForName(anOperation);
\r
149 operation.perform(aUser, article);
\r
150 logger.info("Operation " + anOperation + " successfully performed on article " + anId);
\r
152 logger.error("Error while performing " + anOperation + " on article " + anId + ": article is null");
\r
154 catch (Throwable e) {
\r
155 logger.error("Error while performing " + anOperation + " on article " + anId + ": " + e.getMessage());
\r
159 public void articleoperation(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleException {
\r
160 String articleIdString = aRequest.getParameter("articleid");
\r
161 String operationString = aRequest.getParameter("operation");
\r
162 String returnUrlString = aRequest.getParameter("returnurl");
\r
164 performArticleOperation(getActiveUser(aRequest), articleIdString, operationString);
\r
165 redirect(aResponse, returnUrlString);
\r
168 public void articleoperationbatch(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleException {
\r
169 String returnUrlString = aRequest.getParameter("returnurl");
\r
171 String[] operations = aRequest.getParameterValues("operation");
\r
173 for (int i=0; i<operations.length; i++) {
\r
174 if (operations[i].length()>0) {
\r
175 List parts = StringRoutines.splitString(operations[i], ";");
\r
177 if (parts.size() != 2) {
\r
178 logger.error("articleoperationbatch: operation string invalid: " +
\r
182 String articleIdString = (String) parts.get(0);
\r
183 String operationString = (String) parts.get(1);
\r
185 performArticleOperation(getActiveUser(aRequest), articleIdString, operationString);
\r
190 redirect(aResponse, returnUrlString);
\r