admin activity logger added
[mir.git] / source / mircoders / servlet / ServletModuleLocalizer.java
index 363af6c..e4badfa 100755 (executable)
@@ -1,5 +1,5 @@
 /*\r
- * Copyright (C) 2001, 2002  The Mir-coders group\r
+ * Copyright (C) 2001, 2002 The Mir-coders group\r
  *\r
  * This file is part of Mir.\r
  *\r
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
  *\r
  * In addition, as a special exception, The Mir-coders gives permission to link\r
- * the code of this program with the com.oreilly.servlet library, any library\r
- * licensed under the Apache Software License, The Sun (tm) Java Advanced\r
- * Imaging library (JAI), The Sun JIMI library (or with modified versions of\r
- * the above that use the same license as the above), and distribute linked\r
- * combinations including the two.  You must obey the GNU General Public\r
- * License in all respects for all of the code used other than the above\r
- * mentioned libraries.  If you modify this file, you may extend this exception\r
- * to your version of the file, but you are not obligated to do so.  If you do\r
- * not wish to do so, delete this exception statement from your version.\r
+ * the code of this program with  any library licensed under the Apache Software License,\r
+ * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library\r
+ * (or with modified versions of the above that use the same license as the above),\r
+ * and distribute linked combinations including the two.  You must obey the\r
+ * GNU General Public License in all respects for all of the code used other than\r
+ * the above mentioned libraries.  If you modify this file, you may extend this\r
+ * exception to your version of the file, but you are not obligated to do so.\r
+ * If you do not wish to do so, delete this exception statement from your version.\r
  */\r
-\r
 package mircoders.servlet;\r
 \r
+import java.util.HashMap;\r
 import java.util.List;\r
-\r
+import java.util.Map;\r
+import java.util.Vector;\r
 import javax.servlet.http.HttpServletRequest;\r
 import javax.servlet.http.HttpServletResponse;\r
-import javax.servlet.http.HttpSession;\r
 \r
 import mir.entity.adapter.EntityAdapter;\r
 import mir.log.LoggerWrapper;\r
 import mir.servlet.ServletModule;\r
 import mir.servlet.ServletModuleExc;\r
-import mir.servlet.ServletModuleFailure;\r
 import mir.util.StringRoutines;\r
 import mircoders.entity.EntityComment;\r
 import mircoders.entity.EntityContent;\r
