various fixes/cleanup: old producers are now completely gone, old logfile class too
[mir.git] / source / mir / misc / HTMLTemplateProcessor.java
index 1b45367..346d3d2 100755 (executable)
-/*
- * put your module comment here
- */
-
-
-package mir.misc;
-
-import  java.lang.*;
-import  java.util.*;
-import  java.io.*;
-import  java.net.*;
-import  freemarker.template.*;
-import  mir.entity.*;
-import  mir.storage.*;
-import javax.servlet.http.*;
-
-
-/**
- * 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;
-  private static String               productionHost;
-  private static String               audioHost;
-  private static String               videoHost;
-  private static String               imageHost;
-  private static String               openAction;
-  protected static String producerDocRoot = MirConfig.getProp("Producer.DocRoot");
-  protected static String producerStorageRoot = MirConfig.getProp("Producer.StorageRoot");
-
-
-  //
-  // init
-
-  static {
-
-    templateDir = MirConfig.getPropWithHome("HTMLTemplateProcessor.Dir");
-    templateCache = new FileTemplateCache(templateDir);
-    templateCache.setLoadingPolicy(templateCache.LOAD_ON_DEMAND);
-    templateCache.startAutoUpdate();
-    theLog = Logfile.getInstance(MirConfig.getPropWithHome("HTMLTemplateProcessor.Logfile"));
-    docRoot = MirConfig.getProp("RootUri");
-    /** @todo
-      quickhack: action-root is only for Mir!!!!, idfx
-      actionRoot = docRoot + "/servlet/" + MirConfig.getProp("ServletName");*/
-    actionRoot = docRoot + "/servlet/Mir";
-    openAction = MirConfig.getProp("Producer.OpenAction");
-    productionHost = MirConfig.getProp("Producer.ProductionHost");
-    videoHost = MirConfig.getProp("Producer.VideoHost");
-    audioHost = MirConfig.getProp("Producer.AudioHost");
-    imageHost = MirConfig.getProp("Producer.Image.Host");
-    producerDocRoot = MirConfig.getProp("Producer.DocRoot");
-    producerStorageRoot = MirConfig.getProp("Producer.StorageRoot");
-
-  }
-
-  /**
-   * 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)
-      throws HTMLParseException {
-    process(res, templateFilename,  entList,  (String)null, (TemplateModelRoot)null,  out);
-  }
-
-  /**
-   * 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)
-      throws HTMLParseException {
-
-      SimpleHash modelRoot = new SimpleHash();
-
-      if (entList == null) {
-         process(null,templateFilename, modelRoot, out);
-      } 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);
-        } 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
-   * @param out
-   * @exception HTMLParseException
-   */
-    public static void process(HttpServletResponse res,String templateFilename, HashMap mergeData, PrintWriter out)
-      throws HTMLParseException {
-      process(res,templateFilename, makeSimpleHash(mergeData), out);
-    }
-
-  /**
-   * 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)
-      throws HTMLParseException {
-      process(null,templateFilename, (TemplateModelRoot)null, out);
-    }
-
-
-  /**
-   * 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)
-      throws HTMLParseException {
-      if (out==null) throw new HTMLParseException("KEIN OUTPUTSTREAM");
-      Template tmpl = getTemplateFor(templateFilename);
-      if (tmpl == null) throw new HTMLParseException("KEIN TEMPLATE: " + templateFilename);
-      if (tmr==null) tmr = new SimpleHash();
-
-      String session=null;
-      if (res!=null) {
-        session=res.encodeURL("");
-      }
-
-      // put standard configuration into tempalteRootmodel
-      SimpleHash configHash = new SimpleHash();
-      configHash.put("docroot", new SimpleScalar(producerDocRoot));
-      configHash.put("storageroot", new SimpleScalar(producerStorageRoot));
-      configHash.put("productionhost", new SimpleScalar(productionHost));
-      configHash.put("openaction", new SimpleScalar(openAction));
-      configHash.put("actionRootLogin",new SimpleScalar(actionRoot));
-
-
-      tmr.put("docRoot", new SimpleScalar(docRoot));
-      tmr.put("now", new SimpleScalar(StringUtil.date2readableDateTime(new GregorianCalendar())));
-      tmr.put("actionRoot", new SimpleScalar(actionRoot+session));
-      tmr.put("openAction", new SimpleScalar(openAction));
-      tmr.put("productionHost", new SimpleScalar(productionHost));
-      tmr.put("videoHost", new SimpleScalar(videoHost));
-      tmr.put("audioHost", new SimpleScalar(audioHost));
-      tmr.put("imageHost", new SimpleScalar(imageHost));
-
-      tmr.put("config", configHash);
-      tmpl.process(tmr, out);
-
-    }
-
-
-  /**
-   *   Wandelt eine Entity-Liste in eine SimpleList von SimpleHashes um.
-   *   @param aList ist eine Liste von Entity
-   *   @return eine freemarker.template.SimpleList von SimpleHashes.
-   */
-  public static SimpleList makeSimpleList(EntityList aList) throws StorageObjectException
-  {
-    SimpleList      simpleList = new SimpleList();
-    if (aList != null) {
-      for(int i=0;i<aList.size();i++){
-        simpleList.add(makeSimpleHash(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(), makeSimpleHash(currentEntity));
-      }
-    }
-    return simpleHash;
-  }
-
-  /**
-   *  Konvertiert ein Entity in ein freemarker.template.SimpleHash-Modell
-   *  @param entity ist die Entity
-   *  @return SimpleHash mit den entsprechenden freemarker Daten
-   *
-   */
-    public static SimpleHash makeSimpleHash(Entity entity) {
-      if (entity != null) {
-        return makeSimpleHash(entity.getValues());
-      }
-      else {
-        //theLog.printWarning("Entity ist <null>");
-        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;
-  }
-
-
-  /**
-   * Wandelt EntityListe in SimpleHash um, und versieht die Liste mit StandardInfos,
-   * die aus EntityList kommen.
-   *
-   * @param entList
-   * @return SimpleHash mit Entity-Daten und ZusatzInfos.
-   * @exception StorageObjectException
-   */
-    public static SimpleHash makeSimpleHashWithEntitylistInfos(EntityList entList) throws StorageObjectException {
-      SimpleHash modelRoot = new SimpleHash();
-      if (entList!=null) {
-                modelRoot.put("contentlist", makeSimpleList(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
-  {
-    if (templateFilename!=null) return templateCache.getTemplate(templateFilename);
-    else {
-      theLog.printError("CACHE (ERR): Unknown template: " + templateFilename);
-      throw new HTMLParseException("Templatefile: "+ templateFilename + " not found.");
-    }
-  }
-
-  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