b85508380ff02fc27d642a8d802b5999dc0fc944
[mir.git] / source / OpenMir.java
1 import java.io.*;
2 import java.util.*;
3 import java.net.*;
4 import java.lang.reflect.*;
5 import javax.servlet.*;
6 import javax.servlet.http.*;
7 import java.sql.*;
8
9 import freemarker.template.*;
10
11 import mir.misc.*;
12 import mir.servlet.*;
13
14 import mircoders.servlet.*;
15 import mircoders.module.*;
16 import mircoders.entity.*;
17 import mircoders.storage.*;
18
19 /**
20  *  OpenMir.java - main servlet for open posting and comment feature to articles
21  *
22  *  @author RK 1999-2001
23  *
24  */
25
26
27 public class OpenMir extends AbstractServlet {
28   
29   //private static boolean                confed=false;
30   private static String lang;
31   public HttpSession session;
32
33   public void doGet(HttpServletRequest req, HttpServletResponse res)
34     throws ServletException, IOException {
35     doPost(req,res);
36   }
37
38   public void doPost(HttpServletRequest req, HttpServletResponse res)
39     throws ServletException, IOException {
40
41     long            startTime = (new java.util.Date()).getTime();
42     long            sessionConnectTime=0;
43
44     // get the configration - this could conflict if 2 mirs are in the
45     // VM maybe? to be checked. -mh
46     if(getServletContext().getAttribute("mir.confed") == null) {
47       getConfig(req);
48     }
49     session = req.getSession();
50
51     if(session.getAttribute("Language")==null){
52       setLanguage(session,getAcceptLanguage(req));
53     }
54
55     res.setContentType("text/html");
56     try {
57       ServletModuleDispatch.dispatch(ServletModuleOpenIndy.getInstance(),req,res);
58     }
59     catch (ServletModuleUserException e) {
60       handleUserError(req,res,res.getWriter(), e.getMsg());
61     }
62     catch (ServletModuleException e){
63       e.printStackTrace();
64       handleError(req,res,res.getWriter(), "OpenIndy :: ServletException in Module ServletModule -- " + e.toString());
65     }
66     // timing...
67     sessionConnectTime = new java.util.Date().getTime() - startTime;
68     theLog.printInfo("EXECTIME (ServletModuleOpenIndy): " + sessionConnectTime + " ms");
69   }
70
71   private void handleUserError(HttpServletRequest req, HttpServletResponse res,
72                                                                                                                          PrintWriter out, String errorString) {
73     try {
74       theLog.printError(errorString);
75       SimpleHash modelRoot = new SimpleHash();
76       modelRoot.put("errorstring", new SimpleScalar(errorString));
77       modelRoot.put("date", new SimpleScalar(StringUtil.date2readableDateTime(new GregorianCalendar())));
78       HTMLTemplateProcessor.process(res,MirConfig.getProp("Mir.UserErrorTemplate"),
79                                                                                                                                                 modelRoot, out, req.getLocale() );
80       out.close();
81     }
82     catch (Exception e) {
83       System.err.println("Fehler in UserErrorTemplate");
84     }
85
86   }
87
88   private void handleError(HttpServletRequest req, HttpServletResponse res,PrintWriter out, String errorString) {
89
90     try {
91       theLog.printError(errorString);
92       SimpleHash modelRoot = new SimpleHash();
93       modelRoot.put("errorstring", new SimpleScalar(errorString));
94       modelRoot.put("date", new SimpleScalar(StringUtil.date2readableDateTime(
95                                                                                                                                                                                          new GregorianCalendar())));
96       HTMLTemplateProcessor.process(res,MirConfig.getProp("Mir.ErrorTemplate"),
97                                                                                                                                                 modelRoot,out, req.getLocale());
98       out.close();
99     }
100     catch (Exception e) {
101       System.err.println("Fehler in ErrorTemplate");
102     }
103
104   }
105
106   public String getServletInfo(){ return "OpenIndy 1.0 rev01"; }
107
108 }
109