At last the EntityBatchingProducerNode is working. This will replace the old
[mir.git] / source / mircoders / producer / ProducerList.java
index f13b775..5533a37 100755 (executable)
@@ -2,12 +2,14 @@ package mircoders.producer;
 
 import java.io.*;
 import java.lang.*;
+import java.lang.reflect.*;
 import java.util.*;
 import java.sql.*;
 
 import freemarker.template.*;
 
 import mir.misc.*;
+import mir.media.*;
 import mir.storage.*;
 import mir.module.*;
 import mir.entity.*;
@@ -20,142 +22,118 @@ import mircoders.storage.*;
 
 abstract public class ProducerList extends Producer {
 
-       public String listTemplate;
-       public String whereClause;
-       public String orderBy;
-       public String fileDesc;
-       protected HashMap additional = new HashMap();
-
-       public void handle(PrintWriter htmlout, EntityUsers user, boolean sync, boolean force)
-               throws StorageObjectException, ModuleException {
-               handleIt(htmlout,user,force);
-       }
-
-       public void handleIt(PrintWriter htmlout, EntityUsers user, boolean force)
-               throws StorageObjectException, ModuleException {
-
-               logHTML(htmlout, "Producer.List: started");
-    int newsPerPage = Integer.parseInt(Configuration.getProperty("Producer.StartPage.Newswire"));
-               long                sessionConnectTime = 0;
-               long                startTime = (new java.util.Date()).getTime();
-               String              htmlFileName = "";
-               String              currentMediaId;
-               EntityContent       currentContent;
-               EntityList          list;
-               EntityGruppen       userEntity=null;
-               SimpleHash          imageHash = new SimpleHash();
-               int size = 0;
-               int listSize = 0;
-
-               int maxItemsOnPage = Integer.parseInt(Configuration.getProperty("Lists.Max.Items"));
-
-               try {
-                       listSize = contentModule.getSize(whereClause);
-               } catch (Exception e) {
-                       logHTML(htmlout,e.toString());
-               }
-
-               int modRest = listSize % maxItemsOnPage;
-               int numberOfPages = (listSize - modRest) / maxItemsOnPage;
-               boolean first=true;
-               for (int i = 0;i < numberOfPages+1;i ++) {
-                       //break the loop, if only athe actuell pages should be produced
-                       if (force == false && i==3) {
-                               break;
-                       }
-                       //break, if only the first page has to be produced
-                       if (force == false && modRest != 0 && first==false){
-                               break;
-                       }
-
-
-                       if (first==true) {
-                               //get the data for the first page
-                               size=maxItemsOnPage + modRest;
-                               list = contentModule.getContent(whereClause, orderBy, 0, size, userEntity);
-                               first=false;
-                       } else {
-                               //get the data for the other pages
-                               list = contentModule.getContent(whereClause, orderBy, size, maxItemsOnPage, userEntity);
-                               size = size + maxItemsOnPage;
-                       }
-
-                       //now produce the pages
-                       if (list!=null || force==true) {
-                               SimpleHash mergeData = HTMLTemplateProcessor.makeSimpleHashWithEntitylistInfos(list);
-                               //first we try to get the images
-                               SimpleList itemList = HTMLTemplateProcessor.makeSimpleList(list);
-                               if(list!=null){
-                                       for (int k=0; k < list.size();k++) {
-                                               currentContent = (EntityContent)list.elementAt(k);
-            //images to content
-                                               EntityList currentMedia = DatabaseContentToMedia.getInstance().getMedia(currentContent);
-                                               if (currentMedia!=null && currentMedia.getCount()>=1) {
-                                                       SimpleList mediaList = HTMLTemplateProcessor.makeSimpleList(currentMedia);
-                                                       mergeData.put("to_media", mediaList);
-                                               }
-            //content to html
-            if(currentContent.getValue("is_html").equals("0")){
-              String temp = (String)currentContent.getValue("description");
-              if(temp!=null && temp.length()>0){
-                temp = StringUtil.createHTML(temp);
-                temp = StringUtil.decodeHTMLinTags(temp);
-                currentContent.setValueForProperty("description",temp);
-              }
+  public String listTemplate;
+  public String whereClause;
+  public String orderBy;
+  public String fileDesc;
+  protected HashMap additional = new HashMap();
+
+
+
+  public void handle(PrintWriter htmlout, EntityUsers user, boolean sync, boolean force)
+    throws StorageObjectException, ModuleException {
+    handleIt(htmlout,user,force);
+  }
+
+  /** @todo this should return the number of pages produced! */
+  public void handleIt(PrintWriter htmlout, EntityUsers user, boolean force)
+    throws StorageObjectException, ModuleException {
+
+    logHTML(htmlout, "Producer.List: started");
+    int newsPerPage = Integer.parseInt(MirConfig.getProp("Producer.StartPage.Newswire"));
+    long                sessionConnectTime = 0;
+    long                startTime = (new java.util.Date()).getTime();
+    String              htmlFileName = "";
+    String              currentMediaId;
+    EntityContent       currentContent;
+    EntityList          list;
+    EntityUsers         userEntity=null;
+    SimpleHash          imageHash = new SimpleHash();
+    int size = 0;
+    int listSize = 0;
+
+    int maxItemsOnPage = Integer.parseInt(MirConfig.getProp("Lists.Max.Items"));
+
+    try {
+      listSize = contentModule.getSize(whereClause);
+    } catch (Exception e) {
+      logHTML(htmlout,e.toString());
+    }
+
+    int modRest = listSize % maxItemsOnPage;
+    int numberOfPages = (listSize - modRest) / maxItemsOnPage;
+    boolean first=true;
+    for (int i = 0;i < numberOfPages+1;i ++) {
+      //break the loop, if only athe actuell pages should be produced
+      if (force == false && i==3) {
+        break;
+      }
+      //break, if only the first page has to be produced
+      if (force == false && modRest != 0 && first==false){
+        break;
+      }
+
+
+      if (first==true) {
+        //get the data for the first page
+        size=maxItemsOnPage + modRest;
+        list = contentModule.getContent(whereClause, orderBy, 0, size, userEntity);
+        first=false;
+      } else {
+        //get the data for the other pages
+        list = contentModule.getContent(whereClause, orderBy, size, maxItemsOnPage, userEntity);
+        size = size + maxItemsOnPage;
+      }
+
+      //now produce the pages
+      if (list!=null || force==true) {
+        SimpleHash mergeData = HTMLTemplateProcessor.makeSimpleHashWithEntitylistInfos(list);
+        //process hashmap additional and add to mergedata
+        if (additional != null) {
+          Set set = additional.keySet();
+          for (Iterator it = set.iterator();it.hasNext();) {
+            String key = (String)it.next();
+            mergeData.put(key,(TemplateModel)additional.get(key));
+          }
+        }
+
+        if (i==0){
+          htmlFileName = producerDocRoot + "/" + fileDesc + ".shtml";
+          mergeData.put("filename",fileDesc + ".shtml");
+          mergeData.put("previousPage","");
+          if(numberOfPages<=1){
+            mergeData.put("nextPage","");
+          } else {
+            mergeData.put("nextPage",fileDesc + (numberOfPages-1) + ".shtml");
+          }
+        } else {
+          if (i==1 && numberOfPages > 2){
+            mergeData.put("previousPage",fileDesc + ".shtml");
+            mergeData.put("nextPage",fileDesc + (numberOfPages-2) + ".shtml");
+          } else {
+            if (i==(numberOfPages-1)){
+              mergeData.put("previousPage",fileDesc + (numberOfPages-i+1) + ".shtml");
+              mergeData.put("nextPage","");
             } else {
-              String temp = (String)currentContent.getValue("description");
-              if(temp!=null && temp.length()>0){
-                temp = StringUtil.decodeHTMLinTags(temp);
-                currentContent.setValueForProperty("description",temp);
-              }
+              mergeData.put("previousPage",fileDesc + (numberOfPages-(i-1)) + ".shtml");
+              mergeData.put("nextPage",fileDesc + (numberOfPages-(i+1)) + ".shtml");
             }
-                                       }
-                                       mergeData.put("images", imageHash);
-                               }
-
-                               //process hashmap additional and add to mergedata
-                               if (additional != null) {
-                                       Set set = additional.keySet();
-                                       for (Iterator it = set.iterator();it.hasNext();) {
-                                               String key = (String)it.next();
-                                               mergeData.put(key,(TemplateModel)additional.get(key));
-                                       }
-                               }
-
-                               if (i==0){
-                                       htmlFileName = producerDocRoot + "/" + fileDesc + ".shtml";
-                                       mergeData.put("filename",fileDesc + ".shtml");
-                                       mergeData.put("previousPage","");
-                                       if(numberOfPages<=1){
-                                               mergeData.put("nextPage","");
-                                       } else {
-                                               mergeData.put("nextPage",fileDesc + (numberOfPages-1) + ".shtml");
-                                       }
-                               } else {
-                                       if (i==1 && numberOfPages > 2){
-                                               mergeData.put("previousPage",fileDesc + ".shtml");
-                                               mergeData.put("nextPage",fileDesc + (numberOfPages-2) + ".shtml");
-                                       } else {
-                                               if (i==(numberOfPages-1)){
-                                                       mergeData.put("previousPage",fileDesc + (numberOfPages-i+1) + ".shtml");
-                                                       mergeData.put("nextPage","");
-                                               } else {
-                                                       mergeData.put("previousPage",fileDesc + (numberOfPages-(i-1)) + ".shtml");
-                                                       mergeData.put("nextPage",fileDesc + (numberOfPages-(i+1)) + ".shtml");
-                                               }
-                                       }
-                                       htmlFileName = producerDocRoot + "/" + fileDesc + (numberOfPages-i) + ".shtml";
-                                       mergeData.put("filename",fileDesc + (numberOfPages-i) + ".shtml");
-                               }
-
-                               //producing the html-files
-                               boolean retVal = produce(listTemplate, htmlFileName, mergeData, htmlout);
-                       } //end if
-               }//end for
-
-               sessionConnectTime = new java.util.Date().getTime() - startTime;
-               logHTML(htmlout, "Producer.List finished: " + sessionConnectTime + " ms.");
-       } //end handle
-
-       abstract public void setAdditional(String key, TemplateModel value);
+          }
+          htmlFileName = producerDocRoot + "/" + fileDesc + (numberOfPages-i) + ".shtml";
+          mergeData.put("filename",fileDesc + (numberOfPages-i) + ".shtml");
+        }
+
+        //producing the html-files
+        boolean retVal = produce(listTemplate, htmlFileName, mergeData, htmlout);
+      } //end if
+    }//end for
+
+    sessionConnectTime = new java.util.Date().getTime() - startTime;
+    logHTML(htmlout, "Producer.List finished: " + sessionConnectTime + " ms.");
+  } //end handle
+
+  public void setAdditional(String key, TemplateModel value) {
+    additional.put(key,value);
+  }
+
 }