no message
[mir.git] / source / mircoders / servlet / ServletModuleLinksImcs.java
1 package mircoders.servlet;
2
3 import java.io.*;
4 import java.sql.*;
5 import java.util.*;
6 import javax.servlet.*;
7 import javax.servlet.http.*;
8
9 import freemarker.template.*;
10
11 import mir.servlet.*;
12 import mir.module.*;
13 import mir.misc.*;
14 import mir.entity.*;
15 import mir.storage.*;
16 import  mir.servlet.ServletModuleException;
17
18 import mircoders.entity.*;
19 import mircoders.storage.*;
20 import mircoders.module.*;
21
22 /*
23  *  ServletModuleLinksImcs -
24  *  liefert HTML fuer LinksImcs
25  *
26  *
27  * @author RK
28  */
29
30 public class ServletModuleLinksImcs extends ServletModule
31 {
32   // Singelton / Kontruktor
33   private static ServletModuleLinksImcs instance = new ServletModuleLinksImcs();
34   public static ServletModule getInstance() { return instance; }
35
36
37   private ServletModuleLinksImcs() {
38     theLog = Logfile.getInstance(Configuration.getProperty("Home") + Configuration.getProperty("ServletModule.LinksImcs.Logfile"));
39     templateListString = Configuration.getProperty("ServletModule.LinksImcs.ListTemplate");
40     templateObjektString = Configuration.getProperty("ServletModule.LinksImcs.ObjektTemplate");
41     templateConfirmString = Configuration.getProperty("ServletModule.LinksImcs.ConfirmTemplate");
42
43     try {
44       mainModule = new ModuleLinksImcs(DatabaseLinksImcs.getInstance());
45     } catch (StorageObjectException e) {
46       theLog.printDebugInfo("ServletModuleLinksImcs konnte nicht initialisiert werden");
47     }
48   }
49
50   public void add(HttpServletRequest req, HttpServletResponse res)
51     throws ServletModuleException {
52     try {
53       SimpleHash modelRoot = new SimpleHash();
54       EntityList   theList;
55       int offset = 0;
56
57       theList = mainModule.getByWhereClause("", offset);
58       modelRoot.put("new", "1");
59       modelRoot.put("contentlist",HTMLTemplateProcessor.makeSimpleList(theList));
60       //modelRoot.put("contentlist", DatabaseLinksImcs.getInstance().getHashData());
61       PrintWriter out = res.getWriter();
62
63       if (theList == null || theList.getCount() == 0 || theList.getCount()>1){
64         //HTMLTemplateProcessor.process(getLanguage(req)+"/"+templateObjektString, theList, out);
65         HTMLTemplateProcessor.process(getLanguage(req)+"/"+templateObjektString, modelRoot, out);
66
67       } else {
68         //deliver(req, res, theList.elementAt(0), templateObjektString);
69         deliver(req, res, modelRoot, templateObjektString);
70       }
71
72     } catch(ModuleException e) {
73       throw new ServletModuleException(e.toString());
74     } catch (HTMLParseException e) {
75       throw new ServletModuleException(e.toString());
76     } catch (IOException e) {
77       throw new ServletModuleException(e.toString());
78     } catch(StorageObjectException e) {
79       throw new ServletModuleException(e.toString());
80     }
81
82
83   }
84 }
85