X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=source%2Fmircoders%2Fservlet%2FServletModuleProducer.java;h=51427b5ffbf006dd252027fe070456244f7deaa5;hb=4451d4c8c25d46e9c405e966ff6bd016a1512f4f;hp=3b044b982c5ddb39848cd9ff7daf3c8be7c0286a;hpb=d90c1bbdd5e1823253436f24dce80de4f0abbfcb;p=mir.git diff --git a/source/mircoders/servlet/ServletModuleProducer.java b/source/mircoders/servlet/ServletModuleProducer.java index 3b044b98..51427b5f 100755 --- a/source/mircoders/servlet/ServletModuleProducer.java +++ b/source/mircoders/servlet/ServletModuleProducer.java @@ -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. * @@ -18,17 +18,15 @@ * 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; @@ -46,8 +44,8 @@ import mir.generator.Generator; import mir.log.LoggerWrapper; import mir.producer.ProducerFactory; import mir.servlet.ServletModule; -import mir.servlet.ServletModuleException; -import mir.util.NullWriter; +import mir.servlet.ServletModuleFailure; +import mir.util.HTTPRequestParser; import mir.util.ResourceBundleGeneratorFunction; import mircoders.global.MirGlobal; @@ -64,15 +62,15 @@ public class ServletModuleProducer extends ServletModule int totalNrComments; List producersData; - void generateResponse(String aGeneratorIdentifier, PrintWriter aWriter, Map aResponseData, Locale aLocale) throws ServletModuleException { + void generateResponse(String aGeneratorIdentifier, PrintWriter aWriter, Map aResponseData, Locale aLocale) { try { generator = MirGlobal.localizer().generators().makeAdminGeneratorLibrary().makeGenerator(aGeneratorIdentifier); MirGlobal.localizer().producerAssistant().initializeGenerationValueSet(aResponseData); aResponseData.put( "lang", new ResourceBundleGeneratorFunction( aLocale, MessageResources.getMessageResources("bundles.admin"))); - generator.generate(aWriter, aResponseData, new PrintWriter(new NullWriter())); + generator.generate(aWriter, aResponseData, logger); } catch (Throwable t) { - throw new ServletModuleException(t.getMessage()); + throw new ServletModuleFailure(t); } } @@ -82,22 +80,22 @@ public class ServletModuleProducer extends ServletModule defaultAction="showProducerQueueStatus"; } - public void showMessage(PrintWriter aWriter, Locale aLocale, String aMessage, String anArgument1, String anArgument2) throws ServletModuleException { + 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 ServletModuleException(t.getMessage()); + throw new ServletModuleFailure(t); } } - - public void showProducerQueueStatus(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleException { + public void showProducerQueueStatus(HttpServletRequest aRequest, HttpServletResponse aResponse) { Object comments; Map generationData; Generator generator; @@ -107,7 +105,7 @@ public class ServletModuleProducer extends ServletModule try { generator = MirGlobal.localizer().generators().makeAdminGeneratorLibrary().makeGenerator("producerqueue.template"); - generationData = ServletHelper.makeGenerationData(getLocale(aRequest)); + generationData = ServletHelper.makeGenerationData(aRequest, aResponse, new Locale[] { getLocale(aRequest), getFallbackLocale(aRequest)}); generationData.put( "thisurl", "module=Producer&do=showProducerQueueStatus"); producersData = new Vector(); @@ -135,48 +133,47 @@ public class ServletModuleProducer extends ServletModule generationData.put("producers", producersData); generationData.put("queue", MirGlobal.producerEngine().getQueueStatus()); - generator.generate(aResponse.getWriter(), generationData, new PrintWriter(new NullWriter())); + generator.generate(aResponse.getWriter(), generationData, logger); } catch (Throwable t) { - t.printStackTrace(System.out); - throw new ServletModuleException(t.getMessage()); + throw new ServletModuleFailure(t); } } - public void produce(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException { + 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"); } } - catch (Exception e) { - throw new ServletModuleException(e.getMessage()); + catch (Throwable t) { + throw new ServletModuleFailure(t); } } - public void produceAllNew(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleException { + 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 (Exception e) { - throw new ServletModuleException(e.getMessage()); + catch (Throwable t) { + throw new ServletModuleFailure(t); } } - public void enqueue(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleException { + public void enqueue(HttpServletRequest aRequest, HttpServletResponse aResponse) { try { if (aRequest.getParameter("producer")!=null) { String producerParam = aRequest.getParameter("producer"); @@ -184,15 +181,30 @@ public class ServletModuleProducer extends ServletModule MirGlobal.producerEngine().addJob(producerParam, verbParam); - showProducerQueueStatus(aRequest, aResponse); + ServletHelper.redirect(aResponse, "Producer", "showProducerQueueStatus"); } } - catch (Exception e) { - throw new ServletModuleException(e.getMessage()); + catch (Throwable t) { + throw new ServletModuleFailure(t); } } - public void cancelAbortJob(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleException { - // 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); + } } }