1 package mircoders.producer;
7 import freemarker.template.*;
14 import mircoders.entity.*;
15 import mircoders.storage.*;
18 public class ProducerContent extends Producer {
20 public static void main(String argv[]){
22 * Why are we reloading the config here?
23 * Can someone please explain this?
24 * Hope I didn't break anything
25 * -mh. <heckmann@hbe.ca>
27 //Configuration.initConfig("config");
28 System.out.println(MirConfig.getProp("Producer.DocRoot"));
31 new ProducerContent().handle(new PrintWriter(System.out), null, false,false);
32 } catch(Exception e) {
33 System.err.println(e.toString());
39 public void handle(PrintWriter htmlout, EntityUsers user, boolean force, boolean sync)
40 throws StorageObjectException, ModuleException {
42 handle(htmlout,user,force,sync,null);
49 public void handle(PrintWriter htmlout, EntityUsers user, boolean force, boolean sync, String id)
50 throws StorageObjectException, ModuleException {
52 String contentTemplate = MirConfig.getProp("Producer.Content.Template");
53 int contentBatchsize = Integer.parseInt(MirConfig.getProp("Producer.Content.Batchsize"));
54 String extLinkName = MirConfig.getProp("Producer.ExtLinkName");
55 String intLinkName = MirConfig.getProp("Producer.IntLinkName");
56 String mailLinkName = MirConfig.getProp("Producer.MailLinkName");
57 String imageRoot = MirConfig.getProp("Producer.ImageRoot");
59 long sessionConnectTime = 0;
60 long startTime = (new java.util.Date()).getTime();
61 String whereClause = " ";
63 String htmlFileName = null;
64 String currentMediaId;
65 EntityContent currentContent;
66 EntityList batchEntityList;
67 HashMap currentContentValues;
68 SimpleHash imageHash = new SimpleHash();
69 EntityUsers userEntity=null;
73 // production of the content-pages
74 orderBy="date desc, webdb_lastchange desc";
76 whereClause="is_published='1'";
77 // if true: produces a single content item
79 whereClause += " AND id="+id;
81 batchEntityList = contentModule.getContent(whereClause, orderBy, 0, contentBatchsize, userEntity);
83 whereClause="is_produced='0' AND is_published='1'";
84 //if true produces a single contentitem
86 whereClause += " AND id="+id;
88 batchEntityList = contentModule.getContent(whereClause, orderBy, 0, contentBatchsize, userEntity);
91 while (batchEntityList != null) {
92 for(int i=0;i<batchEntityList.size();i++) {
93 currentContent = (EntityContent)batchEntityList.elementAt(i);
94 currentContentValues = currentContent.getValues();
96 //because of postgres 7.1.* not needed anymore
97 //currentContentValues.put("content_data",currentContent.getContentData());
98 String date = (String)currentContentValues.get("date");
99 String year = date.substring(0,4);
100 String month = date.substring(4,6);
102 htmlFileName = producerDocRoot
103 + "/" + year + "/" + month + "/" + currentContentValues.get("id") + ".shtml";
105 currentContentValues.put("content_data",StringUtil.deleteForbiddenTags((String)currentContentValues.get("content_data")));
106 currentContentValues.put("description",StringUtil.deleteForbiddenTags((String)currentContentValues.get("description")));
109 //create http-links and email-links
110 if (currentContentValues.get("is_html").equals("0")) {
111 String temp = (String)currentContentValues.get("content_data");
112 if(temp!=null && temp.length()>0){
113 temp = StringUtil.createHTML(temp,imageRoot,mailLinkName,extLinkName,intLinkName);
114 temp = StringUtil.decodeHTMLinTags(temp);
115 currentContentValues.put("content_data",temp);
117 temp = (String)currentContentValues.get("description");
118 if(temp!=null && temp.length()>0){
119 temp = StringUtil.createHTML(temp,imageRoot,mailLinkName,extLinkName,intLinkName);
120 temp = StringUtil.decodeHTMLinTags(temp);
121 currentContentValues.put("description",temp);
124 String temp = (String)currentContentValues.get("content_data");
125 if(temp!=null && temp.length()>0){
126 temp = StringUtil.decodeHTMLinTags(temp);
127 currentContentValues.put("content_data",temp);
129 temp = (String)currentContentValues.get("description");
130 if(temp!=null && temp.length()>0){
131 temp = StringUtil.decodeHTMLinTags(temp);
132 currentContentValues.put("description",temp);
136 //create the freemarker-model
137 SimpleHash mergeData = HTMLTemplateProcessor.makeSimpleHash(currentContentValues);
140 EntityList currentMedia = DatabaseContentToMedia.getInstance().getImages(currentContent);
141 if (currentMedia!=null && currentMedia.getCount()>=1) {
142 SimpleList mediaList = HTMLTemplateProcessor.makeSimpleList(currentMedia);
143 mergeData.put("to_media", mediaList);
146 // get the comments for the article
147 mergeData.put("comments", currentContent.getComments());
149 // get the topics of this article
150 mergeData.put("topics",HTMLTemplateProcessor.makeSimpleList(DatabaseContentToTopics.getInstance().getTopics(currentContent)));
153 boolean retVal = produce(contentTemplate, htmlFileName, mergeData, htmlout);
154 sessionConnectTime = new java.util.Date().getTime() - startTime;
155 if (retVal == true && !"1".equals(currentContent.getValue("is_produced")))
156 currentContent.setProduced(true);
159 if (batchEntityList.hasNextBatch()){
160 batchEntityList = contentModule.getContent(whereClause, orderBy, batchEntityList.getNextBatch(),contentBatchsize, userEntity);
162 batchEntityList=null;
166 // timing an message to browser
167 sessionConnectTime = new java.util.Date().getTime() - startTime;
168 logHTML(htmlout, "Producer.Content finished: " + sessionConnectTime + " ms.");