4 import java.lang.reflect.*;
5 import javax.servlet.*;
6 import javax.servlet.http.*;
9 import freemarker.template.*;
14 import mircoders.servlet.*;
15 import mircoders.module.*;
16 import mircoders.entity.*;
17 import mircoders.storage.*;
20 * OpenMir.java - main servlet for open posting and comment feature to articles
22 * @author RK 1999-2001
27 public class OpenMir extends AbstractServlet {
29 //private static boolean confed=false;
30 private static String lang;
31 public HttpSession session;
33 public void doGet(HttpServletRequest req, HttpServletResponse res)
34 throws ServletException, IOException {
38 public void doPost(HttpServletRequest req, HttpServletResponse res)
39 throws ServletException, IOException {
41 long startTime = (new java.util.Date()).getTime();
42 long sessionConnectTime=0;
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) {
49 session = req.getSession();
51 if(session.getAttribute("Language")==null){
52 if (req.getParameter("language")!=null) {
53 setLanguage(session, req.getParameter("language"));
56 setLanguage(session, getAcceptLanguage(req));
60 if (req.getParameter("language")!=null)
61 setLocale(session, new Locale(req.getParameter("language"), "") );
63 res.setContentType("text/html");
65 ServletModuleDispatch.dispatch(ServletModuleOpenIndy.getInstance(),req,res);
67 catch (ServletModuleUserException e) {
68 handleUserError(req,res,res.getWriter(), e.getMsg());
70 catch (ServletModuleException e){
72 handleError(req,res,res.getWriter(), "OpenIndy :: ServletException in Module ServletModule -- " + e.toString());
75 sessionConnectTime = new java.util.Date().getTime() - startTime;
76 theLog.printInfo("EXECTIME (ServletModuleOpenIndy): " + sessionConnectTime + " ms");
79 private void handleUserError(HttpServletRequest req, HttpServletResponse res,
80 PrintWriter out, String errorString) {
82 theLog.printError(errorString);
83 SimpleHash modelRoot = new SimpleHash();
84 modelRoot.put("errorstring", new SimpleScalar(errorString));
85 modelRoot.put("date", new SimpleScalar(StringUtil.date2readableDateTime(new GregorianCalendar())));
86 HTMLTemplateProcessor.process(res,MirConfig.getProp("Mir.UserErrorTemplate"),
87 modelRoot, out, req.getLocale() );
91 System.err.println("Fehler in UserErrorTemplate");
96 private void handleError(HttpServletRequest req, HttpServletResponse res,PrintWriter out, String errorString) {
99 theLog.printError(errorString);
100 SimpleHash modelRoot = new SimpleHash();
101 modelRoot.put("errorstring", new SimpleScalar(errorString));
102 modelRoot.put("date", new SimpleScalar(StringUtil.date2readableDateTime(
103 new GregorianCalendar())));
104 HTMLTemplateProcessor.process(res,MirConfig.getProp("Mir.ErrorTemplate"),
105 modelRoot,out, req.getLocale());
108 catch (Exception e) {
109 System.err.println("Fehler in ErrorTemplate");
114 public String getServletInfo(){ return "OpenIndy 1.0 rev01"; }