various fixes/cleanup: old producers are now completely gone, old logfile class too
[mir.git] / source / mir / misc / HTMLTemplateProcessor.java
index f02f59f..346d3d2 100755 (executable)
 \r
 package mir.misc;\r
 \r
+import java.io.PrintWriter;\r
+import java.net.URLEncoder;\r
+import java.util.*;\r
+\r
+import javax.servlet.http.HttpServletResponse;\r
+\r
+import org.apache.struts.util.MessageResources;\r
+\r
 import freemarker.template.*;\r
+\r
+import mir.log.LoggerWrapper;\r
 import mir.util.*;\r
 import mir.generator.*;\r
 import mir.config.MirPropertiesConfiguration;\r
@@ -39,13 +49,6 @@ import mir.config.MirPropertiesConfiguration.PropertiesConfigExc;
 import mir.entity.Entity;\r
 import mir.entity.EntityList;\r
 import mir.storage.StorageObjectFailure;\r
-import org.apache.struts.util.MessageResources;\r
-\r
-import javax.servlet.http.HttpServletResponse;\r
-import java.io.PrintWriter;\r
-import java.net.URLEncoder;\r
-import java.util.*;\r
-\r
 \r
 /**\r
  * Hilfsklasse zum Mergen von Template und Daten\r
@@ -55,21 +58,25 @@ public final class HTMLTemplateProcessor {
   public static String templateDir;\r
   private static MirPropertiesConfiguration configuration;\r
   private static FileTemplateCache templateCache;\r
-  private static Logfile theLog;\r
   private static String docRoot;\r
   private static String actionRoot;\r
+  private static LoggerWrapper logger;\r
 \r
   static {\r
+    // ML: configuration is not thread safe: it's risky to use it like this\r
+    //     actually I don't see why HTMLTemplateProcessor needs to be a\r
+    //     class with static methods. This causes more problems than it solves.\r
     try {\r
       configuration = MirPropertiesConfiguration.instance();\r
-    } catch (PropertiesConfigExc e) {\r
+    }\r
+    catch (PropertiesConfigExc e) {\r
       e.printStackTrace();\r
     }\r
-    theLog = Logfile.getInstance(\r
-      configuration.getStringWithHome("HTMLTemplateProcessor.Logfile"));\r
-    templateDir = \r
-       configuration.getStringWithHome("HTMLTemplateProcessor.Dir");\r
-    theLog.printDebugInfo("templateDir: " + templateDir);\r
+\r
+    logger = new LoggerWrapper("TemplateEngine");\r
+\r
+    templateDir =\r
+        configuration.getStringWithHome("HTMLTemplateProcessor.Dir");\r
     templateCache = new FileTemplateCache(templateDir);\r
     templateCache.setLoadingPolicy(FileTemplateCache.LOAD_ON_DEMAND);\r
     // gone in freemarker 1.7.1: templateCache.startAutoUpdate();\r
@@ -225,8 +232,7 @@ public final class HTMLTemplateProcessor {
   public static void process(HttpServletResponse res, String templateFilename,\r
                              TemplateModelRoot tmr, TemplateModelRoot extra,\r
                              PrintWriter out, Locale locale, String bundles,\r
-                             String bundles2) throws\r
-      HTMLParseException {\r
+                             String bundles2) throws HTMLParseException {\r
     if (out == null)\r
       throw new HTMLParseException("no outputstream");\r
     Template tmpl = getTemplateFor(templateFilename);\r
@@ -249,7 +255,7 @@ public final class HTMLTemplateProcessor {
     while (it.hasNext()) {\r
       key = (String) it.next();\r
       configHash.put(key, new SimpleScalar(\r
-       configuration.getString(key))\r
+        configuration.getString(key))\r
       );\r
     }\r
 \r
@@ -288,13 +294,6 @@ public final class HTMLTemplateProcessor {
 \r
     if (extra != null) {\r
       outPutHash.put("extra", extra);\r
-      try {\r
-        while ( ( (SimpleList) extra).hasNext()) {\r
-          theLog.printDebugInfo( ( (SimpleList) extra).next().toString());\r
-        }\r
-      }\r
-      catch (Exception e) {\r
-      }\r
     }\r
     outPutHash.put("data", tmr);\r
     outPutHash.put("config", configHash);\r
@@ -318,10 +317,8 @@ public final class HTMLTemplateProcessor {
    *\r
    *    @deprecated EntityLists comply with TemplateListModel now.\r
    */\r
-  public static SimpleList makeSimpleList(EntityList aList) throws\r
-      StorageObjectFailure {\r
-    theLog.printWarning(\r
-        "## using deprecated makeSimpleList(entityList) - a waste of resources");\r
+  public static SimpleList makeSimpleList(EntityList aList) throws StorageObjectFailure {\r
+    logger.warn("using deprecated makeSimpleList(entityList) - a waste of resources");\r
     SimpleList simpleList = new SimpleList();\r
     if (aList != null) {\r
       for (int i = 0; i < aList.size(); i++) {\r
@@ -431,9 +428,8 @@ public final class HTMLTemplateProcessor {
           "template");\r
 \r
     if (returnTemplate == null) {\r
-      theLog.printError("CACHE (ERR): Unknown template: " + templateFilename);\r
-      throw new HTMLParseException("Templatefile: " + templateFilename +\r
-                                   " not found.");\r
+      logger.error("CACHE (ERR): Unknown template: " + templateFilename);\r
+      throw new HTMLParseException("Templatefile: " + templateFilename + " not found.");\r
     }\r
 \r
     return returnTemplate;\r