@@ -59,31 +57,46 @@ public class ServletModuleLocalizer extends ServletModule {
 \r
   private ModuleContent contentModule;\r
   private ModuleComment commentModule;\r
+  private List administerOperations;\r
 \r
   private ServletModuleLocalizer() {\r
     try {\r
+      logger = new LoggerWrapper("ServletModule.Localizer");\r
+\r
       contentModule = new ModuleContent(DatabaseContent.getInstance());\r
       commentModule = new ModuleComment(DatabaseComment.getInstance());\r
 \r
-      logger = new LoggerWrapper("ServletModule.Localizer");\r
+      administerOperations = new Vector();\r
+\r
+      String settings[] = configuration.getStringArray("Mir.Localizer.Admin.AdministerOperations");\r
+\r
+      if (settings!=null) {\r
+        for (int i = 0; i < settings.length; i++) {\r
+          String setting = settings[i].trim();\r
+\r
+          if (setting.length() > 0) {\r
+            List parts = StringRoutines.splitString(setting, ":");\r
+            if (parts.size() != 2) {\r
+              logger.error("config error: " + settings[i] + ", 2 parts expected");\r
+            }\r
+            else {\r
+              Map entry = new HashMap();\r
+              entry.put("name", (String) parts.get(0));\r
+              entry.put("url", (String) parts.get(1));\r
+              administerOperations.add(entry);\r
+            }\r
+          }\r
+        }\r
+      }\r
     }\r
     catch (Exception e) {\r
       logger.error("ServletModuleLocalizer could not be initialized: " + e.getMessage());\r
     }\r
-  }\r
 \r
-  private EntityAdapter getActiveUser(HttpServletRequest aRequest) throws ServletModuleExc {\r
-    try {\r
-      HttpSession session = aRequest.getSession(false);\r
-      return MirGlobal.localizer().dataModel().adapterModel().makeEntityAdapter\r
-          ("user", (EntityUsers) session.getAttribute("login.uid"));\r
-    }\r
-    catch (Throwable e) {\r
-      throw new ServletModuleFailure("ServletModuleLocalizer.getActiveUser: " + e.getMessage(), e);\r
-    }\r
+\r
   }\r
 \r
-  public void performCommentOperation(EntityAdapter aUser, String anId, String anOperation) {\r
+  public void performCommentOperation(HttpServletRequest aRequest, String anId, String anOperation) {\r
     MirAdminInterfaceLocalizer.MirSimpleEntityOperation operation;\r
     EntityAdapter comment;\r
     EntityComment entity;\r
@@ -92,12 +105,13 @@ public class ServletModuleLocalizer extends ServletModule {
       entity = (EntityComment) commentModule.getById(anId);\r
 \r
       if (entity != null) {\r
-        comment = MirGlobal.localizer().dataModel().adapterModel().makeEntityAdapter("comment", entity);\r
-        operation = MirGlobal.localizer().adminInterface().simpleCommentOperationForName(anOperation);\r
-        operation.perform(aUser, comment);\r
+        MirGlobal.performCommentOperation(ServletHelper.getUser(aRequest), entity, anOperation);\r
         logger.info("Operation " + anOperation + " successfully performed on comment " + anId);\r
+        logAdminUsage(aRequest, "comment."+anId, "operation " + anOperation + " performed");\r
+      }\r
+      else {\r
+        logger.error("Error while performing " + anOperation + " on comment " + anId + ": comment is null");\r
       }\r
-      logger.error("Error while performing " + anOperation + " on comment " + anId + ": comment is null");\r
     }\r
     catch (Throwable e) {\r
       logger.error("Error while performing " + anOperation + " on comment " + anId + ": " + e.getMessage());\r
@@ -109,7 +123,7 @@ public class ServletModuleLocalizer extends ServletModule {
     String operationString = aRequest.getParameter("operation");\r
     String returnUrlString = aRequest.getParameter("returnurl");\r
 \r
-    performCommentOperation(getActiveUser(aRequest), commentIdString, operationString);\r
+    performCommentOperation(aRequest, commentIdString, operationString);\r
 \r
     redirect(aResponse, returnUrlString);\r
   }\r
@@ -119,19 +133,21 @@ public class ServletModuleLocalizer extends ServletModule {
 \r
     String[] operations = aRequest.getParameterValues("operation");\r
 \r
-    for (int i=0; i<operations.length; i++) {\r
-      if (operations[i].length()>0) {\r
-        List parts = StringRoutines.splitString(operations[i], ";");\r
-\r
-        if (parts.size() != 2) {\r
-          logger.error("commentoperationbatch: operation string invalid: " +\r
-                       operations[i]);\r
-        }\r
-        else {\r
-          String commentIdString = (String) parts.get(0);\r
-          String operationString = (String) parts.get(1);\r
-\r
-          performCommentOperation(getActiveUser(aRequest), commentIdString, operationString);\r
+    if (operations!=null) {\r
+      for (int i = 0; i < operations.length; i++) {\r
+        if (operations[i].length() > 0) {\r
+          List parts = StringRoutines.splitString(operations[i], ";");\r
+\r
+          if (parts.size() != 2) {\r
+            logger.error("commentoperationbatch: operation string invalid: " +\r
+                         operations[i]);\r
+          }\r
+          else {\r
+            String commentIdString = (String) parts.get(0);\r
+            String operationString = (String) parts.get(1);\r
+\r
+            performCommentOperation(aRequest, commentIdString, operationString);\r
+          }\r
         }\r
       }\r
     }\r
@@ -139,7 +155,7 @@ public class ServletModuleLocalizer extends ServletModule {
     redirect(aResponse, returnUrlString);\r
   }\r
 \r
-  public void performArticleOperation(EntityAdapter aUser, String anId, String anOperation) {\r
+  public void performArticleOperation(HttpServletRequest aRequest, String anId, String anOperation) {\r
     MirAdminInterfaceLocalizer.MirSimpleEntityOperation operation;\r
     EntityAdapter article;\r
     EntityContent entity;\r
@@ -148,14 +164,13 @@ public class ServletModuleLocalizer extends ServletModule {
       entity = (EntityContent) contentModule.getById(anId);\r
 \r
       if (entity != null) {\r
-        article = MirGlobal.localizer().dataModel().adapterModel().\r
-            makeEntityAdapter("content", entity);\r
-        operation = MirGlobal.localizer().adminInterface().\r
-            simpleArticleOperationForName(anOperation);\r
-        operation.perform(aUser, article);\r
+        MirGlobal.performArticleOperation(ServletHelper.getUser(aRequest), entity, anOperation);\r
         logger.info("Operation " + anOperation + " successfully performed on article " + anId);\r
+        logAdminUsage(aRequest, "article."+anId, "operation " + anOperation + " performed");\r
+      }\r
+      else {\r
+        logger.error("Error while performing " + anOperation + " on article " + anId + ": article is null");\r
       }\r
-      logger.error("Error while performing " + anOperation + " on article " + anId + ": article is null");\r
     }\r
     catch (Throwable e) {\r
       logger.error("Error while performing " + anOperation + " on article " + anId + ": " + e.getMessage());\r
@@ -167,7 +182,7 @@ public class ServletModuleLocalizer extends ServletModule {
     String operationString = aRequest.getParameter("operation");\r
     String returnUrlString = aRequest.getParameter("returnurl");\r
 \r
-    performArticleOperation(getActiveUser(aRequest), articleIdString, operationString);\r
+    performArticleOperation(aRequest, articleIdString, operationString);\r
     redirect(aResponse, returnUrlString);\r
   }\r
 \r
@@ -176,18 +191,21 @@ public class ServletModuleLocalizer extends ServletModule {
 \r
     String[] operations = aRequest.getParameterValues("operation");\r
 \r
-    for (int i=0; i<operations.length; i++) {\r
-      if (operations[i].length()>0) {\r
-        List parts = StringRoutines.splitString(operations[i], ";");\r
+    if (operations!=null) {\r
 \r
-        if (parts.size() != 2) {\r
-          logger.error("articleoperationbatch: operation string invalid: " + operations[i]);\r
-        }\r
-        else {\r
-          String articleIdString = (String) parts.get(0);\r
-          String operationString = (String) parts.get(1);\r
+      for (int i = 0; i < operations.length; i++) {\r
+        if (operations[i].length() > 0) {\r
+          List parts = StringRoutines.splitString(operations[i], ";");\r
 \r
-          performArticleOperation(getActiveUser(aRequest), articleIdString, operationString);\r
+          if (parts.size() != 2) {\r
+            logger.error("articleoperationbatch: operation string invalid: " + operations[i]);\r
+          }\r
+          else {\r
+            String articleIdString = (String) parts.get(0);\r
+            String operationString = (String) parts.get(1);\r
+\r
+            performArticleOperation(aRequest, articleIdString, operationString);\r
+          }\r
         }\r
       }\r
     }\r
@@ -195,4 +213,7 @@ public class ServletModuleLocalizer extends ServletModule {
     redirect(aResponse, returnUrlString);\r
   }\r
 \r
+  public List getAdministerOperations() throws ServletModuleExc {\r
+    return administerOperations;\r
+  }\r
 }
\ No newline at end of file