From 96e3f217ad3b3e4582e9b07966df8daf14072189 Mon Sep 17 00:00:00 2001 From: idfx Date: Mon, 25 Mar 2002 16:02:41 +0000 Subject: [PATCH] a better solution for the popUpData: there is a new method process in HTMLTemplateProcessor with a second TemplateModelRoot parameter. this Parameter should be used for PopUpData, it is merged into the templates as SimpleHash with the name popups --- source/mir/misc/HTMLTemplateProcessor.java | 111 +++++++++++++--------- source/mir/servlet/ServletModule.java | 68 ++++++------- source/mircoders/servlet/ServletModuleImages.java | 15 ++- templates-dist/admin/image.template | 2 +- 4 files changed, 111 insertions(+), 85 deletions(-) diff --git a/source/mir/misc/HTMLTemplateProcessor.java b/source/mir/misc/HTMLTemplateProcessor.java index 9688a308..af419eac 100755 --- a/source/mir/misc/HTMLTemplateProcessor.java +++ b/source/mir/misc/HTMLTemplateProcessor.java @@ -181,6 +181,23 @@ public final class HTMLTemplateProcessor { 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, Locale locale) + throws HTMLParseException { + process(res,templateFilename,tmr,null,out,locale); + + } /** * Mischt die freemarker-Struktur tmr mit @@ -192,51 +209,57 @@ public final class HTMLTemplateProcessor { * @param out * @exception HTMLParseException */ - public static void process(HttpServletResponse res,String templateFilename, - TemplateModelRoot tmr, 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(""); - } - - /** @todo why do we double those? should be cleaned up and - * statically initialized, we do not need to assemble a config - * hash everytime we give out a page, only exception is - * date "now" // rk */ - // put standard configuration into tempalteRootmodel - SimpleHash configHash = new SimpleHash(); - configHash.put("producerDocRoot", 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)); - configHash.put("docRoot", new SimpleScalar(docRoot)); - configHash.put("now", new SimpleScalar(StringUtil.date2readableDateTime(new GregorianCalendar()))); - configHash.put("actionRoot", new SimpleScalar(actionRoot+session)); - configHash.put("productionHost", new SimpleScalar(productionHost)); - configHash.put("videoHost", new SimpleScalar(videoHost)); - configHash.put("audioHost", new SimpleScalar(audioHost)); - configHash.put("imageHost", new SimpleScalar(imageHost)); - configHash.put("mirVersion", new SimpleScalar(MirConfig.getProp("Mir.Version"))); - // this conform to updated freemarker syntax - configHash.put("compressWhitespace", new freemarker.template.utility.CompressWhitespace() ); + public static void process(HttpServletResponse res,String templateFilename, + TemplateModelRoot tmr, TemplateModelRoot popups, + 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(""); + } + + // put standard configuration into tempalteRootmodel + SimpleHash configHash = new SimpleHash(); + configHash.put("producerDocRoot", 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)); + configHash.put("docRoot", new SimpleScalar(docRoot)); + configHash.put("now", new SimpleScalar(StringUtil.date2readableDateTime(new GregorianCalendar()))); + configHash.put("actionRoot", new SimpleScalar(actionRoot+session)); + configHash.put("productionHost", new SimpleScalar(productionHost)); + configHash.put("videoHost", new SimpleScalar(videoHost)); + configHash.put("audioHost", new SimpleScalar(audioHost)); + configHash.put("imageHost", new SimpleScalar(imageHost)); + configHash.put("mirVersion", new SimpleScalar(MirConfig.getProp("Mir.Version"))); + // this conform to updated freemarker syntax + configHash.put("compressWhitespace", new freemarker.template.utility.CompressWhitespace() ); + + SimpleHash outPutHash = new SimpleHash(); - SimpleHash outPutHash = new SimpleHash(); - outPutHash.put("data",tmr); - outPutHash.put("config", configHash); - - MessageResources messages = MessageResources.getMessageResources("admin"); - outPutHash.put("lang", new MessageMethodModel(locale, messages) ); - - tmpl.process(outPutHash,out); - } + if(popups!=null){ + outPutHash.put("popups",popups); + try{ + while(((SimpleList)popups).hasNext()){ + theLog.printDebugInfo(((SimpleList)popups).next().toString()); + } + }catch(Exception e){} + } + outPutHash.put("data",tmr); + outPutHash.put("config", configHash); + + MessageResources messages = MessageResources.getMessageResources("admin"); + outPutHash.put("lang", new MessageMethodModel(locale, messages) ); + + tmpl.process(outPutHash,out); + } /** diff --git a/source/mir/servlet/ServletModule.java b/source/mir/servlet/ServletModule.java index 84e87bc2..48f6e47b 100755 --- a/source/mir/servlet/ServletModule.java +++ b/source/mir/servlet/ServletModule.java @@ -2,6 +2,8 @@ package mir.servlet; import freemarker.template.SimpleHash; import freemarker.template.TemplateModelRoot; +import freemarker.template.TemplateModel; + import mir.entity.EntityList; import mir.misc.*; import mir.module.AbstractModule; @@ -271,22 +273,6 @@ public abstract class ServletModule { } } - // Hilfsprozeduren - /** - public void predeliver(HttpServletResponse res, TemplateModelRoot rtm, String tmpl) - throws ServletModuleException { - try { - PrintWriter out = new LineFilterWriter(res.getWriter()); - StringWriter a = new StringWriter(); - deliver(new PrintWriter(a),rtm,tmpl); - out.write(a.toString()); - out.flush(); - } catch (Exception e) { - e.printStackTrace();System.err.println(e.toString()); - } - } - */ - /** * deliver liefert das Template mit dem Filenamen templateFilename * an den HttpServletResponse res aus, nachdem es mit den Daten aus @@ -298,23 +284,41 @@ public abstract class ServletModule { * @param tmpl Name des Templates * @exception ServletModuleException */ - public void deliver(HttpServletRequest req, HttpServletResponse res, TemplateModelRoot rtm, String templateFilename) - throws ServletModuleException { - if (rtm == null) rtm = new SimpleHash(); - try { - //PrintWriter out = new LineFilterWriter(res.getWriter()); - PrintWriter out = res.getWriter(); - HTMLTemplateProcessor.process(res, templateFilename, rtm, out, getLocale(req)); - out.close(); - } - catch (HTMLParseException e) { - throw new ServletModuleException(e.toString()); - } - catch (IOException e) { - throw new ServletModuleException(e.toString()); - } - } + public void deliver(HttpServletRequest req, HttpServletResponse res, + TemplateModelRoot rtm, TemplateModelRoot popups, + String templateFilename) + throws ServletModuleException { + if (rtm == null) rtm = new SimpleHash(); + try { + PrintWriter out = res.getWriter(); + HTMLTemplateProcessor.process(res, templateFilename, rtm, popups, out, + getLocale(req)); + out.close(); + } catch (HTMLParseException e) { + throw new ServletModuleException(e.toString()); + } catch (IOException e) { + throw new ServletModuleException(e.toString()); + } + } + + /** + * deliver liefert das Template mit dem Filenamen templateFilename + * an den HttpServletResponse res aus, nachdem es mit den Daten aus + * TemplateModelRoot rtm gemischt wurde + * + * @param res Http-Response, die vom Dispatcher durchgereicht wird + * @param rtm beinahalten das freemarker.template.TempalteModelRoot mit den + * Daten, die ins Template gemerged werden sollen. + * @param tmpl Name des Templates + * @exception ServletModuleException + */ + public void deliver(HttpServletRequest req, HttpServletResponse res, + TemplateModelRoot rtm, String templateFilename) + throws ServletModuleException { + deliver(req, res, rtm, null, templateFilename); + } + /** * deliver liefert das Template mit dem Filenamen templateFilename * an den HttpServletResponse res aus, nachdem es mit den Daten aus diff --git a/source/mircoders/servlet/ServletModuleImages.java b/source/mircoders/servlet/ServletModuleImages.java index 4c34b033..870a262c 100755 --- a/source/mircoders/servlet/ServletModuleImages.java +++ b/source/mircoders/servlet/ServletModuleImages.java @@ -285,9 +285,9 @@ public class ServletModuleImages extends mir.servlet.ServletModule try { SimpleHash mergeData = new SimpleHash(); mergeData.put("new", "1"); - mergeData.put("mediafolderPopupData", - DatabaseMediafolder.getInstance().getPopupData()); - deliver(req, res, mergeData, templateObjektString); + SimpleHash popups = new SimpleHash(); + popups.put("mediafolderPopupData",DatabaseMediafolder.getInstance().getPopupData()); + deliver(req, res, mergeData, popups, templateObjektString); } catch (Exception e) { throw new ServletModuleException(e.toString());} } @@ -302,11 +302,10 @@ public class ServletModuleImages extends mir.servlet.ServletModule throws ServletModuleException { if (idParam!=null && !idParam.equals("")) { try { - EntityImages entity = (EntityImages)mainModule.getById(idParam); - SimpleHash mergeData = HTMLTemplateProcessor.makeSimpleHash(entity); - mergeData.put("mediafolderPopupData", - DatabaseMediafolder.getInstance().getPopupData()); - deliver(req, res, mergeData, templateObjektString); + SimpleHash popups = new SimpleHash(); + popups.put("mediafolderPopupData",DatabaseMediafolder.getInstance().getPopupData()); + deliver(req, res, mainModule.getById(idParam),popups, + templateObjektString); } catch (ModuleException e) { throw new ServletModuleException(e.toString()); } catch (StorageObjectException e) { diff --git a/templates-dist/admin/image.template b/templates-dist/admin/image.template index 8bb84e61..f78d34ef 100755 --- a/templates-dist/admin/image.template +++ b/templates-dist/admin/image.template @@ -45,7 +45,7 @@ function openWin(url) { ${lang("image.mediafolder")}: -- 2.11.0