a better solution for the popUpData: there is a new method process in HTMLTemplatePro...
authoridfx <idfx>
Mon, 25 Mar 2002 16:02:41 +0000 (16:02 +0000)
committeridfx <idfx>
Mon, 25 Mar 2002 16:02:41 +0000 (16:02 +0000)
source/mir/misc/HTMLTemplateProcessor.java
source/mir/servlet/ServletModule.java
source/mircoders/servlet/ServletModuleImages.java
templates-dist/admin/image.template

index 9688a30..af419ea 100755 (executable)
@@ -181,6 +181,23 @@ public final class HTMLTemplateProcessor {
       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);
+                                                                                                                        
+       }
 
   /**
    * Mischt die freemarker-Struktur <code>tmr</code> 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);
+       }
 
 
   /**
index 84e87bc..48f6e47 100755 (executable)
@@ -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
index 4c34b03..870a262 100755 (executable)
@@ -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) {
index 8bb84e6..f78d34e 100755 (executable)
@@ -45,7 +45,7 @@ function openWin(url) {
         <B>${lang("image.mediafolder")}:</B></font></td>
     <td>
                <select name="to_media_folder">
-               <list data.mediafolderPopupData as m>
+               <list popups.mediafolderPopupData as m>
                <option value="${m.key}" <if m.key == data.to_media_folder>selected</if>>${m.value}</option>
                </list>
            </select>