1 package mircoders.producer;
5 import java.lang.reflect.*;
9 import freemarker.template.*;
17 import mircoders.module.*;
18 import mircoders.entity.*;
19 import mircoders.storage.*;
23 abstract public class ProducerList extends Producer {
25 public String listTemplate;
26 public String whereClause;
27 public String orderBy;
28 public String fileDesc;
29 protected HashMap additional = new HashMap();
33 public void handle(PrintWriter htmlout, EntityUsers user, boolean sync, boolean force)
34 throws StorageObjectException, ModuleException {
35 handleIt(htmlout,user,force);
38 /** @todo this should return the number of pages produced! */
39 public void handleIt(PrintWriter htmlout, EntityUsers user, boolean force)
40 throws StorageObjectException, ModuleException {
42 logHTML(htmlout, "Producer.List: started");
43 int newsPerPage = Integer.parseInt(MirConfig.getProp("Producer.StartPage.Newswire"));
44 long sessionConnectTime = 0;
45 long startTime = (new java.util.Date()).getTime();
46 String htmlFileName = "";
47 String currentMediaId;
48 EntityContent currentContent;
50 EntityUsers userEntity=null;
51 SimpleHash imageHash = new SimpleHash();
55 int maxItemsOnPage = Integer.parseInt(MirConfig.getProp("Lists.Max.Items"));
58 listSize = contentModule.getSize(whereClause);
59 } catch (Exception e) {
60 logHTML(htmlout,e.toString());
63 int modRest = listSize % maxItemsOnPage;
64 int numberOfPages = (listSize - modRest) / maxItemsOnPage;
66 for (int i = 0;i < numberOfPages+1;i ++) {
67 //break the loop, if only athe actuell pages should be produced
68 if (force == false && i==3) {
71 //break, if only the first page has to be produced
72 if (force == false && modRest != 0 && first==false){
78 //get the data for the first page
79 size=maxItemsOnPage + modRest;
80 list = contentModule.getContent(whereClause, orderBy, 0, size, userEntity);
83 //get the data for the other pages
84 list = contentModule.getContent(whereClause, orderBy, size, maxItemsOnPage, userEntity);
85 size = size + maxItemsOnPage;
88 //now produce the pages
89 if (list!=null || force==true) {
90 SimpleHash mergeData = HTMLTemplateProcessor.makeSimpleHashWithEntitylistInfos(list);
91 //process hashmap additional and add to mergedata
92 if (additional != null) {
93 Set set = additional.keySet();
94 for (Iterator it = set.iterator();it.hasNext();) {
95 String key = (String)it.next();
96 mergeData.put(key,(TemplateModel)additional.get(key));
101 htmlFileName = "/" + fileDesc + ".shtml";
102 mergeData.put("filename",fileDesc + ".shtml");
103 mergeData.put("previousPage","");
104 if(numberOfPages<=1){
105 mergeData.put("nextPage","");
107 mergeData.put("nextPage",fileDesc + (numberOfPages-1) + ".shtml");
110 if (i==1 && numberOfPages > 2){
111 mergeData.put("previousPage",fileDesc + ".shtml");
112 mergeData.put("nextPage",fileDesc + (numberOfPages-2) + ".shtml");
114 if (i==(numberOfPages-1)){
115 mergeData.put("previousPage",fileDesc + (numberOfPages-i+1) + ".shtml");
116 mergeData.put("nextPage","");
118 mergeData.put("previousPage",fileDesc + (numberOfPages-(i-1)) + ".shtml");
119 mergeData.put("nextPage",fileDesc + (numberOfPages-(i+1)) + ".shtml");
122 htmlFileName = "/" + fileDesc + (numberOfPages-i) + ".shtml";
123 mergeData.put("filename",fileDesc + (numberOfPages-i) + ".shtml");
126 //producing the html-files
127 boolean retVal = produce(listTemplate, htmlFileName, mergeData, htmlout);
131 sessionConnectTime = new java.util.Date().getTime() - startTime;
132 logHTML(htmlout, "Producer.List finished: " + sessionConnectTime + " ms.");
135 public void setAdditional(String key, TemplateModel value) {
136 additional.put(key,value);