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;
38 import javax.servlet.*;
39 import javax.servlet.http.*;
41 import freemarker.template.*;
50 import mircoders.storage.*;
51 import mircoders.module.*;
54 * ServletModuleComment - controls navigation for Comments
60 public class ServletModuleComment extends ServletModule
63 private ModuleContent moduleContent;
65 // Singelton / Kontruktor
66 private static ServletModuleComment instance = new ServletModuleComment();
67 public static ServletModule getInstance() { return instance; }
69 private ServletModuleComment() {
70 theLog = Logfile.getInstance(MirConfig.getProp("Home") + MirConfig.getProp("ServletModule.Comment.Logfile"));
71 templateListString = MirConfig.getProp("ServletModule.Comment.ListTemplate");
72 templateObjektString = MirConfig.getProp("ServletModule.Comment.ObjektTemplate");
73 templateConfirmString = MirConfig.getProp("ServletModule.Comment.ConfirmTemplate");
75 mainModule = new ModuleComment(DatabaseComment.getInstance());
76 moduleContent = new ModuleContent(DatabaseContent.getInstance());
78 catch (StorageObjectException e) {
79 theLog.printError("servletmodule: comment could not be initialized");
84 public void list(HttpServletRequest req, HttpServletResponse res)
85 throws ServletModuleException
87 // Parameter auswerten
88 SimpleHash mergeData = new SimpleHash();
89 String query_text = req.getParameter("query_text");
90 mergeData.put("query_text",query_text);
91 if (query_text!=null) mergeData.put("query_text_encoded",URLEncoder.encode(query_text));
92 String query_field = req.getParameter("query_field");
93 mergeData.put("query_field",query_field);
94 String query_is_published = req.getParameter("query_is_published");
95 mergeData.put("query_is_published",query_is_published);
97 String offset = req.getParameter("offset");
98 if (offset==null || offset.equals("")) offset="0";
99 mergeData.put("offset",offset);
102 String order = req.getParameter("order");
104 mergeData.put("order", order);
105 mergeData.put("order_encoded", URLEncoder.encode(order));
106 if (order.equals("webdb_create")) order="webdb_create desc";
110 String whereClause=""; boolean isFirst=true;
111 if (query_text!=null && !query_text.equalsIgnoreCase("")) {
112 whereClause += "lower("+query_field+") like lower('%"+query_text+"%')"; isFirst=false;}
113 if (query_is_published != null && !query_is_published.equals("")) {
114 if (isFirst==false) whereClause+=" and ";
115 whereClause += "is_published='"+query_is_published+"'";
119 //System.out.println("sql-whereclause: " + whereClause + " order: " + order + " offset: " + offset);
121 // fetch und ausliefern
124 if (query_text!=null || query_is_published!=null ) {
125 EntityList theList = mainModule.getByWhereClause(whereClause, order, (new Integer(offset)).intValue());
126 if (theList!=null && theList.size()>0) {
128 //make articleHash for comment
129 StringBuffer buf= new StringBuffer("id in (");boolean first=true;
130 for(int i=0;i<theList.size();i++) {
131 if (first==false) buf.append(",");
133 buf.append(theList.elementAt(i).getValue("to_media"));
136 SimpleHash articleHash = HTMLTemplateProcessor.makeSimpleHash(moduleContent.getByWhereClause(buf.toString(),-1));
137 mergeData.put("articleHash", articleHash);
140 mergeData.put("contentlist",theList);
141 mergeData.put("count", (new Integer(theList.getCount())).toString());
142 mergeData.put("from", (new Integer(theList.getFrom())).toString());
143 mergeData.put("to", (new Integer(theList.getTo())).toString());
144 if (theList.hasNextBatch())
145 mergeData.put("next", (new Integer(theList.getNextBatch())).toString());
146 if (theList.hasPrevBatch())
147 mergeData.put("prev", (new Integer(theList.getPrevBatch())).toString());
151 HTMLTemplateProcessor.process(res, templateListString, mergeData, res.getWriter(), getLocale(req));
153 catch (ModuleException e) {throw new ServletModuleException(e.toString());}
154 catch (IOException e) {throw new ServletModuleException(e.toString());}
155 catch (Exception e) {throw new ServletModuleException(e.toString());}