added Hidden articles servlet module
[mir.git] / source / mircoders / servlet / ServletModuleHidden.java
1 package mircoders.servlet;
2
3 import java.io.*;
4 import java.sql.*;
5 import java.util.*;
6 import java.net.*;
7 import javax.servlet.*;
8 import javax.servlet.http.*;
9
10 import freemarker.template.*;
11
12 import mir.servlet.*;
13 import mir.module.*;
14 import mir.misc.*;
15 import mir.entity.*;
16 import mir.storage.*;
17
18 import mir.entity.*;
19 import mircoders.storage.*;
20 import mircoders.module.*;
21
22 /*
23  *  ServletModuleHidden - output of so called "censored" articles
24  *  @author mh
25  *  @version $Id
26  *
27  */
28
29 public class ServletModuleHidden extends ServletModule
30 {
31
32         // Singelton / Kontruktor
33         private static ServletModuleHidden instance = new ServletModuleHidden();
34         public static ServletModule getInstance() { return instance; }
35
36         private ServletModuleHidden() {
37                 theLog = Logfile.getInstance(MirConfig.getProp("Home") + MirConfig.getProp("ServletModule.Hidden.Logfile"));
38                 templateListString = MirConfig.getProp("ServletModule.Hidden.ListTemplate");
39                 try {
40                         mainModule = new ModuleContent(DatabaseContent.getInstance());
41                 }
42                 catch (StorageObjectException e) {
43                         theLog.printError("servletmoduleHidden could not be initialized");
44                 }
45         }
46
47
48         public void list(HttpServletRequest req, HttpServletResponse res)
49                 throws ServletModuleException
50         {
51                         // Parameter auswerten
52                         SimpleHash mergeData = new SimpleHash();
53       String query_year = req.getParameter("year"); 
54       String query_month = req.getParameter("month"); 
55       String order = "webdb_create";
56
57                         // sql basteln
58       String whereClause = "is_published=false AND webdb_create LIKE '"+
59                             query_year+"-"+query_month+"%'";
60
61                         theLog.printDebugInfo("sql-whereclause: " + whereClause);
62
63                         // fetch und ausliefern
64                         try {
65
66                                 if ((query_year!=null && !query_year.equals("")) 
67             && (query_month!=null && !query_month.equals(""))) {
68           EntityList theList = mainModule.getByWhereClause(whereClause, order, -1);
69                                         if (theList!=null && theList.size()>0) {
70
71                                                 //make articleHash for comment
72                                                 StringBuffer buf= new StringBuffer("id in (");boolean first=true;
73                                                 for(int i=0;i<theList.size();i++) {
74                                                         if (first==false) buf.append(",");
75                                                         first=false;
76                                                         buf.append(theList.elementAt(i).getValue("to_media"));
77                                                 }
78                                                 buf.append(")");
79                                                 SimpleHash articleHash =
80                 HTMLTemplateProcessor.makeSimpleHash(
81                  mainModule.getByWhereClause(buf.toString(),-1));
82                                                 mergeData.put("articleHash", articleHash);
83
84             // send the year and month for use in the list template
85             mergeData.put("year", query_year);
86             mergeData.put("month", query_month);
87                                                 // get comment
88                                                 mergeData.put("contentlist",theList);
89                                         }
90                                 }
91                                 // raus damit
92                                 HTMLTemplateProcessor.process(res, templateListString, mergeData, res.getWriter(), getLocale(req));
93                         }
94                         catch (ModuleException e) {throw new ServletModuleException(e.toString());}
95                         catch (IOException e) {throw new ServletModuleException(e.toString());}
96                         catch (Exception e) {throw new ServletModuleException(e.toString());}
97         }
98 }