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();
32 SimpleHash upMediaSimpleHash;
33 Class mediaHandlerClass;
34 Class mediaStorageClass;
35 String mediaStorageName;
36 String mediaHandlerName=null;
37 MirMedia mediaHandler=null;
38 Database mediaStorage=null;
42 public void handle(PrintWriter htmlout, EntityUsers user, boolean sync, boolean force)
43 throws StorageObjectException, ModuleException {
44 handleIt(htmlout,user,force);
47 public void handleIt(PrintWriter htmlout, EntityUsers user, boolean force)
48 throws StorageObjectException, ModuleException {
50 logHTML(htmlout, "Producer.List: started");
51 int newsPerPage = Integer.parseInt(MirConfig.getProp("Producer.StartPage.Newswire"));
52 long sessionConnectTime = 0;
53 long startTime = (new java.util.Date()).getTime();
54 String htmlFileName = "";
55 String currentMediaId;
56 EntityContent currentContent;
58 EntityUsers userEntity=null;
59 SimpleHash imageHash = new SimpleHash();
63 int maxItemsOnPage = Integer.parseInt(MirConfig.getProp("Lists.Max.Items"));
66 listSize = contentModule.getSize(whereClause);
67 } catch (Exception e) {
68 logHTML(htmlout,e.toString());
71 int modRest = listSize % maxItemsOnPage;
72 int numberOfPages = (listSize - modRest) / maxItemsOnPage;
74 for (int i = 0;i < numberOfPages+1;i ++) {
75 //break the loop, if only athe actuell pages should be produced
76 if (force == false && i==3) {
79 //break, if only the first page has to be produced
80 if (force == false && modRest != 0 && first==false){
86 //get the data for the first page
87 size=maxItemsOnPage + modRest;
88 list = contentModule.getContent(whereClause, orderBy, 0, size, userEntity);
91 //get the data for the other pages
92 list = contentModule.getContent(whereClause, orderBy, size, maxItemsOnPage, userEntity);
93 size = size + maxItemsOnPage;
96 //now produce the pages
97 if (list!=null || force==true) {
98 SimpleHash mergeData = HTMLTemplateProcessor.makeSimpleHashWithEntitylistInfos(list);
99 //first we try to get the images
102 for (int k=0; k < list.size();k++) {
103 currentContent = (EntityContent)list.elementAt(k);
105 EntityList currentMediaList = DatabaseContentToMedia.getInstance().getUploadedMedia(currentContent);
106 if (currentMediaList!=null && currentMediaList.getCount()>=1) {
107 SimpleList mediaListAudio = new SimpleList();
108 SimpleList mediaListImages = new SimpleList();
109 SimpleList mediaListVideo = new SimpleList();
110 SimpleList mediaListOther = new SimpleList();
111 //SimpleHash allMediaSimpleHash = new SimpleHash();
112 for (int n=0; n < currentMediaList.size();n++) {
113 upMedia = currentMediaList.elementAt(n);
114 upMediaSimpleHash = HTMLTemplateProcessor.makeSimpleHash(upMedia);
115 mediaType = ((EntityMedia)upMedia).getMediaType();
116 //must be a non-existant to_media_type entry..
117 if (mediaType != null) {
119 mediaHandlerName = mediaType.getValue("classname");
120 mediaStorageName = mediaType.getValue("tablename");
121 mediaStorageClass = Class.forName("mircoders.storage.Database"+mediaStorageName);
122 mediaHandlerClass = Class.forName("mir.media.MediaHandler"+mediaHandlerName);
123 mediaHandler = (MirMedia)mediaHandlerClass.newInstance();
124 Method m = mediaStorageClass.getMethod("getInstance", null);
125 mediaStorage = (Database)m.invoke(null, null);
126 //we most likely need further info
127 upMedia = mediaStorage.selectById(upMedia.getId());
128 } catch (Exception e) {
129 theLog.printError("ProducerList: problem in reflection: "+mediaHandlerName);
131 upMediaSimpleHash.put("url", mediaHandler.getListView(upMedia, mediaType));
132 if (upMedia.getValue("is_published") == "1") {
133 if (mediaHandler.isImage()) {
134 mediaListImages.add(upMediaSimpleHash);
135 } else if (mediaHandler.isAudio()) {
136 mediaListAudio.add(upMediaSimpleHash);
137 } else if (mediaHandler.isVideo()) {
138 mediaListVideo.add(upMediaSimpleHash);
140 mediaListOther.add(upMediaSimpleHash);
142 } //end if is_published
143 } //end if media_type != null
146 SimpleList contentList = (SimpleList)mergeData.get("contentlist");
147 SimpleHash contentHash = (SimpleHash)contentList.get(k);
148 contentHash.put("to_media_audio", mediaListAudio);
149 contentHash.put("to_media_images", mediaListImages);
150 contentHash.put("to_media_video", mediaListVideo);
151 contentHash.put("to_media_other", mediaListOther);
152 } catch (Exception e){}
153 } //end if currentMediaList != null
156 if(currentContent.getValue("is_html").equals("0")){
157 String temp = (String)currentContent.getValue("description");
158 if(temp!=null && temp.length()>0){
159 temp = StringUtil.createHTML(temp);
160 temp = StringUtil.decodeHTMLinTags(temp);
161 currentContent.setValueForProperty("description",temp);
164 String temp = (String)currentContent.getValue("description");
165 if(temp!=null && temp.length()>0){
166 temp = StringUtil.decodeHTMLinTags(temp);
167 currentContent.setValueForProperty("description",temp);
172 SimpleList itemList = HTMLTemplateProcessor.makeSimpleList(list);
173 //process hashmap additional and add to mergedata
174 if (additional != null) {
175 Set set = additional.keySet();
176 for (Iterator it = set.iterator();it.hasNext();) {
177 String key = (String)it.next();
178 mergeData.put(key,(TemplateModel)additional.get(key));
183 htmlFileName = producerDocRoot + "/" + fileDesc + ".shtml";
184 mergeData.put("filename",fileDesc + ".shtml");
185 mergeData.put("previousPage","");
186 if(numberOfPages<=1){
187 mergeData.put("nextPage","");
189 mergeData.put("nextPage",fileDesc + (numberOfPages-1) + ".shtml");
192 if (i==1 && numberOfPages > 2){
193 mergeData.put("previousPage",fileDesc + ".shtml");
194 mergeData.put("nextPage",fileDesc + (numberOfPages-2) + ".shtml");
196 if (i==(numberOfPages-1)){
197 mergeData.put("previousPage",fileDesc + (numberOfPages-i+1) + ".shtml");
198 mergeData.put("nextPage","");
200 mergeData.put("previousPage",fileDesc + (numberOfPages-(i-1)) + ".shtml");
201 mergeData.put("nextPage",fileDesc + (numberOfPages-(i+1)) + ".shtml");
204 htmlFileName = producerDocRoot + "/" + fileDesc + (numberOfPages-i) + ".shtml";
205 mergeData.put("filename",fileDesc + (numberOfPages-i) + ".shtml");
208 //producing the html-files
209 boolean retVal = produce(listTemplate, htmlFileName, mergeData, htmlout);
213 sessionConnectTime = new java.util.Date().getTime() - startTime;
214 logHTML(htmlout, "Producer.List finished: " + sessionConnectTime + " ms.");
217 abstract public void setAdditional(String key, TemplateModel value);