X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=source%2Fmircoders%2Fproducer%2FProducerList.java;h=5533a3777eda8fa300ea3449aa556357028f71f9;hb=18f61c63a073a372ec21bd0cfd090aabdc58c58b;hp=da5ea9b073dc3f14fe4933aa01483c810d48552d;hpb=86b6f499b413c722acc895346ac5186405b0c44c;p=mir.git diff --git a/source/mircoders/producer/ProducerList.java b/source/mircoders/producer/ProducerList.java index da5ea9b0..5533a377 100755 --- a/source/mircoders/producer/ProducerList.java +++ b/source/mircoders/producer/ProducerList.java @@ -2,12 +2,14 @@ package mircoders.producer; import java.io.*; import java.lang.*; +import java.lang.reflect.*; import java.util.*; import java.sql.*; import freemarker.template.*; import mir.misc.*; +import mir.media.*; import mir.storage.*; import mir.module.*; import mir.entity.*; @@ -20,142 +22,118 @@ import mircoders.storage.*; abstract public class ProducerList extends Producer { - public String listTemplate; - public String whereClause; - public String orderBy; - public String fileDesc; - protected HashMap additional = new HashMap(); + public String listTemplate; + public String whereClause; + public String orderBy; + public String fileDesc; + protected HashMap additional = new HashMap(); - public void handle(PrintWriter htmlout, EntityUsers user, boolean sync, boolean force) - throws StorageObjectException, ModuleException { - handleIt(htmlout,user,force); - } - public void handleIt(PrintWriter htmlout, EntityUsers user, boolean force) - throws StorageObjectException, ModuleException { - logHTML(htmlout, "Producer.List: started"); + public void handle(PrintWriter htmlout, EntityUsers user, boolean sync, boolean force) + throws StorageObjectException, ModuleException { + handleIt(htmlout,user,force); + } + + /** @todo this should return the number of pages produced! */ + public void handleIt(PrintWriter htmlout, EntityUsers user, boolean force) + throws StorageObjectException, ModuleException { + + logHTML(htmlout, "Producer.List: started"); int newsPerPage = Integer.parseInt(MirConfig.getProp("Producer.StartPage.Newswire")); - long sessionConnectTime = 0; - long startTime = (new java.util.Date()).getTime(); - String htmlFileName = ""; - String currentMediaId; - EntityContent currentContent; - EntityList list; - EntityGruppen userEntity=null; - SimpleHash imageHash = new SimpleHash(); - int size = 0; - int listSize = 0; - - int maxItemsOnPage = Integer.parseInt(MirConfig.getProp("Lists.Max.Items")); - - try { - listSize = contentModule.getSize(whereClause); - } catch (Exception e) { - logHTML(htmlout,e.toString()); - } - - int modRest = listSize % maxItemsOnPage; - int numberOfPages = (listSize - modRest) / maxItemsOnPage; - boolean first=true; - for (int i = 0;i < numberOfPages+1;i ++) { - //break the loop, if only athe actuell pages should be produced - if (force == false && i==3) { - break; - } - //break, if only the first page has to be produced - if (force == false && modRest != 0 && first==false){ - break; - } - - - if (first==true) { - //get the data for the first page - size=maxItemsOnPage + modRest; - list = contentModule.getContent(whereClause, orderBy, 0, size, userEntity); - first=false; - } else { - //get the data for the other pages - list = contentModule.getContent(whereClause, orderBy, size, maxItemsOnPage, userEntity); - size = size + maxItemsOnPage; - } - - //now produce the pages - if (list!=null || force==true) { - SimpleHash mergeData = HTMLTemplateProcessor.makeSimpleHashWithEntitylistInfos(list); - //first we try to get the images - SimpleList itemList = HTMLTemplateProcessor.makeSimpleList(list); - if(list!=null){ - for (int k=0; k < list.size();k++) { - currentContent = (EntityContent)list.elementAt(k); - //images to content - EntityList currentMedia = DatabaseContentToMedia.getInstance().getMedia(currentContent); - if (currentMedia!=null && currentMedia.getCount()>=1) { - SimpleList mediaList = HTMLTemplateProcessor.makeSimpleList(currentMedia); - mergeData.put("to_media", mediaList); - } - //content to html - if(currentContent.getValue("is_html").equals("0")){ - String temp = (String)currentContent.getValue("description"); - if(temp!=null && temp.length()>0){ - temp = StringUtil.createHTML(temp); - temp = StringUtil.decodeHTMLinTags(temp); - currentContent.setValueForProperty("description",temp); - } + long sessionConnectTime = 0; + long startTime = (new java.util.Date()).getTime(); + String htmlFileName = ""; + String currentMediaId; + EntityContent currentContent; + EntityList list; + EntityUsers userEntity=null; + SimpleHash imageHash = new SimpleHash(); + int size = 0; + int listSize = 0; + + int maxItemsOnPage = Integer.parseInt(MirConfig.getProp("Lists.Max.Items")); + + try { + listSize = contentModule.getSize(whereClause); + } catch (Exception e) { + logHTML(htmlout,e.toString()); + } + + int modRest = listSize % maxItemsOnPage; + int numberOfPages = (listSize - modRest) / maxItemsOnPage; + boolean first=true; + for (int i = 0;i < numberOfPages+1;i ++) { + //break the loop, if only athe actuell pages should be produced + if (force == false && i==3) { + break; + } + //break, if only the first page has to be produced + if (force == false && modRest != 0 && first==false){ + break; + } + + + if (first==true) { + //get the data for the first page + size=maxItemsOnPage + modRest; + list = contentModule.getContent(whereClause, orderBy, 0, size, userEntity); + first=false; + } else { + //get the data for the other pages + list = contentModule.getContent(whereClause, orderBy, size, maxItemsOnPage, userEntity); + size = size + maxItemsOnPage; + } + + //now produce the pages + if (list!=null || force==true) { + SimpleHash mergeData = HTMLTemplateProcessor.makeSimpleHashWithEntitylistInfos(list); + //process hashmap additional and add to mergedata + if (additional != null) { + Set set = additional.keySet(); + for (Iterator it = set.iterator();it.hasNext();) { + String key = (String)it.next(); + mergeData.put(key,(TemplateModel)additional.get(key)); + } + } + + if (i==0){ + htmlFileName = producerDocRoot + "/" + fileDesc + ".shtml"; + mergeData.put("filename",fileDesc + ".shtml"); + mergeData.put("previousPage",""); + if(numberOfPages<=1){ + mergeData.put("nextPage",""); + } else { + mergeData.put("nextPage",fileDesc + (numberOfPages-1) + ".shtml"); + } + } else { + if (i==1 && numberOfPages > 2){ + mergeData.put("previousPage",fileDesc + ".shtml"); + mergeData.put("nextPage",fileDesc + (numberOfPages-2) + ".shtml"); + } else { + if (i==(numberOfPages-1)){ + mergeData.put("previousPage",fileDesc + (numberOfPages-i+1) + ".shtml"); + mergeData.put("nextPage",""); } else { - String temp = (String)currentContent.getValue("description"); - if(temp!=null && temp.length()>0){ - temp = StringUtil.decodeHTMLinTags(temp); - currentContent.setValueForProperty("description",temp); - } + mergeData.put("previousPage",fileDesc + (numberOfPages-(i-1)) + ".shtml"); + mergeData.put("nextPage",fileDesc + (numberOfPages-(i+1)) + ".shtml"); } - } - mergeData.put("images", imageHash); - } - - //process hashmap additional and add to mergedata - if (additional != null) { - Set set = additional.keySet(); - for (Iterator it = set.iterator();it.hasNext();) { - String key = (String)it.next(); - mergeData.put(key,(TemplateModel)additional.get(key)); - } - } - - if (i==0){ - htmlFileName = producerDocRoot + "/" + fileDesc + ".shtml"; - mergeData.put("filename",fileDesc + ".shtml"); - mergeData.put("previousPage",""); - if(numberOfPages<=1){ - mergeData.put("nextPage",""); - } else { - mergeData.put("nextPage",fileDesc + (numberOfPages-1) + ".shtml"); - } - } else { - if (i==1 && numberOfPages > 2){ - mergeData.put("previousPage",fileDesc + ".shtml"); - mergeData.put("nextPage",fileDesc + (numberOfPages-2) + ".shtml"); - } else { - if (i==(numberOfPages-1)){ - mergeData.put("previousPage",fileDesc + (numberOfPages-i+1) + ".shtml"); - mergeData.put("nextPage",""); - } else { - mergeData.put("previousPage",fileDesc + (numberOfPages-(i-1)) + ".shtml"); - mergeData.put("nextPage",fileDesc + (numberOfPages-(i+1)) + ".shtml"); - } - } - htmlFileName = producerDocRoot + "/" + fileDesc + (numberOfPages-i) + ".shtml"; - mergeData.put("filename",fileDesc + (numberOfPages-i) + ".shtml"); - } - - //producing the html-files - boolean retVal = produce(listTemplate, htmlFileName, mergeData, htmlout); - } //end if - }//end for - - sessionConnectTime = new java.util.Date().getTime() - startTime; - logHTML(htmlout, "Producer.List finished: " + sessionConnectTime + " ms."); - } //end handle - - abstract public void setAdditional(String key, TemplateModel value); + } + htmlFileName = producerDocRoot + "/" + fileDesc + (numberOfPages-i) + ".shtml"; + mergeData.put("filename",fileDesc + (numberOfPages-i) + ".shtml"); + } + + //producing the html-files + boolean retVal = produce(listTemplate, htmlFileName, mergeData, htmlout); + } //end if + }//end for + + sessionConnectTime = new java.util.Date().getTime() - startTime; + logHTML(htmlout, "Producer.List finished: " + sessionConnectTime + " ms."); + } //end handle + + public void setAdditional(String key, TemplateModel value) { + additional.put(key,value); + } + }