2 * Copyright (C) 2001, 2002 The Mir-coders group
4 * This file is part of Mir.
6 * Mir is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * Mir is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with Mir; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * In addition, as a special exception, The Mir-coders gives permission to link
21 * the code of this program with the com.oreilly.servlet library, any library
22 * licensed under the Apache Software License, The Sun (tm) Java Advanced
23 * Imaging library (JAI), The Sun JIMI library (or with modified versions of
24 * the above that use the same license as the above), and distribute linked
25 * combinations including the two. You must obey the GNU General Public
26 * License in all respects for all of the code used other than the above
27 * mentioned libraries. If you modify this file, you may extend this exception
28 * to your version of the file, but you are not obligated to do so. If you do
29 * not wish to do so, delete this exception statement from your version.
32 package mircoders.producer;
36 import java.lang.reflect.*;
40 import freemarker.template.*;
48 import mircoders.module.*;
49 import mircoders.entity.*;
50 import mircoders.storage.*;
54 abstract public class ProducerList extends Producer {
56 public String listTemplate;
57 public String whereClause;
58 public String orderBy;
59 public String fileDesc;
60 protected HashMap additional = new HashMap();
64 public void handle(PrintWriter htmlout, EntityUsers user, boolean sync, boolean force)
65 throws StorageObjectException, ModuleException {
66 handleIt(htmlout,user,force);
69 /** @todo this should return the number of pages produced! */
70 public void handleIt(PrintWriter htmlout, EntityUsers user, boolean force)
71 throws StorageObjectException, ModuleException {
73 logHTML(htmlout, "Producer.List: started");
74 int newsPerPage = Integer.parseInt(MirConfig.getProp("Producer.StartPage.Newswire"));
75 long sessionConnectTime = 0;
76 long startTime = (new java.util.Date()).getTime();
77 String htmlFileName = "";
78 String currentMediaId;
79 EntityContent currentContent;
81 EntityUsers userEntity=null;
82 SimpleHash imageHash = new SimpleHash();
86 int maxItemsOnPage = Integer.parseInt(MirConfig.getProp("Lists.Max.Items"));
89 listSize = contentModule.getSize(whereClause);
90 } catch (Exception e) {
91 logHTML(htmlout,e.toString());
94 int modRest = listSize % maxItemsOnPage;
95 int numberOfPages = (listSize - modRest) / maxItemsOnPage;
97 for (int i = 0;i < numberOfPages+1;i ++) {
98 //break the loop, if only athe actuell pages should be produced
99 if (force == false && i==3) {
102 //break, if only the first page has to be produced
103 if (force == false && modRest != 0 && first==false){
109 //get the data for the first page
110 size=maxItemsOnPage + modRest;
111 list = contentModule.getContent(whereClause, orderBy, 0, size, userEntity);
114 //get the data for the other pages
115 list = contentModule.getContent(whereClause, orderBy, size, maxItemsOnPage, userEntity);
116 size = size + maxItemsOnPage;
119 //now produce the pages
120 if (list!=null || force==true) {
121 SimpleHash mergeData = HTMLTemplateProcessor.makeSimpleHashWithEntitylistInfos(list);
122 //process hashmap additional and add to mergedata
123 if (additional != null) {
124 Set set = additional.keySet();
125 for (Iterator it = set.iterator();it.hasNext();) {
126 String key = (String)it.next();
127 mergeData.put(key,(TemplateModel)additional.get(key));
132 htmlFileName = "/" + fileDesc + ".shtml";
133 mergeData.put("filename",fileDesc + ".shtml");
134 mergeData.put("previousPage","");
135 if(numberOfPages<=1){
136 mergeData.put("nextPage","");
138 mergeData.put("nextPage",fileDesc + (numberOfPages-1) + ".shtml");
141 if (i==1 && numberOfPages > 2){
142 mergeData.put("previousPage",fileDesc + ".shtml");
143 mergeData.put("nextPage",fileDesc + (numberOfPages-2) + ".shtml");
145 if (i==(numberOfPages-1)){
146 mergeData.put("previousPage",fileDesc + (numberOfPages-i+1) + ".shtml");
147 mergeData.put("nextPage","");
149 mergeData.put("previousPage",fileDesc + (numberOfPages-(i-1)) + ".shtml");
150 mergeData.put("nextPage",fileDesc + (numberOfPages-(i+1)) + ".shtml");
153 htmlFileName = "/" + fileDesc + (numberOfPages-i) + ".shtml";
154 mergeData.put("filename",fileDesc + (numberOfPages-i) + ".shtml");
157 //producing the html-files
158 boolean retVal = produce(listTemplate, htmlFileName, mergeData, htmlout);
162 sessionConnectTime = new java.util.Date().getTime() - startTime;
163 logHTML(htmlout, "Producer.List finished: " + sessionConnectTime + " ms.");
166 public void setAdditional(String key, TemplateModel value) {
167 additional.put(key,value);