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.net.URLEncoder;
\r
35 import javax.servlet.http.HttpServletRequest;
\r
36 import javax.servlet.http.HttpServletResponse;
\r
38 import freemarker.template.SimpleHash;
\r
39 import mir.entity.EntityList;
\r
40 import mir.log.LoggerWrapper;
\r
41 import mir.misc.HTMLTemplateProcessor;
\r
42 import mir.servlet.ServletModule;
\r
43 import mir.servlet.ServletModuleExc;
\r
44 import mir.servlet.ServletModuleFailure;
\r
45 import mir.storage.StorageObjectFailure;
\r
46 import mircoders.module.ModuleMessage;
\r
47 import mircoders.storage.DatabaseMessages;
\r
50 * Title: ServletModuleMessage
\r
52 * Copyright: Copyright (c) 2001-2002
\r
53 * Company: mir-coders
\r
59 public class ServletModuleMessage extends ServletModule
\r
62 // Singelton / Kontruktor
\r
64 private static ServletModuleMessage instance = new ServletModuleMessage();
\r
65 public static ServletModule getInstance() { return instance; }
\r
67 private ServletModuleMessage() {
\r
69 logger = new LoggerWrapper("ServletModule.Messages");
\r
71 templateListString = configuration.getString("ServletModule.Messages.ListTemplate");
\r
72 templateObjektString = configuration.getString("ServletModule.Messages.ObjektTemplate");
\r
73 templateConfirmString = configuration.getString("ServletModule.Messages.ConfirmTemplate");
\r
76 mainModule = new ModuleMessage(DatabaseMessages.getInstance());
\r
78 catch (StorageObjectFailure e) {
\r
79 logger.error("initialization of ServletModuleMessage failed!: " + e.getMessage());
\r
81 throw new ServletModuleFailure(e);
\r
85 public void list(HttpServletRequest req, HttpServletResponse res) throws ServletModuleExc
\r
87 // fetch and deliver
\r
89 SimpleHash mergeData = new SimpleHash();
\r
90 String offset = req.getParameter("offset");
\r
91 if (offset==null || offset.equals("")) offset="0";
\r
92 mergeData.put("offset",offset);
\r
93 EntityList theList = mainModule.getByWhereClause(null, "webdb_create desc", (new Integer(offset)).intValue());
\r
94 mergeData.put("contentlist",theList);
\r
95 if(theList.getOrder()!=null) {
\r
96 mergeData.put("order", theList.getOrder());
\r
97 mergeData.put("order_encoded", URLEncoder.encode(theList.getOrder()));
\r
99 mergeData.put("count", (new Integer(theList.getCount())).toString());
\r
100 mergeData.put("from", (new Integer(theList.getFrom())).toString());
\r
101 mergeData.put("to", (new Integer(theList.getTo())).toString());
\r
102 if (theList.hasNextBatch())
\r
103 mergeData.put("next", (new Integer(theList.getNextBatch())).toString());
\r
104 if (theList.hasPrevBatch())
\r
105 mergeData.put("prev", (new Integer(theList.getPrevBatch())).toString());
\r
107 HTMLTemplateProcessor.process(res, templateListString, mergeData, res.getWriter(), getLocale(req), getFallbackLocale(req));
\r
110 catch (Throwable e) {
\r
111 throw new ServletModuleFailure(e);
\r