2 * Copyright (C) 2001, 2002 The Mir-coders group
\r
4 * This file is part of Mir.
\r
6 * Mir is free software; you can redistribute it and/or modify
\r
7 * it under the terms of the GNU General Public License as published by
\r
8 * the Free Software Foundation; either version 2 of the License, or
\r
9 * (at your option) any later version.
\r
11 * Mir is distributed in the hope that it will be useful,
\r
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 * GNU General Public License for more details.
\r
16 * You should have received a copy of the GNU General Public License
\r
17 * along with Mir; if not, write to the Free Software
\r
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
20 * In addition, as a special exception, The Mir-coders gives permission to link
\r
21 * the code of this program with the com.oreilly.servlet library, any library
\r
22 * licensed under the Apache Software License, The Sun (tm) Java Advanced
\r
23 * Imaging library (JAI), The Sun JIMI library (or with modified versions of
\r
24 * the above that use the same license as the above), and distribute linked
\r
25 * combinations including the two. You must obey the GNU General Public
\r
26 * License in all respects for all of the code used other than the above
\r
27 * mentioned libraries. If you modify this file, you may extend this exception
\r
28 * to your version of the file, but you are not obligated to do so. If you do
\r
29 * not wish to do so, delete this exception statement from your version.
\r
32 package mircoders.servlet;
\r
34 import java.io.PrintWriter;
\r
35 import java.util.HashMap;
\r
36 import java.util.Locale;
\r
37 import java.util.Map;
\r
39 import org.apache.struts.util.MessageResources;
\r
40 import mir.entity.adapter.EntityIteratorAdapter;
\r
41 import mir.generator.Generator;
\r
42 import mir.servlet.ServletModuleExc;
\r
43 import mir.servlet.ServletModuleFailure;
\r
44 import mir.util.CachingRewindableIterator;
\r
45 import mir.util.NullWriter;
\r
46 import mir.util.ResourceBundleGeneratorFunction;
\r
47 import mircoders.global.MirGlobal;
\r
51 public class ServletHelper {
\r
52 public static Map makeGenerationData(Locale[] aLocales) throws ServletModuleExc {
\r
53 return makeGenerationData(aLocales, "bundles.adminlocal", "bundles.admin");
\r
56 public static Map makeGenerationData(Locale[] aLocales, String aBundle) throws ServletModuleExc {
\r
57 return makeGenerationData(aLocales, aBundle, aBundle);
\r
60 public static Map makeGenerationData(Locale[] aLocales, String aBundle, String aDefaultBundle) throws ServletModuleExc {
\r
63 Map result = new HashMap();
\r
65 MirGlobal.localizer().producerAssistant().initializeGenerationValueSet(result);
\r
67 result.put("returnurl", null);
\r
70 new CachingRewindableIterator(
\r
71 new EntityIteratorAdapter( "", "id", 30,
\r
72 MirGlobal.localizer().dataModel().adapterModel(), "language"));
\r
74 new CachingRewindableIterator(
\r
75 new EntityIteratorAdapter("", "id", 30,
\r
76 MirGlobal.localizer().dataModel().adapterModel(), "topic"));
\r
78 Object articleTypes =
\r
79 new CachingRewindableIterator(
\r
80 new EntityIteratorAdapter( "", "id", 30,
\r
81 MirGlobal.localizer().dataModel().adapterModel(), "articleType"));
\r
83 Object commentStatuses =
\r
84 new CachingRewindableIterator(
\r
85 new EntityIteratorAdapter( "", "id", 30,
\r
86 MirGlobal.localizer().dataModel().adapterModel(), "commentStatus"));
\r
88 result.put("commentstatuses", commentStatuses);
\r
89 result.put("articletypes", articleTypes);
\r
90 result.put("languages", languages);
\r
91 result.put("topics", topics);
\r
94 new ResourceBundleGeneratorFunction( aLocales,
\r
95 new MessageResources[] { MessageResources.getMessageResources(aBundle),
\r
96 MessageResources.getMessageResources(aDefaultBundle)}));
\r
100 catch (Throwable t) {
\r
101 throw new ServletModuleFailure(t);
\r
105 public static void generateResponse(PrintWriter aWriter, Map aGenerationData, String aGenerator) throws ServletModuleExc {
\r
106 Generator generator;
\r
109 generator = MirGlobal.localizer().generators().makeAdminGeneratorLibrary().makeGenerator(aGenerator);
\r
111 generator.generate(aWriter, aGenerationData, new PrintWriter(new NullWriter()));
\r
113 catch (Throwable t) {
\r
114 throw new ServletModuleFailure(t);
\r
118 public static void generateOpenPostingResponse(PrintWriter aWriter, Map aGenerationData, String aGenerator) throws ServletModuleExc {
\r
119 Generator generator;
\r
122 generator = MirGlobal.localizer().generators().makeOpenPostingGeneratorLibrary().makeGenerator(aGenerator);
\r
124 generator.generate(aWriter, aGenerationData, new PrintWriter(new NullWriter()));
\r
126 catch (Throwable t) {
\r
127 throw new ServletModuleFailure(t);
\r