rebuilding head
[mir.git] / source / mircoders / servlet / ServletModuleAdmin.java
index ec85a08..568983b 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  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
-package mircoders.servlet;\r
-\r
-import java.util.Locale;\r
-import java.util.Map;\r
-import javax.servlet.http.HttpServletRequest;\r
-import javax.servlet.http.HttpServletResponse;\r
-\r
-import mir.entity.adapter.EntityIteratorAdapter;\r
-import mir.log.LoggerWrapper;\r
-import mir.servlet.ServletModule;\r
-import mir.servlet.ServletModuleFailure;\r
-import mir.util.CachingRewindableIterator;\r
-import mir.util.URLBuilder;\r
-import mircoders.global.MirGlobal;\r
-\r
-public class ServletModuleAdmin extends ServletModule\r
-{\r
-  private static ServletModuleAdmin instance = new ServletModuleAdmin();\r
-  public static ServletModule getInstance() { return instance; }\r
-\r
-  private ServletModuleAdmin() {\r
-    logger = new LoggerWrapper("ServletModule.Admin");\r
-    defaultAction = "start";\r
-  }\r
-\r
-  public void superusermenu(HttpServletRequest aRequest, HttpServletResponse aResponse) {\r
-    URLBuilder urlBuilder = new URLBuilder();\r
-    int count;\r
-\r
-    try {\r
-      Map responseData = ServletHelper.makeGenerationData(aRequest, aResponse, new Locale[] { getLocale(aRequest), getFallbackLocale(aRequest)});\r
-      urlBuilder.setValue("module", "Admin");\r
-      urlBuilder.setValue("do", "superusermenu");\r
-\r
-      responseData.put("thisurl" , urlBuilder.getQuery());\r
-\r
-      ServletHelper.generateResponse(aResponse.getWriter(), responseData, "superusermenu.template");\r
-    }\r
-    catch (Throwable e) {\r
-      throw new ServletModuleFailure(e);\r
-    }\r
-  }\r
-\r
-  public void start(HttpServletRequest aRequest, HttpServletResponse aResponse) {\r
-    String startTemplate = configuration.getString("Mir.StartTemplate");\r
-    String sessionUrl = aResponse.encodeURL("");\r
-\r
-    try {\r
-      Map mergeData = ServletHelper.makeGenerationData(aRequest, aResponse, new Locale[] {getLocale(aRequest), getFallbackLocale(aRequest)}\r
-          , "bundles.admin", "bundles.adminlocal");\r
-      mergeData.put("messages",\r
-                    new CachingRewindableIterator(\r
-          new EntityIteratorAdapter("", "webdb_create desc", 10,\r
-                                    MirGlobal.localizer().dataModel().adapterModel(), "internalMessage", 10, 0)));\r
-\r
-      mergeData.put("fileeditentries", ( (ServletModuleFileEdit) ServletModuleFileEdit.getInstance()).getEntries());\r
-      mergeData.put("administeroperations", ( (ServletModuleLocalizer) ServletModuleLocalizer.getInstance()).getAdministerOperations());\r
-\r
-      mergeData.put("searchvalue", null);\r
-      mergeData.put("searchfield", null);\r
-      mergeData.put("searchispublished", null);\r
-      mergeData.put("searcharticletype", null);\r
-      mergeData.put("searchorder", null);\r
-      mergeData.put("selectarticleurl", null);\r
-\r
-      ServletHelper.generateResponse(aResponse.getWriter(), mergeData, startTemplate);\r
-    }\r
-    catch (Exception e) {\r
-      throw new ServletModuleFailure(e);\r
-    }\r
-  }\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  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.IOException;
+import java.io.Writer;
+import java.util.Map;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+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
+{
+  private static ServletModuleAdmin instance = new ServletModuleAdmin();
+  public static ServletModule getInstance() { return instance; }
+
+  private ServletModuleAdmin() {
+    logger = new LoggerWrapper("ServletModule.Admin");
+    defaultAction = "start";
+  }
+
+  public void superusermenu(HttpServletRequest aRequest, HttpServletResponse aResponse) {
+    URLBuilder urlBuilder = new URLBuilder();
+
+    try {
+      Map responseData = ServletHelper.makeGenerationData(aRequest, aResponse, getLocales(aRequest));
+      urlBuilder.setValue("module", "Admin");
+      urlBuilder.setValue("do", "superusermenu");
+
+      responseData.put("thisurl" , urlBuilder.getQuery());
+
+      ServletHelper.generateResponse(aResponse.getWriter(), responseData, "superusermenu.template");
+    }
+    catch (Throwable e) {
+      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);
+    }
+  }
+
+  /**
+   * 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);
+    }
+  }
+
+}