coding style cleanup.
[mir.git] / source / Mir.java
index 8ac8b84..1c0de3e 100755 (executable)
@@ -50,8 +50,8 @@ public class Mir extends AbstractServlet
     // get the configration
     if (!confed){
       confed = getConfig(req);
-      MirConfig.setServletName(getServletName());
     }
+    MirConfig.setServletName(getServletName());
 
     session = req.getSession(true);
 
@@ -166,6 +166,9 @@ public class Mir extends AbstractServlet
     catch (InvocationTargetException e) { handleError( res,res.getWriter(), "ServletModule" + moduleName + " target not found."); }
     catch (ClassNotFoundException e) { handleError(res, res.getWriter(), "ServletModule" + moduleName + " not found."); }
     catch (IllegalArgumentException e) { handleError( res,res.getWriter(), "ServletModule" + moduleName + " not found."); }
+    catch (ServletModuleUserException e) {
+      handleUserError(res,res.getWriter(), e.getMsg());
+    }
     catch (ServletModuleException e){ handleError(res,res.getWriter(), "ServletException in Module ServletModule" + moduleName + " -- " + e.toString()); }
     catch (IllegalAccessException e){
         handleError(res,res.getWriter(), "No access to class ServletModule" + moduleName + " -- " + e.toString()); }
@@ -189,6 +192,21 @@ public class Mir extends AbstractServlet
     }
   }
 
+  private void handleUserError(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);
+      out.close();
+    }
+    catch (Exception e) {
+      System.err.println("Fehler in UserErrorTemplate");
+    }
+
+  }
   /**
    *  evaluate login for user / password
    */
@@ -196,8 +214,11 @@ public class Mir extends AbstractServlet
     try {
       if (usersModule == null) usersModule = new ModuleUsers(DatabaseUsers.getInstance());
       return usersModule.getUserForLogin(user, password);
+    } catch(Exception e) {
+      theLog.printDebugInfo(e.toString());
+      e.printStackTrace();
+      return null;
     }
-    catch(Exception e) { theLog.printDebugInfo(e.toString()); return null; }
   }
 
   // Redirect-methods
@@ -225,7 +246,7 @@ public class Mir extends AbstractServlet
       // merge with logged in user and messages
       SimpleHash mergeData = new SimpleHash();
       mergeData.put("session",sessionUrl);
-      mergeData.put("login_user", HTMLTemplateProcessor.makeSimpleHash(userEntity));
+      mergeData.put("login_user", userEntity);
       if (messageModule == null) messageModule = new ModuleMessage(DatabaseMessages.getInstance());
       mergeData.put("messages", HTMLTemplateProcessor.makeSimpleList(messageModule.getByWhereClause(null, "webdb_create desc",0,10)));
       HTMLTemplateProcessor.process(res,getLanguage(req,session)+"/"+startTemplate, mergeData,out);