EntityList now freemarker compliant. Deprecated makeSimpleList(EntityList)
authorrk <rk>
Sun, 17 Feb 2002 17:33:40 +0000 (17:33 +0000)
committerrk <rk>
Sun, 17 Feb 2002 17:33:40 +0000 (17:33 +0000)
source/mir/entity/EntityList.java
source/mir/entity/EntityRelation.java
source/mir/misc/HTMLTemplateProcessor.java
source/mircoders/entity/EntityContent.java
source/mircoders/module/ModuleBreaking.java
source/mircoders/module/ModuleTopics.java

index 303917d..77e5969 100755 (executable)
@@ -7,6 +7,9 @@ package  mir.entity;
 
 import java.lang.*;
 import java.util.*;
+
+import freemarker.template.*;
+
 import mir.misc.*;
 
 
@@ -17,23 +20,28 @@ import mir.misc.*;
  * @author <RK>
  * @version    27.6.1999
  */
-public class EntityList {
-               private static Logfile     theLog;
-               private ArrayList          theEntityArrayList;
-               private String             whereClause;
-               private String             orderClause;
-               private int                count;
-               private int                offset;
-               private int                offsetnext = -1;
-               private int                offsetprev = -1;
+public class EntityList implements TemplateListModel {
+
+  private static Logfile     theLog;
+  private ArrayList          theEntityArrayList;
+  private String             whereClause;
+  private String             orderClause;
+  private int                count;
+  private int                offset;
+  private int                offsetnext = -1;
+  private int                offsetprev = -1;
+  private int                freemarkerListPointer=-1;
+
+
+  static {
+    theLog = Logfile.getInstance(MirConfig.getProp("Home") + MirConfig.getProp("Entity.Logfile"));
+  }
 
        /**
         * Konstruktor für leere Liste von Entities
         */
                public EntityList(){
                        this.theEntityArrayList = new ArrayList();
-                       if (theLog == null)
-                        this.theLog = Logfile.getInstance(this.getClass().getName());
                }
 
        /**
@@ -173,27 +181,46 @@ public class EntityList {
         * Fügt eine Entity in die Liste ein
         * @param anEntity
         */
-       public void add (Entity anEntity) {
-       if (anEntity!=null)
-                       theEntityArrayList.add(anEntity);
-       else
-                       theLog.printWarning("add (EntityList) mit leerer Entity");
-               }
+  public void add (Entity anEntity) {
+    if (anEntity!=null)
+        theEntityArrayList.add(anEntity);
+    else
+                       theLog.printWarning("EntityList: add called with empty Entity");
+  }
 
        /**
         * @return Anzahl der Entities in der Liste
         */
-               public int size() {
-       return theEntityArrayList.size();
-               }
+  public int size() {
+    return theEntityArrayList.size();
+  }
 
 
+  public Entity elementAt(int i) {
+    /** @todo check if i is in list.size() */
+    return (Entity)theEntityArrayList.get(i);
+  }
 
 
+  // Freemarker TemplateListModel methods
 
+  public TemplateModel get(int i){ return elementAt(i); }
+  public boolean isRewound() { return (freemarkerListPointer==-1) ? true : false; }
+  public void rewind() { freemarkerListPointer=-1; }
 
-               public Entity elementAt(int i) {
-                       return (Entity)theEntityArrayList.get(i);
-               }
+  public TemplateModel next() {
+    if (hasNext()) { freemarkerListPointer++;return get(freemarkerListPointer); }
+    else return null;
+  }
+
+  public boolean hasNext() {
+    return theEntityArrayList.size()>0 && freemarkerListPointer+2<=theEntityArrayList.size();
+  }
+
+  public boolean isEmpty() {
+    if (theEntityArrayList!=null)
+      return theEntityArrayList.size()>0 ;
+    else return false;
+  }
 
 }
index 161855d..edd296b 100755 (executable)
@@ -83,7 +83,7 @@ public class EntityRelation {
     }
     else return null;
   }
-  
+
   /**
    *   @return Liefert eine freemarker.template.SimpleList mit den verknuepften
    *           Entities, wenn es sich um eine TO_MANY Liste handelt, ansonsten
@@ -128,7 +128,7 @@ public class EntityRelation {
     }
     return null;
   }
-  
+
   /**
    *   @return Liefert eine freemarker.template.SimpleList mit den verknuepften
    *           Entities, wenn es sich um eine TO_MANY Liste handelt, ansonsten
index cc596f7..f6e981f 100755 (executable)
@@ -232,9 +232,12 @@ public final class HTMLTemplateProcessor {
    *   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++) {
@@ -320,7 +323,7 @@ public final class HTMLTemplateProcessor {
   public static SimpleHash makeSimpleHashWithEntitylistInfos(EntityList entList) throws StorageObjectException {
     SimpleHash modelRoot = new SimpleHash();
     if (entList!=null) {
-      modelRoot.put("contentlist", makeSimpleList(entList));
+      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()));
index 047f6bf..bccc7cf 100755 (executable)
@@ -211,7 +211,7 @@ public class EntityContent extends Entity
       }
       else if (key.equals("to_topics")) {
         try {
-          HTMLTemplateProcessor.makeSimpleList(DatabaseContentToTopics.getInstance().getTopics(this));
+          DatabaseContentToTopics.getInstance().getTopics(this);
         }
         catch (Exception ex) {
           theLog.printWarning("-- getTopics: could not fetch data " + ex.toString());
@@ -340,18 +340,16 @@ public class EntityContent extends Entity
 
   //######## @todo all of the following getBlahForContent should have
   // and optimized version where LIMIT=1 sql for list view.
-  private SimpleList getImagesForContent()
+  private EntityList getImagesForContent()
     throws StorageObjectException, TemplateModelException
   {
-    return HTMLTemplateProcessor.makeSimpleList(
-             DatabaseContentToMedia.getInstance().getImages(this) );
+    return DatabaseContentToMedia.getInstance().getImages(this);
   }
 
-  private SimpleList getAudioForContent()
+  private EntityList getAudioForContent()
     throws StorageObjectException, TemplateModelException
   {
-    return HTMLTemplateProcessor.makeSimpleList(
-             DatabaseContentToMedia.getInstance().getAudio(this) );
+    return DatabaseContentToMedia.getInstance().getAudio(this) ;
   }
 
   private SimpleList getVideoForContent()
index edb8aba..bec0c2f 100755 (executable)
@@ -40,11 +40,11 @@ public class ModuleBreaking extends AbstractModule
        }
 
        // Methoden
-  public SimpleList getBreakingNews() {
-    SimpleList returnList = null;
+  public EntityList getBreakingNews() {
+    EntityList returnList = null;
     try {
       EntityList entityList = getByWhereClause(null,"webdb_create desc",0,5);
-      returnList = HTMLTemplateProcessor.makeSimpleList(entityList);
+      returnList = entityList;
     }
     catch (Exception ex) {
       theLog.printWarning("--getBreakingNews(): could not fetch Breaking News" + ex.toString());
index 2cdf2e7..ac4f02e 100755 (executable)
@@ -50,11 +50,11 @@ public class ModuleTopics extends AbstractModule
      *  @return SimpleList of all Topics sorted by title
      *
      */
-    public SimpleList getTopicsList()
+    public EntityList getTopicsList()
     {
-      SimpleList returnList=null;
+      EntityList returnList=null;
       try {
-        returnList=HTMLTemplateProcessor.makeSimpleList(getByWhereClause("","title",-1));
+        returnList=getByWhereClause("","title",-1);
       }
       catch (Exception e)
       {