*/
-public class OpenMir extends AbstractServlet
-{
- private static Logfile theLog;
- private static boolean confed=false;
- private static String lang;
+public class OpenMir extends AbstractServlet {
- public void doGet(HttpServletRequest req, HttpServletResponse res)
- throws ServletException, IOException {
- doPost(req,res);
- }
+ //private static boolean confed=false;
+ private static String lang;
+ public HttpSession session;
- public void doPost(HttpServletRequest req, HttpServletResponse res)
- throws ServletException, IOException {
+ public void doGet(HttpServletRequest req, HttpServletResponse res)
+ throws ServletException, IOException {
+ doPost(req,res);
+ }
- long startTime = (new java.util.Date()).getTime();
- long sessionConnectTime=0;
+ public void doPost(HttpServletRequest req, HttpServletResponse res)
+ throws ServletException, IOException {
- if (!confed){
- confed = getConfig(req);
+ long startTime = (new java.util.Date()).getTime();
+ long sessionConnectTime=0;
+
+ // get the configration - this could conflict if 2 mirs are in the
+ // VM maybe? to be checked. -mh
+ if(getServletContext().getAttribute("mir.confed") == null) {
+ getConfig(req);
}
+ session = req.getSession();
- HttpSession session = req.getSession(true);
if(session.getAttribute("Language")==null){
- setLanguage(req,getAcceptLanguage(req));
+ if (req.getParameter("language")!=null) {
+ setLanguage(session, req.getParameter("language"));
+ }
+ else {
+ setLanguage(session, getAcceptLanguage(req));
+ }
+ }
+
+ if (req.getParameter("language")!=null)
+ setLocale(session, new Locale(req.getParameter("language"), "") );
+
+ res.setContentType("text/html");
+ try {
+ ServletModuleDispatch.dispatch(ServletModuleOpenIndy.getInstance(),req,res);
+ }
+ catch (ServletModuleUserException e) {
+ handleUserError(req,res,res.getWriter(), e.getMsg());
+ }
+ catch (ServletModuleException e){
+ e.printStackTrace();
+ handleError(req,res,res.getWriter(), "OpenIndy :: ServletException in Module ServletModule -- " + e.toString());
+ }
+ // timing...
+ sessionConnectTime = new java.util.Date().getTime() - startTime;
+ theLog.printInfo("EXECTIME (ServletModuleOpenIndy): " + sessionConnectTime + " ms");
+ }
+
+ private void handleUserError(HttpServletRequest req, HttpServletResponse res,
+ PrintWriter out, String errorString) {
+ try {
+ theLog.printError(errorString);
+ SimpleHash modelRoot = new SimpleHash();
+ modelRoot.put("errorstring", new SimpleScalar(errorString));
+ modelRoot.put("date", new SimpleScalar(StringUtil.date2readableDateTime(new GregorianCalendar())));
+ HTMLTemplateProcessor.process(res,MirConfig.getProp("Mir.UserErrorTemplate"),
+ modelRoot, out, req.getLocale() );
+ out.close();
}
+ catch (Exception e) {
+ System.err.println("Fehler in UserErrorTemplate");
+ }
+
+ }
+
+ private void handleError(HttpServletRequest req, HttpServletResponse res,PrintWriter out, String errorString) {
+
+ try {
+ theLog.printError(errorString);
+ SimpleHash modelRoot = new SimpleHash();
+ modelRoot.put("errorstring", new SimpleScalar(errorString));
+ modelRoot.put("date", new SimpleScalar(StringUtil.date2readableDateTime(
+ new GregorianCalendar())));
+ HTMLTemplateProcessor.process(res,MirConfig.getProp("Mir.ErrorTemplate"),
+ modelRoot,out, req.getLocale());
+ out.close();
+ }
+ catch (Exception e) {
+ System.err.println("Fehler in ErrorTemplate");
+ }
+
+ }
- res.setContentType("text/html");
- try {
- ServletModuleDispatch.dispatch(ServletModuleOpenIndy.getInstance(),req,res);
- }
- catch (ServletModuleException e){ handleError(res.getWriter(), "OpenIndy :: ServletException in Module ServletModule -- " + e.toString()); }
- // timing...
- sessionConnectTime = new java.util.Date().getTime() - startTime;
- theLog.printInfo("EXECTIME (ServletModuleOpenIndy): " + sessionConnectTime + " ms");
- }
-
- private void handleError(PrintWriter out, String errorString) {
-
- try {
- theLog.printError(errorString);
- SimpleHash modelRoot = new SimpleHash();
- modelRoot.put("errorstring", new SimpleScalar(errorString));
- modelRoot.put("date", new SimpleScalar(StringUtil.date2readableDateTime(new GregorianCalendar())));
- HTMLTemplateProcessor.process(Configuration.getProperty("Mir.ErrorTemplate"),modelRoot,out);
- out.close();
- }
- catch (Exception e) {
- System.err.println("Fehler in ErrorTemplate");
- }
-
- }
-
- public String getServletInfo(){ return "OpenIndy 1.0 rev01"; }
+ public String getServletInfo(){ return "OpenIndy 1.0 rev01"; }
}