Explicitly mark perms.sh-dist as a bash script.
[mir.git] / source / Mir.java
index 7fdcd32..011b1f9 100755 (executable)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2001, 2002 The Mir-coders group
+ * Copyright (C) 2001-2006 The Mir-coders group
  *
  * This file is part of Mir.
  *
@@ -19,8 +19,6 @@
  *
  * In addition, as a special exception, The Mir-coders gives permission to link
  * the code of this program with  any library licensed under the Apache Software License,
- * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
- * (or with modified versions of the above that use the same license as the above),
  * and distribute linked combinations including the two.  You must obey the
  * GNU General Public License in all respects for all of the code used other than
  * the above mentioned libraries.  If you modify this file, you may extend this
 
 import mir.bundle.Bundle;
 import mir.config.MirPropertiesConfiguration;
-import mir.log.LoggerWrapper;
-import mir.servlet.*;
-import mir.util.StringRoutines;
+import mir.servlet.AbstractServlet;
+import mir.servlet.AdminServletModule;
+import mir.servlet.ServletModuleExc;
+import mir.servlet.ServletModuleUserExc;
 import mir.util.ExceptionRoutines;
+import mir.util.StringRoutines;
+import mircoders.entity.EntityUsers;
+import mircoders.global.MirGlobal;
+import mircoders.module.ModuleUsers;
+import mircoders.servlet.ServletHelper;
 import multex.Failure;
 
 import javax.servlet.ServletConfig;
 import javax.servlet.ServletException;
 import javax.servlet.UnavailableException;
-import javax.servlet.http.*;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+import javax.servlet.http.HttpSessionBindingEvent;
+import javax.servlet.http.HttpSessionBindingListener;
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.io.StringWriter;
-import java.lang.reflect.Method;
-import java.util.*;
-
-import mircoders.module.ModuleUsers;
-import mircoders.global.MirGlobal;
-import mircoders.servlet.ServletHelper;
-import mircoders.entity.EntityUsers;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.GregorianCalendar;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
 
 public class Mir extends AbstractServlet {
   private static ModuleUsers usersModule = null;
-  private final static Map servletModuleInstanceHash = new HashMap();
   private static Locale fallbackLocale = null;
 
   private static List loginLanguages = null;
@@ -153,9 +162,7 @@ public class Mir extends AbstractServlet {
       return user;
     }
     catch (Throwable t) {
-      t.printStackTrace();
-
-      throw new ServletException(t.toString());
+      throw new ServletException(t.getMessage());
     }
   }
 
@@ -191,7 +198,6 @@ public class Mir extends AbstractServlet {
           moduleName="Admin";
         }
 
-
         if (moduleName.equals("login")) {
           String target = (String) session.getAttribute("login.target");
 
@@ -210,8 +216,8 @@ public class Mir extends AbstractServlet {
         }
         else {
           try {
-            ServletModule servletModule = getServletModuleForName(moduleName);
-            ServletModuleDispatch.dispatch(servletModule, aRequest, aResponse);
+            AdminServletModule servletModule = getServletModuleForName(moduleName);
+            servletModule.handleRequest(aRequest, aResponse);
 
             sessionConnectTime = System.currentTimeMillis() - startTime;
             logger.info("EXECTIME (" + moduleName + "): " + sessionConnectTime + " ms");
@@ -231,8 +237,6 @@ public class Mir extends AbstractServlet {
       }
     }
     catch (Throwable t) {
-      t.printStackTrace(logger.asPrintWriter(LoggerWrapper.DEBUG_MESSAGE));
-
       throw new ServletException(t.toString());
     }
   }
@@ -240,42 +244,12 @@ public class Mir extends AbstractServlet {
   /**
    * caching routine to get a module for a module name
    *
-   * @param moduleName the module name
+   * @param aModuleName the module name
    * @return the requested module
    * @throws ServletModuleExc
    */
-
-  private static ServletModule getServletModuleForName(String moduleName) throws ServletModuleExc {
-    // Instance in Map ?
-    if (!servletModuleInstanceHash.containsKey(moduleName)) {
-      // was not found in hash...
-      try {
-        Class theServletModuleClass = null;
-
-        try {
-          // first we try to get ServletModule from stern.che3.servlet
-          theServletModuleClass =
-            Class.forName("mircoders.servlet.ServletModule" + moduleName);
-        }
-        catch (ClassNotFoundException e) {
-          // on failure, we try to get it from lib-layer
-          theServletModuleClass =
-            Class.forName("mir.servlet.ServletModule" + moduleName);
-        }
-
-        Method m = theServletModuleClass.getMethod("getInstance", null);
-        ServletModule smod = (ServletModule) m.invoke(null, null);
-
-        // we put it into map for further reference
-        servletModuleInstanceHash.put(moduleName, smod);
-
-        return smod;
-      }
-      catch (Exception e) {
-        throw new ServletModuleExc("*** error resolving classname for " + moduleName + " -- " + e.getMessage());
-      }
-    }
-               return (ServletModule) servletModuleInstanceHash.get(moduleName);
+  private static AdminServletModule getServletModuleForName(String aModuleName) throws ServletModuleExc {
+    return ServletHelper.getServletModule(aModuleName);
   }
 
   private void handleUserError(HttpServletRequest aRequest, HttpServletResponse aResponse, ServletModuleUserExc anException) {