minor changes according to JLint
[mir.git] / source / mircoders / servlet / ServletModuleProducer.java
index 7956245..c6ba0ec 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.PrintWriter;
@@ -47,7 +45,7 @@ import mir.log.LoggerWrapper;
 import mir.producer.ProducerFactory;
 import mir.servlet.ServletModule;
 import mir.servlet.ServletModuleFailure;
-import mir.util.NullWriter;
+import mir.util.HTTPRequestParser;
 import mir.util.ResourceBundleGeneratorFunction;
 import mircoders.global.MirGlobal;
 
@@ -59,12 +57,10 @@ public class ServletModuleProducer extends ServletModule
   public static ServletModule getInstance() { return instance; }
 
   Object comments;
-  Map generationData;
-  Generator generator;
   int totalNrComments;
-  List producersData;
 
   void generateResponse(String aGeneratorIdentifier, PrintWriter aWriter, Map aResponseData, Locale aLocale) {
+    Generator generator;
     try {
       generator = MirGlobal.localizer().generators().makeAdminGeneratorLibrary().makeGenerator(aGeneratorIdentifier);
       MirGlobal.localizer().producerAssistant().initializeGenerationValueSet(aResponseData);
@@ -82,21 +78,21 @@ public class ServletModuleProducer extends ServletModule
     defaultAction="showProducerQueueStatus";
   }
 
-  public void showMessage(PrintWriter aWriter, Locale aLocale, String aMessage, String anArgument1, String anArgument2) {
+  public void showMessage(HttpServletRequest aRequest, HttpServletResponse aResponse, String aMessage, String anArgument1, String anArgument2) {
     Map responseData;
     try {
-      responseData = new HashMap();
+      responseData = ServletHelper.makeGenerationData(aRequest, aResponse, new Locale[] { getLocale(aRequest), getFallbackLocale(aRequest)});
       responseData.put("message", aMessage);
       responseData.put("argument1", anArgument1);
       responseData.put("argument2", anArgument2);
-      generateResponse("infomessage.template", aWriter, responseData, aLocale);
+
+      ServletHelper.generateResponse(aResponse.getWriter(), responseData, "infomessage.template");
     }
     catch (Throwable t) {
       throw new ServletModuleFailure(t);
     }
   }
 
-
   public void showProducerQueueStatus(HttpServletRequest aRequest, HttpServletResponse aResponse) {
     Object comments;
     Map generationData;
@@ -107,7 +103,7 @@ public class ServletModuleProducer extends ServletModule
     try {
       generator = MirGlobal.localizer().generators().makeAdminGeneratorLibrary().makeGenerator("producerqueue.template");
 
-      generationData = ServletHelper.makeGenerationData(new Locale[] { getLocale(aRequest), getFallbackLocale(aRequest)});
+      generationData = ServletHelper.makeGenerationData(aRequest, aResponse, new Locale[] { getLocale(aRequest), getFallbackLocale(aRequest)});
       generationData.put( "thisurl", "module=Producer&do=showProducerQueueStatus");
 
       producersData = new Vector();
@@ -142,19 +138,18 @@ public class ServletModuleProducer extends ServletModule
     }
   }
 
-  public void produce(HttpServletRequest req, HttpServletResponse res) {
+  public void produce(HttpServletRequest aRequest, HttpServletResponse aResponse) {
     /*
      * This method will only be called by external scripts (e.g. from cron jobs).
      * The output therefore is very simple.
-     *
      */
 
     try {
-      PrintWriter out = res.getWriter();
+      PrintWriter out = aResponse.getWriter();
 
-      if (req.getParameter("producer")!=null) {
-        String producerParam = req.getParameter("producer");
-        String verbParam = req.getParameter("verb");
+      if (aRequest.getParameter("producer")!=null) {
+        String producerParam = aRequest.getParameter("producer");
+        String verbParam = aRequest.getParameter("verb");
 
         MirGlobal.producerEngine().addJob(producerParam, verbParam);
         out.println("job added");
@@ -165,10 +160,11 @@ public class ServletModuleProducer extends ServletModule
     }
   }
 
-  public void produceAllNew(HttpServletRequest aRequest, HttpServletResponse aResponse) {
+  public void producerecipe(HttpServletRequest aRequest, HttpServletResponse aResponse) {
     try {
-      MirGlobal.localizer().producers().produceAllNew();
-      showMessage(aResponse.getWriter(), getLocale(aRequest), "produceAllNewAddedToQueue", "", "");
+      String recipe = aRequest.getParameter("recipe");
+      MirGlobal.localizer().producers().produceRecipe(recipe);
+      showMessage(aRequest, aResponse, "recipeAddedToQueue", recipe, "");
     }
     catch (Throwable t) {
       throw new ServletModuleFailure(t);
@@ -183,7 +179,7 @@ public class ServletModuleProducer extends ServletModule
 
         MirGlobal.producerEngine().addJob(producerParam, verbParam);
 
-        showProducerQueueStatus(aRequest, aResponse);
+        ServletHelper.redirect(aResponse, "Producer", "showProducerQueueStatus");
       }
     }
     catch (Throwable t) {
@@ -191,7 +187,22 @@ public class ServletModuleProducer extends ServletModule
     }
   }
 
-  public void cancelAbortJob(HttpServletRequest aRequest, HttpServletResponse aResponse)  {
-    // ML: to be coded
+  public void cancel(HttpServletRequest aRequest, HttpServletResponse aResponse)  {
+    try {
+      HTTPRequestParser requestParser = new HTTPRequestParser(aRequest);
+
+      if (requestParser.getParameter("cancelall") != null) {
+        MirGlobal.producerEngine().cancelAllJobs();
+      }
+      else {
+        List jobs = new Vector(requestParser.getParameterList("jobid"));
+
+        MirGlobal.producerEngine().cancelJobs(jobs);
+      }
+      ServletHelper.redirect(aResponse, "Producer", "showProducerQueueStatus");
+    }
+    catch (Throwable t) {
+      throw new ServletModuleFailure(t);
+    }
   }
 }