rebuilding head
[mir.git] / source / mircoders / servlet / ServletModuleAdmin.java
index 0cb87c4..568983b 100755 (executable)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2001, 2002  The Mir-coders group
+ * Copyright (C) 2001, 2002 The Mir-coders group
  *
  * This file is part of Mir.
  *
  * 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.
+ * the code of this program with  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.io.*;
-import java.sql.*;
-import java.util.*;
-import javax.servlet.*;
-import javax.servlet.http.*;
-
-import org.apache.struts.util.MessageResources;
-
-import freemarker.template.*;
-
-import mir.servlet.*;
-import mir.misc.*;
-import mir.producer.*;
-import mir.generator.*;
-import mir.producer.*;
-import mir.entity.adapter.*;
-import mir.util.*;
-import mir.log.*;
+import java.io.IOException;
+import java.io.Writer;
+import java.util.Map;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 
-import mircoders.global.*;
+import mir.entity.adapter.EntityIteratorAdapter;
+import mir.log.LoggerWrapper;
+import mir.servlet.ServletModule;
+import mir.servlet.ServletModuleExc;
+import mir.servlet.ServletModuleFailure;
+import mir.util.CachingRewindableIterator;
+import mir.util.URLBuilder;
+import mircoders.global.MirGlobal;
 
 public class ServletModuleAdmin extends ServletModule
 {
@@ -59,18 +51,14 @@ public class ServletModuleAdmin extends ServletModule
 
   private ServletModuleAdmin() {
     logger = new LoggerWrapper("ServletModule.Admin");
-    defaultAction = "showSuperUserMenu";
+    defaultAction = "start";
   }
 
-  public void superusermenu(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleException {
-    // ML: experiment in using the producer's generation system instead of the
-    //     old one...
-
+  public void superusermenu(HttpServletRequest aRequest, HttpServletResponse aResponse) {
     URLBuilder urlBuilder = new URLBuilder();
-    int count;
 
     try {
-      Map responseData = ServletHelper.makeGenerationData(getLocale(aRequest));
+      Map responseData = ServletHelper.makeGenerationData(aRequest, aResponse, getLocales(aRequest));
       urlBuilder.setValue("module", "Admin");
       urlBuilder.setValue("do", "superusermenu");
 
@@ -79,9 +67,79 @@ public class ServletModuleAdmin extends ServletModule
       ServletHelper.generateResponse(aResponse.getWriter(), responseData, "superusermenu.template");
     }
     catch (Throwable e) {
-      e.printStackTrace(new PrintWriter(new LoggerToWriterAdapter(logger, logger.ERROR_MESSAGE)));
+      throw new ServletModuleFailure(e);
+    }
+  }
+
+  /**
+   * Servlet handler method to reload the configuration for scripts.
+   * The output will be aimed at shell sripts.
+   */
+  public void reload(HttpServletRequest aRequest, HttpServletResponse aResponse) {
+    String result = "reload successfull";
+
+    try {
+      MirGlobal.reloadConfigurations();
+    }
+    catch (Throwable t) {
+      result = "error occurred while reloading: " +t.toString();
+    }
+
+    try {
+      Writer writer = aResponse.getWriter();
+      writer.write(result);
+    }
+    catch (IOException e) {
+      throw new ServletModuleFailure(e);
+    }
+  }
 
-      throw new ServletModuleException(e.getMessage());
+  /**
+   * Servlet handler method to reload the configuration.
+   */
+  public void reloadconfiguration(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc {
+    try {
+      MirGlobal.reloadConfigurations();
+       ServletHelper.generateInfoMessage(aRequest, aResponse, getLocales(aRequest),
+           "bundles/admin", "etc/bundles/adminlocal", "reloadSuccessfull", "", "");
+    }
+    catch (Throwable t) {
+      ServletHelper.generateInfoMessage(aRequest, aResponse, getLocales(aRequest),
+           "bundles/admin", "etc/bundles/adminlocal", "reloadFailed", t.toString(), "");
     }
   }
+
+  public void start(HttpServletRequest aRequest, HttpServletResponse aResponse) {
+    String defaultStartTemplate = configuration.getString("Mir.StartTemplate");
+
+    try {
+      Map mergeData = ServletHelper.makeGenerationData(aRequest, aResponse, getLocales(aRequest),
+          "bundles/admin", "etc/bundles/adminlocal");
+      mergeData.put("messages",
+                    new CachingRewindableIterator(
+          new EntityIteratorAdapter("", "webdb_create desc", 10,
+                                    MirGlobal.localizer().dataModel().adapterModel(), "internalMessage", 10, 0)));
+
+      mergeData.put("fileeditentries", ( (ServletModuleFileEdit) ServletModuleFileEdit.getInstance()).getEntries());
+      mergeData.put("administeroperations", ( (ServletModuleLocalizer) ServletModuleLocalizer.getInstance()).getAdministerOperations());
+
+      mergeData.put("searchvalue", null);
+      mergeData.put("searchfield", null);
+      mergeData.put("searchispublished", null);
+      mergeData.put("searcharticletype", null);
+      mergeData.put("searchorder", null);
+      mergeData.put("selectarticleurl", null);
+      mergeData.put("recipes", MirGlobal.localizer().producers().getRecipeNames());
+
+      String startTemplate = MirGlobal.localizer().adminInterface().getAdminPageGenerator(
+          "admin.start", mergeData,
+          ServletHelper.getUserAdapter(aRequest), defaultStartTemplate);
+
+      ServletHelper.generateResponse(aResponse.getWriter(), mergeData, startTemplate);
+    }
+    catch (Exception e) {
+      throw new ServletModuleFailure(e);
+    }
+  }
+
 }