1 package mircoders.producer;
8 import freemarker.template.*;
15 import mircoders.module.*;
16 import mircoders.entity.*;
17 import mircoders.storage.*;
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(MirConfig.getProp("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(MirConfig.getProp("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
89 for (int k=0; k < list.size();k++) {
90 currentContent = (EntityContent)list.elementAt(k);
92 EntityList currentMedia = DatabaseContentToMedia.getInstance().getImages(currentContent);
93 if (currentMedia!=null && currentMedia.getCount()>=1) {
94 SimpleList mediaList = HTMLTemplateProcessor.makeSimpleList(currentMedia);
96 SimpleList contentList = (SimpleList)mergeData.get("contentlist");
97 SimpleHash contentHash = (SimpleHash)contentList.get(k);
98 contentHash.put("to_media", mediaList);
99 } catch (Exception e){}
103 if(currentContent.getValue("is_html").equals("0")){
104 String temp = (String)currentContent.getValue("description");
105 if(temp!=null && temp.length()>0){
106 temp = StringUtil.createHTML(temp);
107 temp = StringUtil.decodeHTMLinTags(temp);
108 currentContent.setValueForProperty("description",temp);
111 String temp = (String)currentContent.getValue("description");
112 if(temp!=null && temp.length()>0){
113 temp = StringUtil.decodeHTMLinTags(temp);
114 currentContent.setValueForProperty("description",temp);
119 SimpleList itemList = HTMLTemplateProcessor.makeSimpleList(list);
120 //process hashmap additional and add to mergedata
121 if (additional != null) {
122 Set set = additional.keySet();
123 for (Iterator it = set.iterator();it.hasNext();) {
124 String key = (String)it.next();
125 mergeData.put(key,(TemplateModel)additional.get(key));
130 htmlFileName = producerDocRoot + "/" + fileDesc + ".shtml";
131 mergeData.put("filename",fileDesc + ".shtml");
132 mergeData.put("previousPage","");
133 if(numberOfPages<=1){
134 mergeData.put("nextPage","");
136 mergeData.put("nextPage",fileDesc + (numberOfPages-1) + ".shtml");
139 if (i==1 && numberOfPages > 2){
140 mergeData.put("previousPage",fileDesc + ".shtml");
141 mergeData.put("nextPage",fileDesc + (numberOfPages-2) + ".shtml");
143 if (i==(numberOfPages-1)){
144 mergeData.put("previousPage",fileDesc + (numberOfPages-i+1) + ".shtml");
145 mergeData.put("nextPage","");
147 mergeData.put("previousPage",fileDesc + (numberOfPages-(i-1)) + ".shtml");
148 mergeData.put("nextPage",fileDesc + (numberOfPages-(i+1)) + ".shtml");
151 htmlFileName = producerDocRoot + "/" + fileDesc + (numberOfPages-i) + ".shtml";
152 mergeData.put("filename",fileDesc + (numberOfPages-i) + ".shtml");
155 //producing the html-files
156 boolean retVal = produce(listTemplate, htmlFileName, mergeData, htmlout);
160 sessionConnectTime = new java.util.Date().getTime() - startTime;
161 logHTML(htmlout, "Producer.List finished: " + sessionConnectTime + " ms.");
164 abstract public void setAdditional(String key, TemplateModel value);