new admin templates! with many thanks to init...
[mir.git] / source / mircoders / servlet / ServletModuleLocalizer.java
index a0d57c0..aa973b3 100755 (executable)
-/*\r
- * Copyright (C) 2001, 2002  The Mir-coders group\r
- *\r
- * This file is part of Mir.\r
- *\r
- * Mir is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 2 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * Mir is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with Mir; if not, write to the Free Software\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
- */\r
-\r
-package mircoders.servlet;\r
-\r
-import java.util.*;\r
-\r
-import javax.servlet.*;\r
-import javax.servlet.http.*;\r
-\r
-import mir.servlet.*;\r
-import mir.entity.adapter.*;\r
-import mir.log.*;\r
-import mir.util.*;\r
-\r
-import mircoders.global.*;\r
-import mircoders.localizer.*;\r
-import mircoders.storage.*;\r
-import mircoders.entity.*;\r
-import mircoders.module.*;\r
-\r
-public class ServletModuleLocalizer extends ServletModule {\r
-  private static ServletModuleLocalizer instance = new ServletModuleLocalizer();\r
-  public static ServletModule getInstance() { return instance; }\r
-\r
-  private ModuleContent contentModule;\r
-  private ModuleComment commentModule;\r
-\r
-  private ServletModuleLocalizer() {\r
-    try {\r
-      contentModule = new ModuleContent(DatabaseContent.getInstance());\r
-      commentModule = new ModuleComment(DatabaseComment.getInstance());\r
-\r
-      logger = new LoggerWrapper("ServletModule.Localizer");\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 ServletModuleException {\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 (Exception e) {\r
-      throw new ServletModuleException("ServletModuleLocalizer.getActiveUser: " + e.getMessage());\r
-    }\r
-  }\r
-\r
-  public void performCommentOperation(EntityAdapter aUser, String anId, String anOperation) {\r
-    MirAdminInterfaceLocalizer.MirSimpleEntityOperation operation;\r
-    EntityAdapter comment;\r
-    EntityComment entity;\r
-\r
-    try {\r
-      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
-        logger.info("Operation " + anOperation + " successfully performed on comment " + anId);\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
-    }\r
-  }\r
-\r
-  public void commentoperation(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleException {\r
-    String commentIdString = aRequest.getParameter("id");\r
-    String operationString = aRequest.getParameter("operation");\r
-    String returnUrlString = aRequest.getParameter("returnurl");\r
-\r
-    performCommentOperation(getActiveUser(aRequest), commentIdString, operationString);\r
-\r
-    redirect(aResponse, returnUrlString);\r
-  }\r
-\r
-  public void commentoperationbatch(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleException {\r
-    String returnUrlString = aRequest.getParameter("returnurl");\r
-\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
-        }\r
-      }\r
-    }\r
-\r
-    redirect(aResponse, returnUrlString);\r
-  }\r
-\r
-  public void performArticleOperation(EntityAdapter aUser, String anId, String anOperation) {\r
-    MirAdminInterfaceLocalizer.MirSimpleEntityOperation operation;\r
-    EntityAdapter article;\r
-    EntityContent entity;\r
-\r
-    try {\r
-      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
-        logger.info("Operation " + anOperation + " successfully performed on article " + anId);\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
-    }\r
-  }\r
-\r
-  public void articleoperation(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleException {\r
-    String articleIdString = aRequest.getParameter("articleid");\r
-    String operationString = aRequest.getParameter("operation");\r
-    String returnUrlString = aRequest.getParameter("returnurl");\r
-\r
-    performArticleOperation(getActiveUser(aRequest), articleIdString, operationString);\r
-    redirect(aResponse, returnUrlString);\r
-  }\r
-\r
-  public void articleoperationbatch(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleException {\r
-    String returnUrlString = aRequest.getParameter("returnurl");\r
-\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("articleoperationbatch: operation string invalid: " +\r
-                       operations[i]);\r
-        }\r
-        else {\r
-          String articleIdString = (String) parts.get(0);\r
-          String operationString = (String) parts.get(1);\r
-\r
-          performArticleOperation(getActiveUser(aRequest), articleIdString, operationString);\r
-        }\r
-      }\r
-    }\r
-\r
-    redirect(aResponse, returnUrlString);\r
-  }\r
-\r
+/*
+ * Copyright (C) 2001, 2002  The Mir-coders group
+ *
+ * This file is part of Mir.
+ *
+ * Mir is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Mir is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Mir; if not, write to the Free Software
+ * 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.
+ */
+
+package mircoders.servlet;
+
+import java.util.List;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+import mir.entity.adapter.EntityAdapter;
+import mir.log.LoggerWrapper;
+import mir.servlet.ServletModule;
+import mir.servlet.ServletModuleExc;
+import mir.servlet.ServletModuleFailure;
+import mir.util.StringRoutines;
+import mircoders.entity.EntityComment;
+import mircoders.entity.EntityContent;
+import mircoders.entity.EntityUsers;
+import mircoders.global.MirGlobal;
+import mircoders.localizer.MirAdminInterfaceLocalizer;
+import mircoders.module.ModuleComment;
+import mircoders.module.ModuleContent;
+import mircoders.storage.DatabaseComment;
+import mircoders.storage.DatabaseContent;
+
+public class ServletModuleLocalizer extends ServletModule {
+  private static ServletModuleLocalizer instance = new ServletModuleLocalizer();
+  public static ServletModule getInstance() { return instance; }
+
+  private ModuleContent contentModule;
+  private ModuleComment commentModule;
+
+  private ServletModuleLocalizer() {
+    try {
+      contentModule = new ModuleContent(DatabaseContent.getInstance());
+      commentModule = new ModuleComment(DatabaseComment.getInstance());
+
+      logger = new LoggerWrapper("ServletModule.Localizer");
+    }
+    catch (Exception e) {
+      logger.error("ServletModuleLocalizer could not be initialized: " + e.getMessage());
+    }
+  }
+
+  private EntityAdapter getActiveUser(HttpServletRequest aRequest) throws ServletModuleExc {
+    try {
+      HttpSession session = aRequest.getSession(false);
+      return MirGlobal.localizer().dataModel().adapterModel().makeEntityAdapter
+          ("user", (EntityUsers) session.getAttribute("login.uid"));
+    }
+    catch (Throwable e) {
+      throw new ServletModuleFailure("ServletModuleLocalizer.getActiveUser: " + e.getMessage(), e);
+    }
+  }
+
+  public void performCommentOperation(EntityAdapter aUser, String anId, String anOperation) {
+    MirAdminInterfaceLocalizer.MirSimpleEntityOperation operation;
+    EntityAdapter comment;
+    EntityComment entity;
+
+    try {
+      entity = (EntityComment) commentModule.getById(anId);
+
+      if (entity != null) {
+        comment = MirGlobal.localizer().dataModel().adapterModel().makeEntityAdapter("comment", entity);
+        operation = MirGlobal.localizer().adminInterface().simpleCommentOperationForName(anOperation);
+        operation.perform(aUser, comment);
+        logger.info("Operation " + anOperation + " successfully performed on comment " + anId);
+      }
+      logger.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());
+    }
+  }
+
+  public void commentoperation(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc {
+    String commentIdString = aRequest.getParameter("id");
+    String operationString = aRequest.getParameter("operation");
+    String returnUrlString = aRequest.getParameter("returnurl");
+
+    performCommentOperation(getActiveUser(aRequest), commentIdString, operationString);
+
+    redirect(aResponse, returnUrlString);
+  }
+
+  public void commentoperationbatch(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc {
+    String returnUrlString = aRequest.getParameter("returnurl");
+
+    String[] operations = aRequest.getParameterValues("operation");
+
+    for (int i=0; i<operations.length; i++) {
+      if (operations[i].length()>0) {
+        List parts = StringRoutines.splitString(operations[i], ";");
+
+        if (parts.size() != 2) {
+          logger.error("commentoperationbatch: operation string invalid: " +
+                       operations[i]);
+        }
+        else {
+          String commentIdString = (String) parts.get(0);
+          String operationString = (String) parts.get(1);
+
+          performCommentOperation(getActiveUser(aRequest), commentIdString, operationString);
+        }
+      }
+    }
+
+    redirect(aResponse, returnUrlString);
+  }
+
+  public void performArticleOperation(EntityAdapter aUser, String anId, String anOperation) {
+    MirAdminInterfaceLocalizer.MirSimpleEntityOperation operation;
+    EntityAdapter article;
+    EntityContent entity;
+
+    try {
+      entity = (EntityContent) contentModule.getById(anId);
+
+      if (entity != null) {
+        article = MirGlobal.localizer().dataModel().adapterModel().
+            makeEntityAdapter("content", entity);
+        operation = MirGlobal.localizer().adminInterface().
+            simpleArticleOperationForName(anOperation);
+        operation.perform(aUser, article);
+        logger.info("Operation " + anOperation + " successfully performed on article " + anId);
+      }
+      logger.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());
+    }
+  }
+
+  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(getActiveUser(aRequest), articleIdString, operationString);
+    redirect(aResponse, returnUrlString);
+  }
+
+  public void articleoperationbatch(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc {
+    String returnUrlString = aRequest.getParameter("returnurl");
+
+    String[] operations = aRequest.getParameterValues("operation");
+
+    for (int i=0; i<operations.length; i++) {
+      if (operations[i].length()>0) {
+        List parts = StringRoutines.splitString(operations[i], ";");
+
+        if (parts.size() != 2) {
+          logger.error("articleoperationbatch: operation string invalid: " + operations[i]);
+        }
+        else {
+          String articleIdString = (String) parts.get(0);
+          String operationString = (String) parts.get(1);
+
+          performArticleOperation(getActiveUser(aRequest), articleIdString, operationString);
+        }
+      }
+    }
+
+    redirect(aResponse, returnUrlString);
+  }
+
 }
\ No newline at end of file