Modified config system:
[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(MirConfig.getProp("Home") + MirConfig.getProp("ServletModule.LinksImcs.Logfile"));
39     templateListString = MirConfig.getProp("ServletModule.LinksImcs.ListTemplate");
40     templateObjektString = MirConfig.getProp("ServletModule.LinksImcs.ObjektTemplate");
41     templateConfirmString = MirConfig.getProp("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("to_parent_id=NULL", offset);
58       modelRoot.put("new", "1");
59       modelRoot.put("contentlist",HTMLTemplateProcessor.makeSimpleList(theList));
60
61       if (theList == null || theList.getCount() == 0 || theList.getCount()>1){
62         HTMLTemplateProcessor.process(res,getLanguage(req)+"/"+templateObjektString, modelRoot, res.getWriter());
63
64       } else {
65         deliver(req, res, modelRoot, templateObjektString);
66       }
67
68     } catch(ModuleException e) {
69       throw new ServletModuleException(e.toString());
70     } catch (HTMLParseException e) {
71       throw new ServletModuleException(e.toString());
72     } catch (IOException e) {
73       throw new ServletModuleException(e.toString());
74     } catch(StorageObjectException e) {
75       throw new ServletModuleException(e.toString());
76     }
77
78
79   }
80 }
81