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 public void handleIt(PrintWriter htmlout, EntityUsers user, boolean force)
39 throws StorageObjectException, ModuleException {
41 logHTML(htmlout, "Producer.List: started");
42 int newsPerPage = Integer.parseInt(MirConfig.getProp("Producer.StartPage.Newswire"));
43 long sessionConnectTime = 0;
44 long startTime = (new java.util.Date()).getTime();
45 String htmlFileName = "";
46 String currentMediaId;
47 EntityContent currentContent;
49 EntityUsers userEntity=null;
50 SimpleHash imageHash = new SimpleHash();
54 int maxItemsOnPage = Integer.parseInt(MirConfig.getProp("Lists.Max.Items"));
57 listSize = contentModule.getSize(whereClause);
58 } catch (Exception e) {
59 logHTML(htmlout,e.toString());
62 int modRest = listSize % maxItemsOnPage;
63 int numberOfPages = (listSize - modRest) / maxItemsOnPage;
65 for (int i = 0;i < numberOfPages+1;i ++) {
66 //break the loop, if only athe actuell pages should be produced
67 if (force == false && i==3) {
70 //break, if only the first page has to be produced
71 if (force == false && modRest != 0 && first==false){
77 //get the data for the first page
78 size=maxItemsOnPage + modRest;
79 list = contentModule.getContent(whereClause, orderBy, 0, size, userEntity);
82 //get the data for the other pages
83 list = contentModule.getContent(whereClause, orderBy, size, maxItemsOnPage, userEntity);
84 size = size + maxItemsOnPage;
87 //now produce the pages
88 if (list!=null || force==true) {
89 SimpleHash mergeData = HTMLTemplateProcessor.makeSimpleHashWithEntitylistInfos(list);
90 //process hashmap additional and add to mergedata
91 if (additional != null) {
92 Set set = additional.keySet();
93 for (Iterator it = set.iterator();it.hasNext();) {
94 String key = (String)it.next();
95 mergeData.put(key,(TemplateModel)additional.get(key));
100 htmlFileName = producerDocRoot + "/" + fileDesc + ".shtml";
101 mergeData.put("filename",fileDesc + ".shtml");
102 mergeData.put("previousPage","");
103 if(numberOfPages<=1){
104 mergeData.put("nextPage","");
106 mergeData.put("nextPage",fileDesc + (numberOfPages-1) + ".shtml");
109 if (i==1 && numberOfPages > 2){
110 mergeData.put("previousPage",fileDesc + ".shtml");
111 mergeData.put("nextPage",fileDesc + (numberOfPages-2) + ".shtml");
113 if (i==(numberOfPages-1)){
114 mergeData.put("previousPage",fileDesc + (numberOfPages-i+1) + ".shtml");
115 mergeData.put("nextPage","");
117 mergeData.put("previousPage",fileDesc + (numberOfPages-(i-1)) + ".shtml");
118 mergeData.put("nextPage",fileDesc + (numberOfPages-(i+1)) + ".shtml");
121 htmlFileName = producerDocRoot + "/" + fileDesc + (numberOfPages-i) + ".shtml";
122 mergeData.put("filename",fileDesc + (numberOfPages-i) + ".shtml");
125 //producing the html-files
126 boolean retVal = produce(listTemplate, htmlFileName, mergeData, htmlout);
130 sessionConnectTime = new java.util.Date().getTime() - startTime;
131 logHTML(htmlout, "Producer.List finished: " + sessionConnectTime + " ms.");
134 abstract public void setAdditional(String key, TemplateModel value);