From 27bf901651f76e202ee92cf407fc70396d1a3f35 Mon Sep 17 00:00:00 2001 From: rk Date: Sun, 17 Feb 2002 17:33:40 +0000 Subject: [PATCH] EntityList now freemarker compliant. Deprecated makeSimpleList(EntityList) --- source/mir/entity/EntityList.java | 73 ++++++++++++++++++++--------- source/mir/entity/EntityRelation.java | 4 +- source/mir/misc/HTMLTemplateProcessor.java | 5 +- source/mircoders/entity/EntityContent.java | 12 ++--- source/mircoders/module/ModuleBreaking.java | 6 +-- source/mircoders/module/ModuleTopics.java | 6 +-- 6 files changed, 67 insertions(+), 39 deletions(-) diff --git a/source/mir/entity/EntityList.java b/source/mir/entity/EntityList.java index 303917d1..77e5969a 100755 --- a/source/mir/entity/EntityList.java +++ b/source/mir/entity/EntityList.java @@ -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 * @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; + } } diff --git a/source/mir/entity/EntityRelation.java b/source/mir/entity/EntityRelation.java index 161855db..edd296b2 100755 --- a/source/mir/entity/EntityRelation.java +++ b/source/mir/entity/EntityRelation.java @@ -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 diff --git a/source/mir/misc/HTMLTemplateProcessor.java b/source/mir/misc/HTMLTemplateProcessor.java index cc596f7f..f6e981f6 100755 --- a/source/mir/misc/HTMLTemplateProcessor.java +++ b/source/mir/misc/HTMLTemplateProcessor.java @@ -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