-/*
- * 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.util.*;
-import mir.generator.*;
-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 + "/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());
- }
- }
- }
-
- /**
- * 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 utilityHash = new SimpleHash();
- try {
- utilityHash.put("compressWhitespace", new freemarker.template.utility.CompressWhitespace());
- utilityHash.put("encodeURI", FreemarkerGenerator.makeAdapter(new GeneratorHTMLFunctions.encodeURIGeneratorFunction()));
- utilityHash.put("encodeHTML", FreemarkerGenerator.makeAdapter(new GeneratorHTMLFunctions.encodeHTMLGeneratorFunction()));
- utilityHash.put("isOdd", FreemarkerGenerator.makeAdapter(new GeneratorIntegerFunctions.isOddFunction()));
- utilityHash.put("increment", FreemarkerGenerator.makeAdapter(new GeneratorIntegerFunctions.incrementFunction()));
- }
- catch (Throwable t) {
- throw new HTMLParseException(t.getMessage());
- }
-
-
- 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);
- outPutHash.put("utility", utilityHash);
-
- 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 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 freemarker.template.*;\r
+import mir.util.*;\r
+import mir.generator.*;\r
+import mir.entity.Entity;\r
+import mir.entity.EntityList;\r
+import mir.storage.StorageObjectException;\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
+ */\r
+public final class HTMLTemplateProcessor {\r
+\r
+ public static String templateDir;\r
+ private static FileTemplateCache templateCache;\r
+ private static Logfile theLog;\r
+ private static String docRoot;\r
+ private static String actionRoot;\r
+\r
+ static {\r
+ templateDir = MirConfig.getPropWithHome("HTMLTemplateProcessor.Dir");\r
+ templateCache = new FileTemplateCache(templateDir);\r
+ templateCache.setLoadingPolicy(templateCache.LOAD_ON_DEMAND);\r
+ // gone in freemarker 1.7.1: templateCache.startAutoUpdate();\r
+ theLog = Logfile.getInstance(MirConfig.getPropWithHome(\r
+ "HTMLTemplateProcessor.Logfile"));\r
+\r
+ docRoot = MirConfig.getProp("RootUri");\r
+ try {\r
+ actionRoot = docRoot + MirConfig.getProp("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
+ 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 (StorageObjectException e) {\r
+ throw new HTMLParseException(e.toString());\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\r
+ 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
+ Enumeration en = MirConfig.getResourceKeys();\r
+ String key;\r
+ while (en.hasMoreElements()) {\r
+ key = (String) en.nextElement();\r
+ configHash.put(key, new SimpleScalar(MirConfig.getProp(key)));\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
+ 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
+ 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\r
+ StorageObjectException {\r
+ theLog.printWarning(\r
+ "## 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
+ StorageObjectException {\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
+ StorageObjectException {\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
+ theLog.printError("CACHE (ERR): Unknown template: " + templateFilename);\r
+ throw new HTMLParseException("Templatefile: " + templateFilename +\r
+ " 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
-/*
- * 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.SimpleScalar;
-import freemarker.template.TemplateMethodModel;
-import freemarker.template.TemplateModel;
-import org.apache.struts.util.MessageResources;
-
-import java.util.List;
-import java.util.Locale;
-
-/**
- * A FreeMarker <code>TemplateMethodModel</code> that provides access to a
- * Struts <code>MessageResources</code>, for use in Interantionalized templates.
- *
- * @author Kellan <kellan@protest.net>
- */
-
-public class MessageMethodModel implements TemplateMethodModel {
-
- /**
- * The perferred locale for this instance of MessageMethod.
- */
- private Locale locale;
-
- /**
- * The MessageResources to query, a single instance shared for
- * the lifetime of servlet.
- */
- private MessageResources messages;
-
-
- /**
- * Construct a MessageMethod that uses the JVM's default locale.
- *
- * @param message The MessageResources object to query
- */
- public MessageMethodModel(MessageResources messages) {
- this(null, messages);
- }
-
- /**
- * Construct a MessageMethod
- *
- * @param locale a Locale object, persumably initialized
- * from users Accept-Language header field
- *
- * @param message The MessageResources object to query
- */
- public MessageMethodModel(Locale locale, MessageResources messages) {
- this.locale = locale;
- this.messages = messages;
- }
-
-
- /**
- * Takes the first argument as a resource key, then looks up
- * a string in the MessagesResources, based on that key, and the Locale
- *
- * TODO: error messages should be i18n :)
- *
- * @param arguments List passed in by FM, first arguement is a string used as the key
- * all subsequent arguments are used as described in MessageResources
- * (they are filled into the placehoders of the string being returned)
- */
- public TemplateModel exec(List arguments) {
- if (arguments != null) {
- String key = (String) arguments.get(0);
- arguments.remove(0);
- String mesg = messages.getMessage(locale, key, arguments.toArray());
-
- if (mesg == null) {
- return new SimpleScalar(errUnknownTag+key);
- }
- return new SimpleScalar(mesg);
- }
- else {
- return missingKeyScalar;
- }
- }
-
- // i'm not real clear on how this is used - kellan :)
- public boolean isEmpty() {
- if (messages == null)
- return true;
- else
- return false;
- }
-
- private static String errUnknownTag = "MESSAGE NOT FOUND: ";
- private static String missingKey = "MESSAGE CALL WITHOUT KEY";
- private static SimpleScalar missingKeyScalar =
- new SimpleScalar(missingKey);
-}
+/*\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 freemarker.template.SimpleScalar;\r
+import freemarker.template.TemplateMethodModel;\r
+import freemarker.template.TemplateModel;\r
+import org.apache.struts.util.MessageResources;\r
+\r
+import java.util.List;\r
+import java.util.Locale;\r
+\r
+/**\r
+ * A FreeMarker <code>TemplateMethodModel</code> that provides access to a\r
+ * Struts <code>MessageResources</code>, for use in Interantionalized templates.\r
+ *\r
+ * @author Kellan <kellan@protest.net>\r
+ */\r
+\r
+public class MessageMethodModel implements TemplateMethodModel {\r
+\r
+ /**\r
+ * The perferred locale for this instance of MessageMethod.\r
+ */\r
+ private Locale locale;\r
+\r
+ /**\r
+ * The MessageResources to query, a single instance shared for\r
+ * the lifetime of servlet.\r
+ */\r
+ private MessageResources messages;\r
+ private MessageResources messages2;\r
+\r
+\r
+ /**\r
+ * Construct a MessageMethod that uses the JVM's default locale.\r
+ *\r
+ * @param message The MessageResources object to query\r
+ */\r
+ public MessageMethodModel(MessageResources messages) {\r
+ this(null, messages);\r
+ }\r
+\r
+ /**\r
+ * Construct a MessageMethod\r
+ *\r
+ * @param locale a Locale object, persumably initialized\r
+ * from users Accept-Language header field\r
+ *\r
+ * @param message The MessageResources object to query\r
+ */\r
+ public MessageMethodModel(Locale aLocale, MessageResources aMessages) {\r
+ this(aLocale, aMessages, null);\r
+ }\r
+\r
+ public MessageMethodModel(Locale aLocale, MessageResources aMessages,\r
+ MessageResources aMessages2) {\r
+ locale = aLocale;\r
+ messages = aMessages;\r
+ messages2 = aMessages2;\r
+ }\r
+\r
+ /**\r
+ * Takes the first argument as a resource key, then looks up\r
+ * a string in the MessagesResources, based on that key, and the Locale\r
+ *\r
+ * TODO: error messages should be i18n :)\r
+ *\r
+ * @param arguments List passed in by FM, first arguement is a string used as the key\r
+ * all subsequent arguments are used as described in MessageResources\r
+ * (they are filled into the placehoders of the string being returned)\r
+ */\r
+ public TemplateModel exec(List arguments) {\r
+ if (arguments != null) {\r
+ String key = (String) arguments.get(0);\r
+ arguments.remove(0);\r
+ String mesg = null;\r
+\r
+ if (messages!=null)\r
+ mesg = messages.getMessage(locale, key, arguments.toArray());\r
+\r
+ if (mesg == null && messages2!=null) {\r
+ mesg = messages2.getMessage(locale, key, arguments.toArray());\r
+ }\r
+\r
+ if (mesg == null) {\r
+ return new SimpleScalar(errUnknownTag + key);\r
+ }\r
+ return new SimpleScalar(mesg);\r
+ }\r
+ else {\r
+ return missingKeyScalar;\r
+ }\r
+ }\r
+\r
+ // i'm not real clear on how this is used - kellan :)\r
+ public boolean isEmpty() {\r
+ if (messages == null)\r
+ return true;\r
+ else\r
+ return false;\r
+ }\r
+\r
+ private static String errUnknownTag = "MESSAGE NOT FOUND: ";\r
+ private static String missingKey = "MESSAGE CALL WITHOUT KEY";\r
+ private static SimpleScalar missingKeyScalar = new SimpleScalar(missingKey);\r
+}\r