various fixes/cleanup: old producers are now completely gone, old logfile class too
[mir.git] / source / mir / misc / HTMLTemplateProcessor.java
index 56d0b30..346d3d2 100755 (executable)
-/*
- * Copyright (C) 2001, 2002  The Mir-coders group
- *
- * This file is part of Mir.
- *
- * Mir is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * Mir is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Mir; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
- * In addition, as a special exception, The Mir-coders gives permission to link
- * the code of this program with the com.oreilly.servlet library, 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 exception
- * to your version of the file, but you are not obligated to do so.  If you do
- * not wish to do so, delete this exception statement from your version.
- */
-
-package mir.misc;
-
-import freemarker.template.*;
-import mir.entity.Entity;
-import mir.entity.EntityList;
-import mir.storage.StorageObjectException;
-import org.apache.struts.util.MessageResources;
-
-import javax.servlet.http.HttpServletResponse;
-import java.io.PrintWriter;
-import java.net.URLEncoder;
-import java.util.*;
-
-
-/**
- * Hilfsklasse zum Mergen von Template und Daten
- */
-public final class HTMLTemplateProcessor {
-
-    public static String templateDir;
-    private static FileTemplateCache templateCache;
-    private static Logfile theLog;
-    private static String docRoot;
-    private static String actionRoot;
-
-    static {
-        templateDir = MirConfig.getPropWithHome("HTMLTemplateProcessor.Dir");
-        templateCache = new FileTemplateCache(templateDir);
-        templateCache.setLoadingPolicy(templateCache.LOAD_ON_DEMAND);
-        // gone in freemarker 1.7.1: templateCache.startAutoUpdate();
-        theLog = Logfile.getInstance(MirConfig.getPropWithHome("HTMLTemplateProcessor.Logfile"));
-
-        docRoot = MirConfig.getProp("RootUri");
-        try {
-            actionRoot = docRoot + MirConfig.getProp("Producer.ActionServlet");
-        } catch (ConfigException ce) {
-            // if  Producer.ActionServlet is not set in the conf file
-            actionRoot = docRoot + "/servlet/Mir";
-        }
-    }
-
-    /**
-     * empty private constructor, to avoid instantiation
-     */
-    private HTMLTemplateProcessor() {
-    }
-
-
-    // process-methods to merge different datastructures
-    // with freemarker templates
-
-
-    /**
-     * Wandelt <code>anEntity</code> in freemarker-Struktur um, mischt die Daten mit
-     * Template <code>templateFilename</code> und gibt das Ergebnis an den PrintWriter
-     * <code>out</code>
-     *
-     * @param templateFilename
-     * @param anEntity
-     * @param out
-     * @exception HTMLParseException
-     */
-
-    public static void process(String templateFilename, Entity anEntity, PrintWriter out)
-            throws HTMLParseException {
-        if (anEntity == null)
-            throw new HTMLParseException("entity is empty!");
-        else
-            process(templateFilename, anEntity, out);
-    }
-
-
-    /**
-     * Wandelt Liste mit Entities <code>entList</code> in freemarker-Struktur um, mischt die Daten mit
-     * Template <code>templateFilename</code> und gibt das Ergebnis an den PrintWriter
-     * <code>out</code>
-     *
-     * @param templateFilename
-     * @param entList
-     * @param out
-     * @exception HTMLParseException
-     */
-    public static void process(HttpServletResponse res, String templateFilename,
-                               EntityList entList, PrintWriter out, Locale locale)
-            throws HTMLParseException {
-        process(res, templateFilename, entList, (String) null, (TemplateModelRoot) null, out, locale);
-    }
-
-    /**
-     * Wandelt Entitylist in freemarker-Struktur um, fügt <code>additionalModel</code>
-     * unter dem Namen <code>additionalModelName</code> ein und mischt die Daten mit
-     * Template <code>templateFilename</code> und gibt das Ergebnis an den PrintWriter
-     * <code>out</code>
-     *
-     * @param templateFilename
-     * @param entList
-     * @param additionalModelName
-     * @param additionalModel
-     * @param out
-     * @exception HTMLParseException
-     */
-    public static void process(HttpServletResponse res, String templateFilename,
-                               EntityList entList, String additionalModelName,
-                               TemplateModelRoot additionalModel, PrintWriter out,
-                               Locale locale)
-            throws HTMLParseException {
-
-        SimpleHash modelRoot = new SimpleHash();
-
-        if (entList == null) {
-            process(null, templateFilename, modelRoot, out, locale);
-        } else {
-            try {
-                modelRoot = makeSimpleHashWithEntitylistInfos(entList);
-
-                // Quickhack um mal ein Popup mit reinzunhemen ..
-                if (additionalModelName != null && additionalModel != null)
-                    modelRoot.put(additionalModelName, additionalModel);
-
-                process(res, templateFilename, modelRoot, out, locale);
-            } catch (StorageObjectException e) {
-                throw new HTMLParseException(e.toString());
-            }
-        }
-    }
-
-    /**
-     * Wandelt HashMap <code>mergeData</code> in freemarker-Struktur und mischt diese mit
-     * Template <code>templateFilename</code> und gibt das Ergebnis an den PrintWriter
-     * <code>out</code>
-     *
-     * @param templateFilename
-     * @param mergeData - a HashMap with mergeData to be converted in SimpleHash
-     * @param out
-     * @exception HTMLParseException
-     */
-    public static void process(HttpServletResponse res, String templateFilename,
-                               HashMap mergeData, PrintWriter out, Locale locale)
-            throws HTMLParseException {
-        process(res, templateFilename, makeSimpleHash(mergeData), out, locale);
-    }
-
-    /**
-     * Gibt Template <code>templateFilename</code> an den PrintWriter
-     * <code>out</code>
-     *
-     * @param templateFilename
-     * @param mergeData
-     * @param out
-     * @exception HTMLParseException
-     */
-    public static void process(String templateFilename, PrintWriter out,
-                               Locale locale)
-            throws HTMLParseException {
-        process(null, templateFilename, (TemplateModelRoot) null, out, locale);
-    }
-
-
-    /**
-     * Mischt die freemarker-Struktur <code>tmr</code> mit
-     * Template <code>templateFilename</code> und gibt das Ergebnis an den PrintWriter
-     * <code>out</code>
-     *
-     * @param templateFilename
-     * @param mergeData
-     * @param out
-     * @exception HTMLParseException
-     */
-    public static void process(HttpServletResponse res, String templateFilename,
-                               TemplateModelRoot tmr, PrintWriter out, Locale locale)
-            throws HTMLParseException {
-        process(res, templateFilename, tmr, null, out, locale, "bundles.admin");
-        // this method is
-    }
-
-    /**
-     * Mischt die freemarker-Struktur <code>tmr</code> mit
-     * Template <code>templateFilename</code> und gibt das Ergebnis an den PrintWriter
-     * <code>out</code>
-     *
-     * @param templateFilename
-     * @param mergeData
-     * @param out
-     * @exception HTMLParseException
-     */
-    public static void process(HttpServletResponse res, String templateFilename,
-                               TemplateModelRoot tmr, TemplateModelRoot extra,
-                               PrintWriter out, Locale locale, String bundles)
-            throws HTMLParseException {
-        if (out == null) throw new HTMLParseException("no outputstream");
-        Template tmpl = getTemplateFor(templateFilename);
-        if (tmpl == null) throw new HTMLParseException("no template: " + templateFilename);
-        if (tmr == null) tmr = new SimpleHash();
-
-        /** @todo  what is this for? (rk) */
-        String session = "";
-        if (res != null) {
-            session = res.encodeURL("");
-        }
-
-        SimpleHash configHash = new SimpleHash();
-
-        // pass the whole config hash to the templates
-        Enumeration en = MirConfig.getResourceKeys();
-        String key;
-        while (en.hasMoreElements()) {
-            key = (String) en.nextElement();
-            configHash.put(key, new SimpleScalar(MirConfig.getProp(key)));
-        }
-
-        // this does not come directly from the config file
-        configHash.put("docRoot", new SimpleScalar(docRoot));
-        configHash.put("actionRoot", new SimpleScalar(actionRoot + session));
-        configHash.put("now", new SimpleScalar(StringUtil.date2readableDateTime(new GregorianCalendar())));
-
-        // this conform to updated freemarker syntax
-        configHash.put("compressWhitespace", new freemarker.template.utility.CompressWhitespace());
-
-        SimpleHash outPutHash = new SimpleHash();
-
-        if (extra != null) {
-            outPutHash.put("extra", extra);
-            try {
-                while (((SimpleList) extra).hasNext()) {
-                    theLog.printDebugInfo(((SimpleList) extra).next().toString());
-                }
-            } catch (Exception e) {
-            }
-        }
-        outPutHash.put("data", tmr);
-        outPutHash.put("config", configHash);
-
-        MessageResources messages = MessageResources.getMessageResources(bundles);
-        outPutHash.put("lang", new MessageMethodModel(locale, messages));
-
-        tmpl.process(outPutHash, out);
-    }
-
-
-    /**
-     *   Converts Entity-List to SimpleList of SimpleHashes.
-     *   @param aList ist eine Liste von Entity
-     *   @return eine freemarker.template.SimpleList von SimpleHashes.
-     *
-     *    @deprecated EntityLists comply with TemplateListModel now.
-     */
-    public static SimpleList makeSimpleList(EntityList aList) throws StorageObjectException {
-        theLog.printWarning("## using deprecated makeSimpleList(entityList) - a waste of resources");
-        SimpleList simpleList = new SimpleList();
-        if (aList != null) {
-            for (int i = 0; i < aList.size(); i++) {
-                simpleList.add(aList.elementAt(i));
-            }
-        }
-        return simpleList;
-    }
-
-    /**
-     *  Konvertiert ein EntityList in ein freemarker.template.SimpleHash-Modell. Im Hash
-     *  sind die einzelnen Entities ueber ihre id zu erreichen.
-     *  @param aList ist die EntityList
-     *  @return SimpleHash mit den entsprechenden freemarker Daten
-     *
-     */
-    public static SimpleHash makeSimpleHash(EntityList aList) throws StorageObjectException {
-        SimpleHash simpleHash = new SimpleHash();
-        Entity currentEntity;
-
-        if (aList != null) {
-            for (int i = 0; i < aList.size(); i++) {
-                currentEntity = (Entity) aList.elementAt(i);
-                simpleHash.put(currentEntity.getId(), currentEntity);
-            }
-        }
-        return simpleHash;
-    }
-
-    /**
-     *  Konvertiert ein Entity in ein freemarker.template.SimpleHash-Modell
-     *  @param entity ist die Entity
-     *  @return SimpleHash mit den entsprechenden freemarker Daten
-     *
-     *  @deprecated This method is deprecated and will be deleted in the next
-     *  release. Entity interfaces freemarker.template.TemplateHashModel now
-     *  and can be used in the same way as SimpleHash. It is not necessary any
-     *  more to make a SimpleHash from an Entity
-     */
-    public static SimpleHash makeSimpleHash(Entity entity) {
-        if (entity != null) {
-            theLog.printWarning("## using deprecated makeSimpleHash(entity) - a waste of resources");
-            return makeSimpleHash(entity.getValues());
-        } else
-            return null;
-    }
-
-    /**
-     *  Konvertiert ein Hashtable mit den keys und values als String
-     *  in ein freemarker.template.SimpleHash-Modell
-     *  @param mergeData der HashMap mit den String / String Daten
-     *  @return SimpleHash mit den entsprechenden freemarker Daten
-     *
-     */
-    public static SimpleHash makeSimpleHash(HashMap mergeData) {
-        SimpleHash modelRoot = new SimpleHash();
-        String aField;
-        if (mergeData != null) {
-            Set set = mergeData.keySet();
-            Iterator it = set.iterator();
-            for (int i = 0; i < set.size(); i++) {
-                aField = (String) it.next();
-                modelRoot.put(aField, (String) mergeData.get(aField));
-            }
-        }
-        return modelRoot;
-    }
-
-
-    /**
-     * Converts EntityList in SimpleHash and adds additional information
-     * to the returned SimpleHash
-     *
-     * @param entList
-     * @return SimpleHash returns SimpleHash with the converted EntityList plus
-     *        additional Data about the list.
-     * @exception StorageObjectException
-     */
-
-    public static SimpleHash makeSimpleHashWithEntitylistInfos(EntityList entList) throws StorageObjectException {
-        SimpleHash modelRoot = new SimpleHash();
-        if (entList != null) {
-            modelRoot.put("contentlist", entList);
-            modelRoot.put("count", new SimpleScalar((new Integer(entList.getCount())).toString()));
-            if (entList.getWhere() != null) {
-                modelRoot.put("where", new SimpleScalar(entList.getWhere()));
-                modelRoot.put("where_encoded", new SimpleScalar(URLEncoder.encode(entList.getWhere())));
-            }
-            if (entList.getOrder() != null) {
-                modelRoot.put("order", new SimpleScalar(entList.getOrder()));
-                modelRoot.put("order_encoded", new SimpleScalar(URLEncoder.encode(entList.getOrder())));
-            }
-            modelRoot.put("from", new SimpleScalar((new Integer(entList.getFrom())).toString()));
-            modelRoot.put("to", new SimpleScalar((new Integer(entList.getTo())).toString()));
-
-            if (entList.hasNextBatch())
-                modelRoot.put("next", new SimpleScalar((new Integer(entList.getNextBatch())).toString()));
-            if (entList.hasPrevBatch())
-                modelRoot.put("prev", new SimpleScalar((new Integer(entList.getPrevBatch())).toString()));
-        }
-        return modelRoot;
-    }
-
-    /**
-     * Private methods to get template from a templateFilename
-     * @param templateFilename
-     * @return Template
-     * @exception HTMLParseException
-     */
-    private static Template getTemplateFor(String templateFilename) throws HTMLParseException {
-        Template returnTemplate = null;
-        if (templateFilename != null)
-            returnTemplate = (Template) templateCache.getItem(templateFilename, "template");
-
-
-        if (returnTemplate == null) {
-            theLog.printError("CACHE (ERR): Unknown template: " + templateFilename);
-            throw new HTMLParseException("Templatefile: " + templateFilename + " not found.");
-        }
-
-        return returnTemplate;
-    }
-
-    public static void stopAutoUpdate() {
-        templateCache.stopAutoUpdate();
-        templateCache = null;
-    }
-
-}
+/*\r
+ * Copyright (C) 2001, 2002  The Mir-coders group\r
+ *\r
+ * This file is part of Mir.\r
+ *\r
+ * Mir is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * Mir is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with Mir; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
+ *\r
+ * In addition, as a special exception, The Mir-coders gives permission to link\r
+ * the code of this program with the com.oreilly.servlet library, any library\r
+ * licensed under the Apache Software License, The Sun (tm) Java Advanced\r
+ * Imaging library (JAI), The Sun JIMI library (or with modified versions of\r
+ * the above that use the same license as the above), and distribute linked\r
+ * combinations including the two.  You must obey the GNU General Public\r
+ * License in all respects for all of the code used other than the above\r
+ * mentioned libraries.  If you modify this file, you may extend this exception\r
+ * to your version of the file, but you are not obligated to do so.  If you do\r
+ * not wish to do so, delete this exception statement from your version.\r
+ */\r
+\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
+import mir.config.MirPropertiesConfiguration.PropertiesConfigExc;\r
+import mir.entity.Entity;\r
+import mir.entity.EntityList;\r
+import mir.storage.StorageObjectFailure;\r
+\r
+/**\r
+ * Hilfsklasse zum Mergen von Template und Daten\r
+ */\r
+public final class HTMLTemplateProcessor {\r
+\r
+  public static String templateDir;\r
+  private static MirPropertiesConfiguration configuration;\r
+  private static FileTemplateCache templateCache;\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
+    }\r
+    catch (PropertiesConfigExc e) {\r
+      e.printStackTrace();\r
+    }\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
+\r
+\r
+    docRoot = configuration.getString("RootUri");\r
+    try {\r
+      actionRoot = docRoot +configuration.getString("Producer.ActionServlet");\r
+    }\r
+    catch (ConfigException ce) {\r
+      // if  Producer.ActionServlet is not set in the conf file\r
+      actionRoot = docRoot + "/Mir";\r
+    }\r
+  }\r
+\r
+  /**\r
+   * empty private constructor, to avoid instantiation\r
+   */\r
+  private HTMLTemplateProcessor() {\r
+  }\r
+\r
+  // process-methods to merge different datastructures\r
+  // with freemarker templates\r
+\r
+  /**\r
+       * Wandelt <code>anEntity</code> in freemarker-Struktur um, mischt die Daten mit\r
+   * Template <code>templateFilename</code> und gibt das Ergebnis an den PrintWriter\r
+   * <code>out</code>\r
+   *\r
+   * @param templateFilename\r
+   * @param anEntity\r
+   * @param out\r
+   * @exception HTMLParseException\r
+   */\r
+\r
+  public static void process(String templateFilename, Entity anEntity,\r
+                             PrintWriter out) throws HTMLParseException {\r
+    if (anEntity == null)\r
+      throw new HTMLParseException("entity is empty!");\r
+    else\r
+      process(templateFilename, anEntity, out);\r
+  }\r
+\r
+  /**\r
+   * Wandelt Liste mit Entities <code>entList</code> in freemarker-Struktur um, mischt die Daten mit\r
+   * Template <code>templateFilename</code> und gibt das Ergebnis an den PrintWriter\r
+   * <code>out</code>\r
+   *\r
+   * @param templateFilename\r
+   * @param entList\r
+   * @param out\r
+   * @exception HTMLParseException\r
+   */\r
+  public static void process(HttpServletResponse res, String templateFilename,\r
+   EntityList entList, PrintWriter out, Locale locale) throws HTMLParseException {\r
+    process(res, templateFilename, entList, (String)null, (TemplateModelRoot)null,\r
+            out, locale);\r
+  }\r
+\r
+  /**\r
+   * Wandelt Entitylist in freemarker-Struktur um, f?gt <code>additionalModel</code>\r
+       * unter dem Namen <code>additionalModelName</code> ein und mischt die Daten mit\r
+   * Template <code>templateFilename</code> und gibt das Ergebnis an den PrintWriter\r
+   * <code>out</code>\r
+   *\r
+   * @param templateFilename\r
+   * @param entList\r
+   * @param additionalModelName\r
+   * @param additionalModel\r
+   * @param out\r
+   * @exception HTMLParseException\r
+   */\r
+\r
+  public static void process(HttpServletResponse res, String templateFilename,\r
+                             EntityList entList, String additionalModelName,\r
+                             TemplateModelRoot additionalModel, PrintWriter out,\r
+                             Locale locale) throws HTMLParseException {\r
+\r
+    SimpleHash modelRoot = new SimpleHash();\r
+\r
+    if (entList == null) {\r
+      process(null, templateFilename, modelRoot, out, locale);\r
+    }\r
+    else {\r
+      try {\r
+        modelRoot = makeSimpleHashWithEntitylistInfos(entList);\r
+\r
+        // Quickhack um mal ein Popup mit reinzunhemen ..\r
+        if (additionalModelName != null && additionalModel != null)\r
+          modelRoot.put(additionalModelName, additionalModel);\r
+\r
+        process(res, templateFilename, modelRoot, out, locale);\r
+      }\r
+      catch (StorageObjectFailure e) {\r
+        throw new HTMLParseException(e.toString());\r
+      }\r
+    }\r
+  }\r
+\r
+\r
+  /**\r
+   * Gibt Template <code>templateFilename</code> an den PrintWriter\r
+   * <code>out</code>\r
+   *\r
+   * @param templateFilename\r
+   * @param mergeData\r
+   * @param out\r
+   * @exception HTMLParseException\r
+   */\r
+  public static void process(String templateFilename, PrintWriter out,\r
+                             Locale locale) throws HTMLParseException {\r
+    process(null, templateFilename, (TemplateModelRoot)null, out, locale);\r
+  }\r
+\r
+  /**\r
+   * Mischt die freemarker-Struktur <code>tmr</code> mit\r
+   * Template <code>templateFilename</code> und gibt das Ergebnis an den PrintWriter\r
+   * <code>out</code>\r
+   *\r
+   * @param templateFilename\r
+   * @param mergeData\r
+   * @param out\r
+   * @exception HTMLParseException\r
+   */\r
+  public static void process(HttpServletResponse res, String templateFilename,\r
+                             TemplateModelRoot tmr, PrintWriter out,\r
+                             Locale locale) throws HTMLParseException {\r
+    process(res, templateFilename, tmr, null, out, locale);\r
+  }\r
+\r
+  public static void process(HttpServletResponse res, String templateFilename,\r
+                             TemplateModelRoot tmr, TemplateModelRoot extra,\r
+                             PrintWriter out, Locale locale) throws HTMLParseException {\r
+    process(res, templateFilename, tmr, extra, out, locale, "bundles.adminlocal", "bundles.admin");\r
+  }\r
+\r
+  public static void process(HttpServletResponse res, String templateFilename,\r
+       TemplateModelRoot tmr, TemplateModelRoot extra, PrintWriter out,\r
+       Locale locale, String bundles) throws HTMLParseException {\r
+    process(res, templateFilename, tmr, extra, out, locale, bundles, null);\r
+  }\r
+\r
+  /**\r
+   * Mischt die freemarker-Struktur <code>tmr</code> mit\r
+   * Template <code>templateFilename</code> und gibt das Ergebnis an den PrintWriter\r
+   * <code>out</code>\r
+   *\r
+   * @param templateFilename\r
+   * @param mergeData\r
+   * @param out\r
+   * @exception HTMLParseException\r
+   */\r
+  public static void process(HttpServletResponse res, String templateFilename,\r
+                             TemplateModelRoot tmr, TemplateModelRoot extra,\r
+                             PrintWriter out, Locale locale, String bundles,\r
+                             String bundles2) throws HTMLParseException {\r
+    if (out == null)\r
+      throw new HTMLParseException("no outputstream");\r
+    Template tmpl = getTemplateFor(templateFilename);\r
+    if (tmpl == null)\r
+      throw new HTMLParseException("no template: " + templateFilename);\r
+    if (tmr == null)\r
+      tmr = new SimpleHash();\r
+\r
+      /** @todo  what is this for? (rk) */\r
+    String session = "";\r
+    if (res != null) {\r
+      session = res.encodeURL("");\r
+    }\r
+\r
+    SimpleHash configHash = new SimpleHash();\r
+\r
+    // pass the whole config hash to the templates\r
+    Iterator it = configuration.getKeys();\r
+    String key;\r
+    while (it.hasNext()) {\r
+      key = (String) it.next();\r
+      configHash.put(key, new SimpleScalar(\r
+        configuration.getString(key))\r
+      );\r
+    }\r
+\r
+    // this does not come directly from the config file\r
+    configHash.put("docRoot", new SimpleScalar(docRoot));\r
+    configHash.put("actionRoot", new SimpleScalar(actionRoot + session));\r
+    configHash.put("now",\r
+                   new SimpleScalar(StringUtil.date2readableDateTime(new GregorianCalendar())));\r
+\r
+    // this conform to updated freemarker syntax\r
+    configHash.put("compressWhitespace",\r
+                   new freemarker.template.utility.CompressWhitespace());\r
+\r
+    SimpleHash utilityHash = new SimpleHash();\r
+    try {\r
+      utilityHash.put("compressWhitespace",\r
+                      new freemarker.template.utility.CompressWhitespace());\r
+      utilityHash.put("encodeURI",\r
+                      FreemarkerGenerator.makeAdapter(new GeneratorHTMLFunctions.\r
+          encodeURIGeneratorFunction()));\r
+      utilityHash.put("encodeHTML",\r
+                      FreemarkerGenerator.makeAdapter(new GeneratorHTMLFunctions.\r
+          encodeHTMLGeneratorFunction()));\r
+      utilityHash.put("isOdd",\r
+                      FreemarkerGenerator.makeAdapter(new GeneratorIntegerFunctions.\r
+          isOddFunction()));\r
+      utilityHash.put("increment",\r
+                      FreemarkerGenerator.makeAdapter(new GeneratorIntegerFunctions.\r
+          incrementFunction()));\r
+    }\r
+    catch (Throwable t) {\r
+      throw new HTMLParseException(t.getMessage());\r
+    }\r
+\r
+    SimpleHash outPutHash = new SimpleHash();\r
+\r
+    if (extra != null) {\r
+      outPutHash.put("extra", extra);\r
+    }\r
+    outPutHash.put("data", tmr);\r
+    outPutHash.put("config", configHash);\r
+    outPutHash.put("utility", utilityHash);\r
+\r
+    MessageResources messages = MessageResources.getMessageResources(bundles);\r
+    if (bundles2!=null) {\r
+      outPutHash.put("lang", new MessageMethodModel(locale, MessageResources.getMessageResources(bundles), MessageResources.getMessageResources(bundles2)));\r
+    }\r
+    else {\r
+      outPutHash.put("lang", new MessageMethodModel(locale, MessageResources.getMessageResources(bundles)));\r
+    }\r
+\r
+    tmpl.process(outPutHash, out);\r
+  }\r
+\r
+  /**\r
+   *   Converts Entity-List to SimpleList of SimpleHashes.\r
+   *   @param aList ist eine Liste von Entity\r
+   *   @return eine freemarker.template.SimpleList von SimpleHashes.\r
+   *\r
+   *    @deprecated EntityLists comply with TemplateListModel now.\r
+   */\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
+        simpleList.add(aList.elementAt(i));\r
+      }\r
+    }\r
+    return simpleList;\r
+  }\r
+\r
+  /**\r
+   *  Konvertiert ein EntityList in ein freemarker.template.SimpleHash-Modell. Im Hash\r
+   *  sind die einzelnen Entities ueber ihre id zu erreichen.\r
+   *  @param aList ist die EntityList\r
+   *  @return SimpleHash mit den entsprechenden freemarker Daten\r
+   *\r
+   */\r
+  public static SimpleHash makeSimpleHash(EntityList aList) throws\r
+      StorageObjectFailure {\r
+    SimpleHash simpleHash = new SimpleHash();\r
+    Entity currentEntity;\r
+\r
+    if (aList != null) {\r
+      for (int i = 0; i < aList.size(); i++) {\r
+        currentEntity = (Entity) aList.elementAt(i);\r
+        simpleHash.put(currentEntity.getId(), currentEntity);\r
+      }\r
+    }\r
+    return simpleHash;\r
+  }\r
+\r
+  /**\r
+   *  Konvertiert ein Hashtable mit den keys und values als String\r
+   *  in ein freemarker.template.SimpleHash-Modell\r
+   *  @param mergeData der HashMap mit den String / String Daten\r
+   *  @return SimpleHash mit den entsprechenden freemarker Daten\r
+   *\r
+   */\r
+  public static SimpleHash makeSimpleHash(HashMap mergeData) {\r
+    SimpleHash modelRoot = new SimpleHash();\r
+    String aField;\r
+    if (mergeData != null) {\r
+      Set set = mergeData.keySet();\r
+      Iterator it = set.iterator();\r
+      for (int i = 0; i < set.size(); i++) {\r
+        aField = (String) it.next();\r
+        modelRoot.put(aField, (String) mergeData.get(aField));\r
+      }\r
+    }\r
+    return modelRoot;\r
+  }\r
+\r
+  /**\r
+   * Converts EntityList in SimpleHash and adds additional information\r
+   * to the returned SimpleHash\r
+   *\r
+   * @param entList\r
+   * @return SimpleHash returns SimpleHash with the converted EntityList plus\r
+   *        additional Data about the list.\r
+   * @exception StorageObjectException\r
+   */\r
+\r
+  public static SimpleHash makeSimpleHashWithEntitylistInfos(EntityList entList) throws\r
+      StorageObjectFailure {\r
+    SimpleHash modelRoot = new SimpleHash();\r
+    if (entList != null) {\r
+      modelRoot.put("contentlist", entList);\r
+      modelRoot.put("count",\r
+                    new SimpleScalar( (new Integer(entList.getCount())).toString()));\r
+      if (entList.getWhere() != null) {\r
+        modelRoot.put("where", new SimpleScalar(entList.getWhere()));\r
+        modelRoot.put("where_encoded",\r
+                      new SimpleScalar(URLEncoder.encode(entList.getWhere())));\r
+      }\r
+      if (entList.getOrder() != null) {\r
+        modelRoot.put("order", new SimpleScalar(entList.getOrder()));\r
+        modelRoot.put("order_encoded",\r
+                      new SimpleScalar(URLEncoder.encode(entList.getOrder())));\r
+      }\r
+      modelRoot.put("from",\r
+                    new SimpleScalar( (new Integer(entList.getFrom())).toString()));\r
+      modelRoot.put("to",\r
+                    new SimpleScalar( (new Integer(entList.getTo())).toString()));\r
+\r
+      if (entList.hasNextBatch())\r
+        modelRoot.put("next",\r
+                      new SimpleScalar( (new Integer(entList.getNextBatch())).\r
+                                       toString()));\r
+      if (entList.hasPrevBatch())\r
+        modelRoot.put("prev",\r
+                      new SimpleScalar( (new Integer(entList.getPrevBatch())).\r
+                                       toString()));\r
+    }\r
+    return modelRoot;\r
+  }\r
+\r
+  /**\r
+   * Private methods to get template from a templateFilename\r
+   * @param templateFilename\r
+   * @return Template\r
+   * @exception HTMLParseException\r
+   */\r
+  private static Template getTemplateFor(String templateFilename) throws\r
+      HTMLParseException {\r
+    Template returnTemplate = null;\r
+    if (templateFilename != null)\r
+      returnTemplate = (Template) templateCache.getItem(templateFilename,\r
+          "template");\r
+\r
+    if (returnTemplate == null) {\r
+      logger.error("CACHE (ERR): Unknown template: " + templateFilename);\r
+      throw new HTMLParseException("Templatefile: " + templateFilename + " not found.");\r
+    }\r
+\r
+    return returnTemplate;\r
+  }\r
+\r
+  public static void stopAutoUpdate() {\r
+    templateCache.stopAutoUpdate();\r
+    templateCache = null;\r
+  }\r
+\r
+}
\ No newline at end of file