fe9e1c96e3530cf9297987f11be7f623659340d0
[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 Logfile                theLog;
30   private static boolean                confed=false;
31   private static String lang;
32   public HttpSession session;
33
34   public void doGet(HttpServletRequest req, HttpServletResponse res)
35     throws ServletException, IOException {
36     doPost(req,res);
37   }
38
39   public void doPost(HttpServletRequest req, HttpServletResponse res)
40     throws ServletException, IOException {
41
42     long            startTime = (new java.util.Date()).getTime();
43     long            sessionConnectTime=0;
44
45     session = req.getSession(true);
46     
47     if (!confed){
48       confed = getConfig(req);
49     }
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 (ServletModuleException e){ handleError(res,res.getWriter(), "OpenIndy :: ServletException in Module ServletModule -- " + e.toString()); }
60     // timing...
61     sessionConnectTime = new java.util.Date().getTime() - startTime;
62     theLog.printInfo("EXECTIME (ServletModuleOpenIndy): " + sessionConnectTime + " ms");
63   }
64
65   private void handleError(HttpServletResponse res,PrintWriter out, String errorString) {
66
67     try {
68       theLog.printError(errorString);
69       SimpleHash modelRoot = new SimpleHash();
70       modelRoot.put("errorstring", new SimpleScalar(errorString));
71       modelRoot.put("date", new SimpleScalar(StringUtil.date2readableDateTime(new GregorianCalendar())));
72       HTMLTemplateProcessor.process(res,Configuration.getProperty("Mir.ErrorTemplate"),modelRoot,out);
73       out.close();
74     }
75     catch (Exception e) {
76       System.err.println("Fehler in ErrorTemplate");
77     }
78
79   }
80
81   public String getServletInfo(){ return "OpenIndy 1.0 rev01"; }
82
83 }
84