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; charset="
64 +MirConfig.getProp("Mir.DefaultEncoding"));
66 ServletModuleDispatch.dispatch(ServletModuleOpenIndy.getInstance(),req,res);
68 catch (ServletModuleUserException e) {
69 handleUserError(req,res,res.getWriter(), e.getMsg());
71 catch (ServletModuleException e){
73 handleError(req,res,res.getWriter(), "OpenIndy :: ServletException in Module ServletModule -- " + e.toString());
76 sessionConnectTime = new java.util.Date().getTime() - startTime;
77 theLog.printInfo("EXECTIME (ServletModuleOpenIndy): " + sessionConnectTime + " ms");
80 private void handleUserError(HttpServletRequest req, HttpServletResponse res,
81 PrintWriter out, String errorString) {
83 theLog.printError(errorString);
84 SimpleHash modelRoot = new SimpleHash();
85 modelRoot.put("errorstring", new SimpleScalar(errorString));
86 modelRoot.put("date", new SimpleScalar(StringUtil.date2readableDateTime(new GregorianCalendar())));
87 HTMLTemplateProcessor.process(res,MirConfig.getProp("Mir.UserErrorTemplate"),
88 modelRoot, out, req.getLocale() );
92 System.err.println("Fehler in UserErrorTemplate");
97 private void handleError(HttpServletRequest req, HttpServletResponse res,PrintWriter out, String errorString) {
100 theLog.printError(errorString);
101 SimpleHash modelRoot = new SimpleHash();
102 modelRoot.put("errorstring", new SimpleScalar(errorString));
103 modelRoot.put("date", new SimpleScalar(StringUtil.date2readableDateTime(
104 new GregorianCalendar())));
105 HTMLTemplateProcessor.process(res,MirConfig.getProp("Mir.ErrorTemplate"),
106 modelRoot,out, req.getLocale());
109 catch (Exception e) {
110 System.err.println("Fehler in ErrorTemplate");
115 public String getServletInfo(){
116 return "OpenMir "+MirConfig.getProp("Mir.Version");