Initial revision
[mir.git] / source / mircoders / servlet / ServletModuleBreaking.java
1 package mircoders.servlet;
2
3 import java.io.*;
4 import java.net.*;
5 import javax.servlet.http.*;
6 import javax.servlet.*;
7 import freemarker.template.*;
8 import webdb.servlet.*;
9 import webdb.misc.*;
10 import webdb.entity.*;
11 import webdb.storage.*;
12 import webdb.module.*;
13 import mir.module.*;
14 import mir.storage.*;
15
16 /*
17  *  ServletModuleBreaking -
18  *  Authentified Navigation for Breaking News
19  *
20  *
21  */
22
23 public class ServletModuleBreaking extends ServletModule
24 {
25
26         // Singelton / Kontruktor
27
28         private static ServletModuleBreaking instance = new ServletModuleBreaking();
29         public static ServletModule getInstance() { return instance; }
30
31         private ServletModuleBreaking() {
32
33                 theLog = Logfile.getInstance(Configuration.getProperty("Home") + Configuration.getProperty("ServletModule.Breaking.Logfile"));
34                 templateListString = Configuration.getProperty("ServletModule.Breaking.ListTemplate");
35                 templateObjektString = Configuration.getProperty("ServletModule.Breaking.ObjektTemplate");
36                 templateConfirmString = Configuration.getProperty("ServletModule.Breaking.ConfirmTemplate");
37                 try {
38                         mainModule = new ModuleBreaking(DatabaseBreaking.getInstance());
39                 }
40                 catch (StorageObjectException e) {
41                         theLog.printDebugInfo("ServletModuleBreaking konnte nicht initialisiert werden");
42                 }
43         }
44
45         public void list(HttpServletRequest req, HttpServletResponse res)
46                 throws ServletModuleException
47         {
48                 // fetch and deliver
49                 try {
50                         SimpleHash mergeData = new SimpleHash();
51                         String offset = req.getParameter("offset");
52                         if (offset==null || offset.equals("")) offset="0";
53                         mergeData.put("offset",offset);
54                         EntityList theList = mainModule.getByWhereClause(null, "webdb_create desc", (new Integer(offset)).intValue());
55                         mergeData.put("contentlist",HTMLTemplateProcessor.makeSimpleList(theList));
56                         if(theList.getOrder()!=null) {
57                                 mergeData.put("order", theList.getOrder());
58                                 mergeData.put("order_encoded", URLEncoder.encode(theList.getOrder()));
59                         }
60                         mergeData.put("count", (new Integer(theList.getCount())).toString());
61                         mergeData.put("from", (new Integer(theList.getFrom())).toString());
62                         mergeData.put("to", (new Integer(theList.getTo())).toString());
63                         if (theList.hasNextBatch())
64                                 mergeData.put("next", (new Integer(theList.getNextBatch())).toString());
65                         if (theList.hasPrevBatch())
66                                 mergeData.put("prev", (new Integer(theList.getPrevBatch())).toString());
67
68                         // raus damit
69                         HTMLTemplateProcessor.process(getLanguage(req)+"/"+templateListString, mergeData, res.getWriter());
70                 }
71                 catch (ModuleException e) {throw new ServletModuleException(e.toString());}
72                 catch (IOException e) {throw new ServletModuleException(e.toString());}
73                 catch (Exception e) {throw new ServletModuleException(e.toString());}
74         }
75 }