import java.lang.*;
import java.util.*;
+
+import freemarker.template.*;
+
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());
}
/**
* 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;
+ }
}
}
else return null;
}
-
+
/**
* @return Liefert eine freemarker.template.SimpleList mit den verknuepften
* Entities, wenn es sich um eine TO_MANY Liste handelt, ansonsten
}
return null;
}
-
+
/**
* @return Liefert eine freemarker.template.SimpleList mit den verknuepften
* Entities, wenn es sich um eine TO_MANY Liste handelt, ansonsten
* 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++) {
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()));
}
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());
//######## @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()
}
// 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());
* @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)
{