2 * Copyright (C) 2001, 2002 The Mir-coders group
4 * This file is part of Mir.
6 * Mir is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * Mir is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with Mir; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * In addition, as a special exception, The Mir-coders gives permission to link
21 * the code of this program with the com.oreilly.servlet library, any library
22 * licensed under the Apache Software License, The Sun (tm) Java Advanced
23 * Imaging library (JAI), The Sun JIMI library (or with modified versions of
24 * the above that use the same license as the above), and distribute linked
25 * combinations including the two. You must obey the GNU General Public
26 * License in all respects for all of the code used other than the above
27 * mentioned libraries. If you modify this file, you may extend this exception
28 * to your version of the file, but you are not obligated to do so. If you do
29 * not wish to do so, delete this exception statement from your version.
32 package mircoders.servlet;
37 import javax.servlet.*;
38 import javax.servlet.http.*;
40 import org.apache.struts.util.MessageResources;
42 import freemarker.template.*;
46 import mir.producer.*;
47 import mir.generator.*;
48 import mir.producer.*;
49 import mir.entity.adapter.*;
52 import mircoders.global.*;
54 /* Verteilerservlet, dass je nach Parameter task die Klasse Producer"TASK"
55 * ueber die Methode handle(); aufruft
60 public class ServletModuleProducer extends ServletModule
63 private static ServletModuleProducer instance = new ServletModuleProducer();
64 public static ServletModule getInstance() { return instance; }
72 void generateResponse(String aGeneratorIdentifier, PrintWriter aWriter, Map aResponseData, Locale aLocale) throws ServletModuleException {
74 generator = MirGlobal.localizer().generators().makeAdminGeneratorLibrary().makeGenerator(aGeneratorIdentifier);
75 MirGlobal.localizer().producerAssistant().initializeGenerationValueSet(aResponseData);
76 aResponseData.put( "lang", new ResourceBundleGeneratorFunction( aLocale, MessageResources.getMessageResources("bundles.admin")));
77 generator.generate(aWriter, aResponseData, new PrintWriter(new NullWriter()));
80 throw new ServletModuleException(t.getMessage());
84 private ServletModuleProducer() {
85 theLog = Logfile.getInstance(MirConfig.getProp("Home") + MirConfig.getProp("ServletModule.Producer.Logfile"));
86 defaultAction="showProducerQueueStatus";
89 public void showMessage(PrintWriter aWriter, Locale aLocale, String aMessage, String anArgument1, String anArgument2) throws ServletModuleException {
92 responseData = new HashMap();
93 responseData.put("message", aMessage);
94 responseData.put("argument1", anArgument1);
95 responseData.put("argument2", anArgument2);
96 generateResponse("infomessage.template", aWriter, responseData, aLocale);
99 throw new ServletModuleException(t.getMessage());
104 public void showProducerQueueStatus(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleException {
112 generator = MirGlobal.localizer().generators().makeAdminGeneratorLibrary().makeGenerator("producerqueue.template");
114 generationData = new HashMap();
115 MirGlobal.localizer().producerAssistant().initializeGenerationValueSet(generationData);
117 generationData.put( "lang", new ResourceBundleGeneratorFunction( getLocale(aRequest), MessageResources.getMessageResources("bundles.admin")));
118 generationData.put( "thisurl", "module=Producer&do=showProducerQueueStatus");
120 producersData = new Vector();
121 Iterator i = MirGlobal.localizer().producers().factories().iterator();
122 while (i.hasNext()) {
123 ProducerFactory factory = (ProducerFactory) i.next();
125 List producerVerbs = new Vector();
126 Iterator j = factory.verbs();
127 while (j.hasNext()) {
128 Map verbData = new HashMap();
129 ProducerFactory.ProducerVerb verb = (ProducerFactory.ProducerVerb) j.next();
130 verbData.put("name", verb.getName());
131 verbData.put("description", verb.getDescription());
133 producerVerbs.add(verbData);
136 Map producerData = new HashMap();
137 producerData.put("name", factory.getName());
138 producerData.put("verbs", producerVerbs);
140 producersData.add(producerData);
142 generationData.put("producers", producersData);
144 generationData.put("queue", MirGlobal.producerEngine().getQueueStatus());
145 generator.generate(aResponse.getWriter(), generationData, new PrintWriter(new NullWriter()));
147 catch (Throwable t) {
148 t.printStackTrace(System.out);
149 throw new ServletModuleException(t.getMessage());
153 public void produce(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException {
155 * This method will only be called by external scripts (e.g. from cron jobs).
156 * The output therefore is very simple.
161 PrintWriter out = res.getWriter();
163 if (req.getParameter("producer")!=null) {
164 String producerParam = req.getParameter("producer");
165 String verbParam = req.getParameter("verb");
167 MirGlobal.producerEngine().addJob(producerParam, verbParam);
168 out.println("job added");
171 catch (Exception e) {
172 throw new ServletModuleException(e.getMessage());
176 public void produceAllNew(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleException {
178 MirGlobal.localizer().producers().produceAllNew();
179 showMessage(aResponse.getWriter(), getLocale(aRequest), "produceAllNewAddedToQueue", "", "");
181 catch (Exception e) {
182 throw new ServletModuleException(e.getMessage());
186 public void enqueue(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleException {
188 if (aRequest.getParameter("producer")!=null) {
189 String producerParam = aRequest.getParameter("producer");
190 String verbParam = aRequest.getParameter("verb");
192 MirGlobal.producerEngine().addJob(producerParam, verbParam);
194 showProducerQueueStatus(aRequest, aResponse);
197 catch (Exception e) {
198 throw new ServletModuleException(e.getMessage());
202 public void cancelAbortJob(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleException {