1 package mircoders.servlet;
7 import javax.servlet.*;
8 import javax.servlet.http.*;
10 import freemarker.template.*;
19 import mircoders.storage.*;
20 import mircoders.module.*;
23 * ServletModuleComment - controls navigation for Comments
29 public class ServletModuleComment extends ServletModule
32 private ModuleContent moduleContent;
34 // Singelton / Kontruktor
35 private static ServletModuleComment instance = new ServletModuleComment();
36 public static ServletModule getInstance() { return instance; }
38 private ServletModuleComment() {
39 theLog = Logfile.getInstance(this.getClass().getName());
40 templateListString = MirConfig.getProp("ServletModule.Comment.ListTemplate");
41 templateObjektString = MirConfig.getProp("ServletModule.Comment.ObjektTemplate");
42 templateConfirmString = MirConfig.getProp("ServletModule.Comment.ConfirmTemplate");
44 mainModule = new ModuleComment(DatabaseComment.getInstance());
45 moduleContent = new ModuleContent(DatabaseContent.getInstance());
47 catch (StorageObjectException e) {
48 theLog.printError("servletmodule: comment could not be initialized");
53 public void list(HttpServletRequest req, HttpServletResponse res)
54 throws ServletModuleException
56 // Parameter auswerten
57 SimpleHash mergeData = new SimpleHash();
58 String query_text = req.getParameter("query_text");
59 mergeData.put("query_text",query_text);
60 if (query_text!=null) mergeData.put("query_text_encoded",URLEncoder.encode(query_text));
61 String query_field = req.getParameter("query_field");
62 mergeData.put("query_field",query_field);
63 String query_is_published = req.getParameter("query_is_published");
64 mergeData.put("query_is_published",query_is_published);
66 String offset = req.getParameter("offset");
67 if (offset==null || offset.equals("")) offset="0";
68 mergeData.put("offset",offset);
71 String order = req.getParameter("order");
73 mergeData.put("order", order);
74 mergeData.put("order_encoded", URLEncoder.encode(order));
75 if (order.equals("webdb_create")) order="webdb_create desc";
79 String whereClause=""; boolean isFirst=true;
80 if (query_text!=null && !query_text.equalsIgnoreCase("")) {
81 whereClause += "lower("+query_field+") like lower('%"+query_text+"%')"; isFirst=false;}
82 if (query_is_published != null && !query_is_published.equals("")) {
83 if (isFirst==false) whereClause+=" and ";
84 whereClause += "is_published='"+query_is_published+"'";
88 theLog.printDebugInfo("sql-whereclause: " + whereClause + " order: " + order + " offset: " + offset);
90 // fetch und ausliefern
93 if (query_text!=null || query_is_published!=null ) {
94 EntityList theList = mainModule.getByWhereClause(whereClause, order, (new Integer(offset)).intValue());
97 //make articleHash for comment
98 StringBuffer buf= new StringBuffer("id in (");boolean first=true;
99 for(int i=0;i<theList.size();i++) {
100 if (first==false) buf.append(",");
102 buf.append(theList.elementAt(i).getValue("to_media"));
105 SimpleHash articleHash = HTMLTemplateProcessor.makeSimpleHash(moduleContent.getByWhereClause(buf.toString(),-1));
106 mergeData.put("articleHash", articleHash);
109 mergeData.put("contentlist",HTMLTemplateProcessor.makeSimpleList(theList));
110 mergeData.put("count", (new Integer(theList.getCount())).toString());
111 mergeData.put("from", (new Integer(theList.getFrom())).toString());
112 mergeData.put("to", (new Integer(theList.getTo())).toString());
113 if (theList.hasNextBatch())
114 mergeData.put("next", (new Integer(theList.getNextBatch())).toString());
115 if (theList.hasPrevBatch())
116 mergeData.put("prev", (new Integer(theList.getPrevBatch())).toString());
120 HTMLTemplateProcessor.process(res,getLanguage(req)+"/"+templateListString, mergeData, res.getWriter());
122 catch (ModuleException e) {throw new ServletModuleException(e.toString());}
123 catch (IOException e) {throw new ServletModuleException(e.toString());}
124 catch (Exception e) {throw new ServletModuleException(e.toString());}