merged 1.1 branch into head
[mir.git] / source / mircoders / servlet / ServletModuleLocalizer.java
index 39370af..4944f23 100755 (executable)
@@ -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,29 +40,20 @@ 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;
-import java.util.Vector;
 
-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 Vector();
-
-      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++) {
@@ -72,7 +62,7 @@ public class ServletModuleLocalizer extends ServletModule {
           if (setting.length() > 0) {
             List parts = StringRoutines.splitString(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();
@@ -85,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);
     }
   }
 
@@ -100,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);
     }
   }
 
@@ -129,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");
 
@@ -140,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 {
@@ -156,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;
 
@@ -164,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());
     }
   }
 
@@ -197,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);