X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=source%2Fmircoders%2Fservlet%2FServletModuleLocalizer.java;h=1967049423d287539b587d415dc0ba82c84a3863;hb=bbe62929488956ca72b03268ce290b562acf08b4;hp=582334f8d7f16bfac4632d82322e8b05370f1945;hpb=213122e7c65211f549722f05aa8e0135f15af35c;p=mir.git diff --git a/source/mircoders/servlet/ServletModuleLocalizer.java b/source/mircoders/servlet/ServletModuleLocalizer.java index 582334f8..19670494 100755 --- a/source/mircoders/servlet/ServletModuleLocalizer.java +++ b/source/mircoders/servlet/ServletModuleLocalizer.java @@ -29,8 +29,7 @@ */ package mircoders.servlet; -import mir.log.LoggerWrapper; -import mir.servlet.ServletModule; +import mir.servlet.AdminServletModule; import mir.servlet.ServletModuleExc; import mir.util.StringRoutines; import mircoders.entity.EntityComment; @@ -41,35 +40,29 @@ import mircoders.module.ModuleContent; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; -public class ServletModuleLocalizer extends ServletModule { - private static ServletModuleLocalizer instance = new ServletModuleLocalizer(); - public static ServletModule getInstance() { return instance; } +public class ServletModuleLocalizer extends AdminServletModule { + private final ModuleContent contentModule = new ModuleContent(); + private final ModuleComment commentModule = new ModuleComment(); + private final List administerOperations = new ArrayList(); - private ModuleContent contentModule; - private ModuleComment commentModule; - private List administerOperations; - - private ServletModuleLocalizer() { + public ServletModuleLocalizer() { try { - logger = new LoggerWrapper("ServletModule.Localizer"); - - contentModule = new ModuleContent(); - commentModule = new ModuleComment(); - - administerOperations = new ArrayList(); - - String settings[] = configuration.getStringArray("Mir.Localizer.Admin.AdministerOperations"); + 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, ":"); + List parts = StringRoutines.splitStringWithEscape(setting, ':', '\\'); if (parts.size() != 2) { - logger.error("config error: " + settings[i] + ", 2 parts expected"); + getLogger().error("config error: " + settings[i] + ", 2 parts expected"); } else { Map entry = new HashMap(); @@ -82,7 +75,7 @@ public class ServletModuleLocalizer extends ServletModule { } } catch (Exception e) { - logger.error("ServletModuleLocalizer could not be initialized: " + e.getMessage()); + getLogger().error("ServletModuleLocalizer could not be initialized" + e.getMessage(), e); } } @@ -97,22 +90,20 @@ public class ServletModuleLocalizer extends ServletModule { * @param anOperation The identifier of the operation to perform */ public void performCommentOperation(HttpServletRequest aRequest, String anId, String anOperation) { - EntityComment entity; - try { - entity = (EntityComment) commentModule.getById(anId); + EntityComment entity = (EntityComment) commentModule.getById(anId); if (entity != null) { MirGlobal.performCommentOperation(ServletHelper.getUser(aRequest), entity, anOperation); - logger.info("Operation " + anOperation + " successfully performed on comment " + anId); + getLogger().debug("Operation " + anOperation + " successfully performed on comment " + anId); logAdminUsage(aRequest, "comment."+anId, "operation " + anOperation + " performed"); } else { - logger.error("Error while performing " + anOperation + " on comment " + anId + ": comment is null"); + getLogger().error("Error while performing " + anOperation + " on comment " + anId + ": comment is null"); } } catch (Throwable e) { - logger.error("Error while performing " + anOperation + " on comment " + anId + ": " + e.getMessage()); + getLogger().error("Error while performing " + anOperation + " on comment " + anId + ": " + e.getMessage(), e); } } @@ -126,6 +117,23 @@ public class ServletModuleLocalizer extends ServletModule { ServletHelper.redirect(aResponse, returnUrlString); } + 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"); + + + if ("comment".equals(type)) { + performCommentOperation(aRequest, id, operation); + } + else { + performArticleOperation(aRequest, id, operation); + } + + ServletHelper.redirect(aResponse, returnUrl); + } + public void commentoperationbatch(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc { String returnUrlString = aRequest.getParameter("returnurl"); @@ -137,7 +145,7 @@ public class ServletModuleLocalizer extends ServletModule { List parts = StringRoutines.splitString(operations[i], ";"); if (parts.size() != 2) { - logger.error("commentoperationbatch: operation string invalid: " + + getLogger().error("commentoperationbatch: operation string invalid: " + operations[i]); } else { @@ -153,6 +161,38 @@ public class ServletModuleLocalizer extends ServletModule { ServletHelper.redirect(aResponse, returnUrlString); } + public void operationbatch(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() != 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; @@ -161,15 +201,15 @@ public class ServletModuleLocalizer extends ServletModule { if (entity != null) { MirGlobal.performArticleOperation(ServletHelper.getUser(aRequest), entity, anOperation); - logger.info("Operation " + anOperation + " successfully performed on article " + anId); + getLogger().info("Operation " + anOperation + " successfully performed on article " + anId); logAdminUsage(aRequest, "article." + anId, "operation " + anOperation + " performed"); } else { - logger.error("Error while performing " + anOperation + " on article " + anId + ": article is null"); + getLogger().error("Error while performing " + anOperation + " on article " + anId + ": article is null"); } } catch (Throwable e) { - logger.error("Error while performing " + anOperation + " on article " + anId + ": " + e.getMessage()); + getLogger().error("Error while performing " + anOperation + " on article " + anId + ": " + e.getMessage()); } } @@ -194,7 +234,7 @@ public class ServletModuleLocalizer extends ServletModule { List parts = StringRoutines.splitString(operations[i], ";"); if (parts.size() != 2) { - logger.error("articleoperationbatch: operation string invalid: " + operations[i]); + getLogger().error("articleoperationbatch: operation string invalid: " + operations[i]); } else { String articleIdString = (String) parts.get(0);