Initial revision
[mir.git] / source / mircoders / servlet / ServletModuleUsers.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 webdb.servlet.*;
12 import webdb.module.*;
13 import webdb.misc.*;
14 import webdb.entity.*;
15 import webdb.storage.*;
16
17 import mir.entity.*;
18 import mir.storage.*;
19 import mir.module.*;
20
21 /*
22  *  ServletModuleUsers -
23  *  liefert HTML fuer Users
24  *
25  *
26  * @author RK
27  */
28
29 public class ServletModuleUsers extends webdb.servlet.ServletModule
30 {
31         // Singelton / Kontruktor
32         private static ServletModuleUsers instance = new ServletModuleUsers();
33         public static ServletModule getInstance() { return instance; }
34
35         private ServletModuleUsers() {
36         theLog = Logfile.getInstance(Configuration.getProperty("Home") + Configuration.getProperty("ServletModule.Users.Logfile"));
37         templateListString = Configuration.getProperty("ServletModule.Users.ListTemplate");
38         templateObjektString = Configuration.getProperty("ServletModule.Users.ObjektTemplate");
39         templateConfirmString = Configuration.getProperty("ServletModule.Users.ConfirmTemplate");
40                                 try {
41                                         mainModule = new ModuleUsers(DatabaseUsers.getInstance());
42                                 }
43                                 catch (StorageObjectException e) {
44                                         theLog.printDebugInfo("servletmoduleusers konnte nicht initialisiert werden");
45                                 }
46         }
47
48         public void edit(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException
49         {
50                 String        idParam = req.getParameter("id");
51                 if (idParam == null) throw new ServletModuleException("Falscher Aufruf: (id) nicht angegeben");
52                  try {
53                         //theLog.printInfo("Showing User with id: " + idParam);
54                         SimpleHash mergeData =  HTMLTemplateProcessor.makeSimpleHash(mainModule.getById(idParam));
55                         deliver(req, res, mergeData, templateObjektString);
56                 }
57                 catch (ModuleException e) { throw new ServletModuleException(e.toString());}
58         }
59
60         public void add(HttpServletRequest req, HttpServletResponse res)
61                 throws ServletModuleException
62         {
63                 try {
64                         SimpleHash mergeData = new SimpleHash();
65                         mergeData.put("new", "1");
66                         deliver(req, res, mergeData, templateObjektString);
67                 }
68                 catch (Exception e) { throw new ServletModuleException(e.toString());}
69         }
70
71  public void insert(HttpServletRequest req, HttpServletResponse res)
72         throws ServletModuleException
73         {
74                 try {
75                         HashMap withValues = getIntersectingValues(req, mainModule.getStorageObject());
76                         String id = mainModule.add(withValues);
77                         SimpleHash mergeData = HTMLTemplateProcessor.makeSimpleHash(mainModule.getById(id));
78                         deliver(req, res, mergeData, templateObjektString);
79                 }
80                 catch (Exception e) { throw new ServletModuleException(e.toString());}
81         }
82 }