X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=source%2Fmir%2Fmisc%2FHTMLTemplateProcessor.java;h=9faf4d02f6e30f09ab532f6e0a2b5912829887dc;hb=0525a0916e50fcf811403dcc75b7365949c6aca4;hp=1a613301896ae5e4379acce2c2454467e7bf28ef;hpb=c785369f4ca9b7a6b295464041c14206c6db84bf;p=mir.git diff --git a/source/mir/misc/HTMLTemplateProcessor.java b/source/mir/misc/HTMLTemplateProcessor.java index 1a613301..9faf4d02 100755 --- a/source/mir/misc/HTMLTemplateProcessor.java +++ b/source/mir/misc/HTMLTemplateProcessor.java @@ -13,6 +13,7 @@ import freemarker.template.*; import mir.entity.*; import mir.storage.*; import javax.servlet.http.*; +import org.apache.struts.util.MessageResources; /** @@ -20,324 +21,390 @@ import javax.servlet.http.*; */ 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 = Configuration.getProperty("Producer.DocRoot"); - protected static String producerStorageRoot = Configuration.getProperty("Producer.StorageRoot"); - - - // - // Initialisierung - - static { - templateDir = Configuration.getProperty("Home") + Configuration.getProperty("HTMLTemplateProcessor.Dir"); - templateCache = new FileTemplateCache(templateDir); - templateCache.setLoadingPolicy(templateCache.LOAD_ON_DEMAND); - //templateCache.startAutoUpdate(); - theLog = Logfile.getInstance(Configuration.getProperty("Home") + Configuration.getProperty("HTMLTemplateProcessor.Logfile")); - docRoot = Configuration.getProperty("HTMLTemplateProcessor.DocRoot"); - actionRoot = Configuration.getProperty("HTMLTemplateProcessor.ActionRoot"); - openAction = Configuration.getProperty("Producer.OpenAction"); - productionHost = Configuration.getProperty("Producer.ProductionHost"); - videoHost = Configuration.getProperty("Producer.VideoHost"); - audioHost = Configuration.getProperty("Producer.AudioHost"); - imageHost = Configuration.getProperty("Producer.Image.Host"); - producerDocRoot = Configuration.getProperty("Producer.DocRoot"); - producerStorageRoot = Configuration.getProperty("Producer.StorageRoot"); - - - } + 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 imagePath; + private static String openAction; + protected static String producerDocRoot = + MirConfig.getProp("Producer.DocRoot"); + protected static String producerStorageRoot = + MirConfig.getProp("Producer.StorageRoot"); + + // + // init + + static { + /** @todo either in the above block or here :) //rk */ + 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"); + //the quick hack is back in effect as it was more broken than ever before + // -mh + // sorry: nadir back in town, i have to debug the mirbase.jar in the + // nadir evironment. from my point of coding, this needs an urgent + // fixxx. + // yeah, from my point too - tob. + //actionRoot = docRoot + "/servlet/" + MirConfig.getProp("ServletName"); + //actionRoot = docRoot + "/servlet/NadirAktuell"; + + 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"); + imagePath = MirConfig.getProp("Producer.Image.Path"); + producerDocRoot = MirConfig.getProp("Producer.DocRoot"); + producerStorageRoot = MirConfig.getProp("Producer.StorageRoot"); + } /** - * Privater Konstruktor, um versehentliche Instantiierung zu verhindern - */ - private HTMLTemplateProcessor () { - } + * empty private constructor, to avoid instantiation + */ + private HTMLTemplateProcessor () { } - // - // process-Methoden zum Mischen verschiedener Datenstrukturen mit HTML-Templates + // process-methods to merge different datastructures + // with freemarker templates - /** - * Wandelt anEntity in freemarker-Struktur um, mischt die Daten mit - * Template templateFilename und gibt das Ergebnis an den PrintWriter - * out - * - * @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 leer!"); - else process(templateFilename, anEntity, out); - } - + /** + * Wandelt anEntity in freemarker-Struktur um, mischt die Daten mit + * Template templateFilename und gibt das Ergebnis an den PrintWriter + * out + * + * @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 entList in freemarker-Struktur um, mischt die Daten mit - * Template templateFilename und gibt das Ergebnis an den PrintWriter - * out - * - * @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 additionalModel - * unter dem Namen additionalModelName ein und mischt die Daten mit - * Template templateFilename und gibt das Ergebnis an den PrintWriter - * out - * - * @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) { - //theLog.printInfo("Keine Daten! Suche erfolglos."); - process(null,templateFilename, modelRoot, out); - } else { - try { - modelRoot = makeSimpleHashWithEntitylistInfos(entList); - // - // Hilfskruecke 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 Liste mit Entities entList in freemarker-Struktur um, mischt die Daten mit + * Template templateFilename und gibt das Ergebnis an den PrintWriter + * out + * + * @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 HashMap mergeData in freemarker-Struktur und mischt diese mit - * Template templateFilename und gibt das Ergebnis an den PrintWriter - * out - * - * @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); - } + /** + * Wandelt Entitylist in freemarker-Struktur um, fügt additionalModel + * unter dem Namen additionalModelName ein und mischt die Daten mit + * Template templateFilename und gibt das Ergebnis an den PrintWriter + * out + * + * @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 templateFilename an den PrintWriter - * out - * - * @param templateFilename - * @param mergeData - * @param out - * @exception HTMLParseException - */ - public static void process(String templateFilename, PrintWriter out) - throws HTMLParseException { - process(null,templateFilename, (TemplateModelRoot)null, out); - } + /** + * Wandelt HashMap mergeData in freemarker-Struktur und mischt diese mit + * Template templateFilename und gibt das Ergebnis an den PrintWriter + * out + * + * @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 templateFilename an den PrintWriter + * out + * + * @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 tmr mit - * Template templateFilename und gibt das Ergebnis an den PrintWriter - * out - * - * @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)); - - - 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); - - } - + * Mischt die freemarker-Struktur tmr mit + * Template templateFilename und gibt das Ergebnis an den PrintWriter + * out + * + * @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); + + } /** - * 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;itmr mit + * Template templateFilename und gibt das Ergebnis an den PrintWriter + * out + * + * @param templateFilename + * @param mergeData + * @param out + * @exception HTMLParseException + */ + public static void process(HttpServletResponse res,String templateFilename, + TemplateModelRoot tmr, TemplateModelRoot extra, + PrintWriter out, Locale locale) + 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(""); } - 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"); - 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