1 package mircoders.producer;
8 import freemarker.template.*;
11 import webdb.storage.*;
12 import webdb.module.*;
13 import webdb.entity.*;
21 abstract public class ProducerList extends Producer {
23 public String listTemplate;
24 public String whereClause;
25 public String orderBy;
26 public String fileDesc;
27 protected HashMap additional = new HashMap();
29 public void handle(PrintWriter htmlout, EntityUsers user, boolean sync, boolean force)
30 throws StorageObjectException, ModuleException {
31 handleIt(htmlout,user,force);
34 public void handleIt(PrintWriter htmlout, EntityUsers user, boolean force)
35 throws StorageObjectException, ModuleException {
37 logHTML(htmlout, "Producer.List: started");
38 int newsPerPage = Integer.parseInt(Configuration.getProperty("Producer.StartPage.Newswire"));
39 long sessionConnectTime = 0;
40 long startTime = (new java.util.Date()).getTime();
41 String htmlFileName = "";
42 String currentMediaId;
43 EntityContent currentContent;
45 EntityGruppen userEntity=null;
46 SimpleHash imageHash = new SimpleHash();
50 int maxItemsOnPage = Integer.parseInt(Configuration.getProperty("Lists.Max.Items"));
53 listSize = contentModule.getSize(whereClause);
54 } catch (Exception e) {
55 logHTML(htmlout,e.toString());
58 int modRest = listSize % maxItemsOnPage;
59 int numberOfPages = (listSize - modRest) / maxItemsOnPage;
61 for (int i = 0;i < numberOfPages+1;i ++) {
62 //break the loop, if only athe actuell pages should be produced
63 if (force == false && i==3) {
66 //break, if only the first page has to be produced
67 if (force == false && modRest != 0 && first==false){
73 //get the data for the first page
74 size=maxItemsOnPage + modRest;
75 list = contentModule.getContent(whereClause, orderBy, 0, size, userEntity);
78 //get the data for the other pages
79 list = contentModule.getContent(whereClause, orderBy, size, maxItemsOnPage, userEntity);
80 size = size + maxItemsOnPage;
83 //now produce the pages
84 if (list!=null || force==true) {
85 SimpleHash mergeData = HTMLTemplateProcessor.makeSimpleHashWithEntitylistInfos(list);
86 //first we try to get the images
87 SimpleList itemList = HTMLTemplateProcessor.makeSimpleList(list);
89 for (int k=0; k < list.size();k++) {
90 currentContent = (EntityContent)list.elementAt(k);
92 currentMediaId = currentContent.getValue("to_media");
93 if (currentMediaId!=null && !currentMediaId.equals("")) {
94 imageHash.put(currentMediaId, HTMLTemplateProcessor.makeSimpleHash(imageModule.getById(currentMediaId)));
97 if(currentContent.getValue("is_html").equals("0")){
98 String temp = (String)currentContent.getValue("description");
99 if(temp!=null && temp.length()>0){
100 temp = StringUtil.createHTML(temp);
101 temp = StringUtil.decodeHTMLinTags(temp);
102 currentContent.setValueForProperty("description",temp);
105 String temp = (String)currentContent.getValue("description");
106 if(temp!=null && temp.length()>0){
107 temp = StringUtil.decodeHTMLinTags(temp);
108 currentContent.setValueForProperty("description",temp);
112 mergeData.put("images", imageHash);
115 //process hashmap additional and add to mergedata
116 if (additional != null) {
117 Set set = additional.keySet();
118 for (Iterator it = set.iterator();it.hasNext();) {
119 String key = (String)it.next();
120 mergeData.put(key,(TemplateModel)additional.get(key));
125 htmlFileName = producerDocRoot + "/" + fileDesc + ".shtml";
126 mergeData.put("filename",fileDesc + ".shtml");
127 mergeData.put("previousPage","");
128 if(numberOfPages<=1){
129 mergeData.put("nextPage","");
131 mergeData.put("nextPage",fileDesc + (numberOfPages-1) + ".shtml");
134 if (i==1 && numberOfPages > 2){
135 mergeData.put("previousPage",fileDesc + ".shtml");
136 mergeData.put("nextPage",fileDesc + (numberOfPages-2) + ".shtml");
138 if (i==(numberOfPages-1)){
139 mergeData.put("previousPage",fileDesc + (numberOfPages-i+1) + ".shtml");
140 mergeData.put("nextPage","");
142 mergeData.put("previousPage",fileDesc + (numberOfPages-(i-1)) + ".shtml");
143 mergeData.put("nextPage",fileDesc + (numberOfPages-(i+1)) + ".shtml");
146 htmlFileName = producerDocRoot + "/" + fileDesc + (numberOfPages-i) + ".shtml";
147 mergeData.put("filename",fileDesc + (numberOfPages-i) + ".shtml");
150 //producing the html-files
151 boolean retVal = produce(listTemplate, htmlFileName, mergeData, htmlout);
155 sessionConnectTime = new java.util.Date().getTime() - startTime;
156 logHTML(htmlout, "Producer.List finished: " + sessionConnectTime + " ms.");
159 abstract public void setAdditional(String key, TemplateModel value);