maintenance + localized operations introduced for comments
[mir.git] / source / mircoders / servlet / ServletModuleLocalizer.java
index 406f978..6977bdf 100755 (executable)
@@ -51,10 +51,12 @@ public class ServletModuleLocalizer extends ServletModule {
   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");
     }
@@ -63,26 +65,29 @@ public class ServletModuleLocalizer extends ServletModule {
     }
   }
 
+  public void commentoperation(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleException {
+    String idString = aRequest.getParameter("id");
+    String operationString = aRequest.getParameter("operation");
+    String returnUrlString = aRequest.getParameter("returnurl");
 
-  public void commentoperation(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException
-  {
-    try {
-      String operationKey = req.getParameter("operation");
-      String commentId = req.getParameter("commentid");
-      EntityComment comment = (EntityComment) DatabaseComment.getInstance().selectById(commentId);
-      MirAdminInterfaceLocalizer.MirSimpleEntityOperation operation =
-          (MirAdminInterfaceLocalizer.MirSimpleEntityOperation)
-          MirGlobal.localizer().adminInterface().simpleArticleOperationForName(operationKey);
+    MirAdminInterfaceLocalizer.MirSimpleEntityOperation operation;
+    EntityAdapter comment;
+    EntityComment entity;
 
-      EntityAdapter adapter = MirGlobal.localizer().dataModel().adapterModel().makeEntityAdapter("comment", comment);
+    try {
+      entity = (EntityComment) commentModule.getById(idString);
 
-      operation.perform( adapter );
+      if (entity!=null) {
+        comment = MirGlobal.localizer().dataModel().adapterModel().makeEntityAdapter("comment", entity);
+        operation = MirGlobal.localizer().adminInterface().simpleCommentOperationForName(operationString);
+        operation.perform(comment);
+      }
 
-      res.sendRedirect(req.getParameter("returnuri"));
+      redirect(aResponse, returnUrlString);
     }
-    catch (Throwable t) {
-      t.printStackTrace(System.out);
-      throw new ServletModuleException(t.getMessage());
+    catch (Throwable e) {
+      e.printStackTrace(System.out);
+      throw new ServletModuleException(e.getMessage());
     }
   }