/*
- * Copyright (C) 2001, 2002 The Mir-coders group
+ * Copyright (C) 2001, 2002 The Mir-coders group
*
* This file is part of Mir.
*
* 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.
+ * the code of this program with 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.*;
+import mir.servlet.AdminServletModule;
+import mir.servlet.ServletModuleExc;
+import mir.util.StringRoutines;
+import mircoders.entity.EntityComment;
+import mircoders.entity.EntityContent;
+import mircoders.global.MirGlobal;
+import mircoders.module.ModuleComment;
+import mircoders.module.ModuleContent;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class ServletModuleLocalizer extends AdminServletModule {
+ private final ModuleContent contentModule = new ModuleContent();
+ private final ModuleComment commentModule = new ModuleComment();
+ private final List administerOperations = new ArrayList();
+
+ public ServletModuleLocalizer() {
+ try {
+ String settings[] =
+ getConfiguration().getStringArray("Mir.Localizer.Admin.AdministerOperations");
+
+ if (settings!=null) {
+ for (int i = 0; i < settings.length; i++) {
+ String setting = settings[i].trim();
+
+ if (setting.length() > 0) {
+ List parts = StringRoutines.splitString(setting, ":");
+ if (parts.size() != 2) {
+ getLogger().error("config error: " + settings[i] + ", 2 parts expected");
+ }
+ else {
+ Map entry = new HashMap();
+ entry.put("name", parts.get(0));
+ entry.put("url", parts.get(1));
+ administerOperations.add(entry);
+ }
+ }
+ }
+ }
+ }
+ catch (Exception e) {
+ getLogger().error("ServletModuleLocalizer could not be initialized" + e.getMessage(), e);
+ }
+ }
-import javax.servlet.*;
-import javax.servlet.http.*;
+ /**
+ * Performs a localizer operation on an article.
+ *
+ * See also
+ * {@link mircoders.localizer.MirAdminInterfaceLocalizer#simpleArticleOperations()}
+ *
+ * @param aRequest The originating request
+ * @param anId The id of the article
+ * @param anOperation The identifier of the operation to perform
+ */
+ public void performCommentOperation(HttpServletRequest aRequest, String anId, String anOperation) {
+ try {
+ EntityComment entity = (EntityComment) commentModule.getById(anId);
-import mir.servlet.*;
-import mir.entity.adapter.*;
-import mir.log.*;
+ if (entity != null) {
+ MirGlobal.performCommentOperation(ServletHelper.getUser(aRequest), entity, anOperation);
+ getLogger().debug("Operation " + anOperation + " successfully performed on comment " + anId);
+ logAdminUsage(aRequest, "comment."+anId, "operation " + anOperation + " performed");
+ }
+ else {
+ getLogger().error("Error while performing " + anOperation + " on comment " + anId + ": comment is null");
+ }
+ }
+ catch (Throwable e) {
+ getLogger().error("Error while performing " + anOperation + " on comment " + anId + ": " + e.getMessage(), e);
+ }
+ }
-import mircoders.global.*;
-import mircoders.localizer.*;
-import mircoders.storage.*;
-import mircoders.entity.*;
-import mircoders.module.*;
+ public void commentoperation(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc {
+ String commentIdString = aRequest.getParameter("id");
+ String operationString = aRequest.getParameter("operation");
+ String returnUrlString = aRequest.getParameter("returnurl");
-public class ServletModuleLocalizer extends ServletModule {
- private static ServletModuleLocalizer instance = new ServletModuleLocalizer();
- public static ServletModule getInstance() { return instance; }
+ performCommentOperation(aRequest, commentIdString, operationString);
- private ModuleContent contentModule;
- private ModuleComment commentModule;
+ ServletHelper.redirect(aResponse, returnUrlString);
+ }
- private ServletModuleLocalizer() {
- try {
- contentModule = new ModuleContent(DatabaseContent.getInstance());
- commentModule = new ModuleComment(DatabaseComment.getInstance());
+ public void operation(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc {
+ String type = aRequest.getParameter("objecttype");
+ String id = aRequest.getParameter("id");
+ String operation = aRequest.getParameter("operation");
+ String returnUrl = aRequest.getParameter("returnurl");
- logger = new LoggerWrapper("ServletModule.Localizer");
+
+ if ("comment".equals(type)) {
+ performCommentOperation(aRequest, id, operation);
}
- catch (Exception e) {
- logger.error("ServletModuleLocalizer could not be initialized: " + e.getMessage());
+ else {
+ performArticleOperation(aRequest, id, operation);
}
+
+ ServletHelper.redirect(aResponse, returnUrl);
}
- public void commentoperation(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleException {
- String idString = aRequest.getParameter("id");
- String operationString = aRequest.getParameter("operation");
+ public void commentoperationbatch(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc {
String returnUrlString = aRequest.getParameter("returnurl");
- MirAdminInterfaceLocalizer.MirSimpleEntityOperation operation;
- EntityAdapter comment;
- EntityComment entity;
+ String[] operations = aRequest.getParameterValues("operation");
- try {
- entity = (EntityComment) commentModule.getById(idString);
+ if (operations!=null) {
+ for (int i = 0; i < operations.length; i++) {
+ if (operations[i].length() > 0) {
+ List parts = StringRoutines.splitString(operations[i], ";");
- if (entity!=null) {
- comment = MirGlobal.localizer().dataModel().adapterModel().makeEntityAdapter("comment", entity);
- operation = MirGlobal.localizer().adminInterface().simpleCommentOperationForName(operationString);
- operation.perform(comment);
- }
+ if (parts.size() != 2) {
+ getLogger().error("commentoperationbatch: operation string invalid: " +
+ operations[i]);
+ }
+ else {
+ String commentIdString = (String) parts.get(0);
+ String operationString = (String) parts.get(1);
- redirect(aResponse, returnUrlString);
- }
- catch (Throwable e) {
- e.printStackTrace(System.out);
- throw new ServletModuleException(e.getMessage());
+ performCommentOperation(aRequest, commentIdString, operationString);
+ }
+ }
+ }
}
+
+ ServletHelper.redirect(aResponse, returnUrlString);
}
- public void articleoperation(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleException {
- String articleIdString = aRequest.getParameter("articleid");
- String operationString = aRequest.getParameter("operation");
+ public void operationbatch(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc {
String returnUrlString = aRequest.getParameter("returnurl");
- MirAdminInterfaceLocalizer.MirSimpleEntityOperation operation;
- EntityAdapter article;
+ String[] operations = aRequest.getParameterValues("operation");
+
+ if (operations!=null) {
+ for (int i = 0; i < operations.length; i++) {
+ if (operations[i].length() > 0) {
+ List parts = StringRoutines.splitString(operations[i], ";");
+
+ if (parts.size() != 3) {
+ getLogger().error("commentoperationbatch: operation string invalid: " +
+ operations[i]);
+ }
+ else {
+ String type = (String) parts.get(0);
+ String id = (String) parts.get(1);
+ String operationString = (String) parts.get(2);
+
+ if ("comment".equals(type)) {
+ performCommentOperation(aRequest, id, operationString);
+ }
+ else {
+ performArticleOperation(aRequest, id, operationString);
+ }
+ }
+ }
+ }
+ }
+
+ ServletHelper.redirect(aResponse, returnUrlString);
+ }
+ public void performArticleOperation(HttpServletRequest aRequest, String anId, String anOperation) {
EntityContent entity;
try {
- entity = (EntityContent) contentModule.getById(articleIdString);
+ entity = (EntityContent) contentModule.getById(anId);
- if (entity!=null) {
- article = MirGlobal.localizer().dataModel().adapterModel().makeEntityAdapter("content", entity);
- operation = MirGlobal.localizer().adminInterface().simpleArticleOperationForName(operationString);
- operation.perform(article);
+ if (entity != null) {
+ MirGlobal.performArticleOperation(ServletHelper.getUser(aRequest), entity, anOperation);
+ getLogger().info("Operation " + anOperation + " successfully performed on article " + anId);
+ logAdminUsage(aRequest, "article." + anId, "operation " + anOperation + " performed");
+ }
+ else {
+ getLogger().error("Error while performing " + anOperation + " on article " + anId + ": article is null");
}
-
- redirect(aResponse, returnUrlString);
}
catch (Throwable e) {
- e.printStackTrace(System.out);
- throw new ServletModuleException(e.getMessage());
+ getLogger().error("Error while performing " + anOperation + " on article " + anId + ": " + e.getMessage());
}
}
+ public void articleoperation(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc {
+ String articleIdString = aRequest.getParameter("articleid");
+ String operationString = aRequest.getParameter("operation");
+ String returnUrlString = aRequest.getParameter("returnurl");
+
+ performArticleOperation(aRequest, articleIdString, operationString);
+ ServletHelper.redirect(aResponse, returnUrlString);
+ }
+
+ public void articleoperationbatch(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc {
+ String returnUrlString = aRequest.getParameter("returnurl");
+
+ String[] operations = aRequest.getParameterValues("operation");
+
+ if (operations!=null) {
+
+ for (int i = 0; i < operations.length; i++) {
+ if (operations[i].length() > 0) {
+ List parts = StringRoutines.splitString(operations[i], ";");
+
+ if (parts.size() != 2) {
+ getLogger().error("articleoperationbatch: operation string invalid: " + operations[i]);
+ }
+ else {
+ String articleIdString = (String) parts.get(0);
+ String operationString = (String) parts.get(1);
+ performArticleOperation(aRequest, articleIdString, operationString);
+ }
+ }
+ }
+ }
+
+ ServletHelper.redirect(aResponse, returnUrlString);
+ }
+
+ public List getAdministerOperations() throws ServletModuleExc {
+ return administerOperations;
+ }
}
\ No newline at end of file