Ok, big merge. here's the new xml-config stuff in action. There's a few
[mir.git] / source / mir / servlet / AbstractServlet.java
index 1a19445..53e75c6 100755 (executable)
@@ -5,9 +5,11 @@ import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpSession;
 import java.io.File;
 import java.util.Locale;
+import java.util.HashMap;
 
 import mir.misc.HTMLTemplateProcessor;
-import mir.misc.Configuration;
+import mir.misc.StringUtil;
+import mir.misc.MirConfig;
 import mir.misc.Logfile;
 
 /**
@@ -24,12 +26,23 @@ public abstract class AbstractServlet extends HttpServlet {
   protected static Logfile theLog;
 
   /**
-   * get the configration
+   * the configration
    */
   protected boolean getConfig(HttpServletRequest req) {
-    Configuration.initConfig(getInitParameter("Config"));
-    theLog = Logfile.getInstance(Configuration.getProperty("Home") + Configuration.getProperty("Mir.Logfile"));
-    theLog.printInfo(super.getServletName() + " started.");
+
+    String RealPath = super.getServletContext().getRealPath("/");
+    String Uri = req.getRequestURI();
+    String Name = super.getServletName();
+    String RootUri = StringUtil.replace(Uri, "/servlet/" + Name, "");
+
+    // init config
+    MirConfig.initConfig(RealPath, RootUri, Name, getInitParameter("Config"));
+
+    theLog = Logfile.getInstance(this.getClass().getName());
+    theLog.printInfo(Name + " started.");
+    theLog.printInfo("Path is: " + MirConfig.getProp("Home"));
+    theLog.printInfo("Root URI is: " + MirConfig.getProp("RootUri"));
+    theLog.printInfo("Lang is: " + MirConfig.getProp("StandardLanguage"));
     return true;
   }
 
@@ -41,11 +54,11 @@ public abstract class AbstractServlet extends HttpServlet {
   }
 
   /**
-   * Get the session-binded language
+   * Get the session-bound language
    */
   protected String getLanguage(HttpServletRequest req, HttpSession session){
     String lang = (String)session.getAttribute("Language");
-    if(lang==null || lang==""){
+    if(lang==null || lang.equals("")){
       return getAcceptLanguage(req);
     } else {
       return lang;
@@ -53,8 +66,8 @@ public abstract class AbstractServlet extends HttpServlet {
   }
 
   /**
-   * Checks the Accept-Language of the clients browser.
-   * if this language is available it returns its country-code,
+   * Checks the Accept-Language of the client browser.
+   * If this language is available it returns its country-code,
    * else it returns the standard-language
    */
   protected String getAcceptLanguage(HttpServletRequest req){
@@ -64,7 +77,7 @@ public abstract class AbstractServlet extends HttpServlet {
     //is there an existing template-path?
     if(!f.isDirectory()){
       //no there isn't. we use standard-language
-      lang = Configuration.getProperty("StandardLanguage");
+      lang = MirConfig.getProp("StandardLanguage");
       theLog.printDebugInfo("language not existing");
     }
     theLog.printDebugInfo("Language: " + lang);