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[]){
21 Configuration.initConfig("config");
22 System.out.println(Configuration.getProperty("Producer.DocRoot"));
25 new ProducerContent().handle(new PrintWriter(System.out), null, false,false);
26 } catch(Exception e) {
27 System.err.println(e.toString());
33 public void handle(PrintWriter htmlout, EntityUsers user, boolean force, boolean sync)
34 throws StorageObjectException, ModuleException {
36 handle(htmlout,user,force,sync,null);
43 public void handle(PrintWriter htmlout, EntityUsers user, boolean force, boolean sync, String id)
44 throws StorageObjectException, ModuleException {
46 String contentTemplate = Configuration.getProperty("Producer.Content.Template");
47 int contentBatchsize = Integer.parseInt(Configuration.getProperty("Producer.Content.Batchsize"));
48 String extLinkName = Configuration.getProperty("Producer.ExtLinkName");
49 String intLinkName = Configuration.getProperty("Producer.IntLinkName");
50 String mailLinkName = Configuration.getProperty("Producer.MailLinkName");
51 String imageRoot = Configuration.getProperty("Producer.ImageRoot");
53 long sessionConnectTime = 0;
54 long startTime = (new java.util.Date()).getTime();
55 String whereClause = " ";
57 String htmlFileName = null;
58 String currentMediaId;
59 EntityContent currentContent;
60 EntityList batchEntityList;
61 HashMap currentContentValues;
62 SimpleHash imageHash = new SimpleHash();
63 EntityGruppen userEntity=null;
67 // production of the content-pages
68 orderBy="date desc, webdb_lastchange desc";
70 whereClause="is_published='1'";
71 // if true: produces a single content item
73 whereClause += " AND id="+id;
75 batchEntityList = contentModule.getContent(whereClause, orderBy, 0, contentBatchsize, userEntity);
77 whereClause="is_produced='0' AND is_published='1'";
78 //if true produces a single contentitem
80 whereClause += " AND id="+id;
82 batchEntityList = contentModule.getContent(whereClause, orderBy, 0, contentBatchsize, userEntity);
85 while (batchEntityList != null) {
86 for(int i=0;i<batchEntityList.size();i++) {
87 currentContent = (EntityContent)batchEntityList.elementAt(i);
88 currentContentValues = currentContent.getValues();
90 //because of postgres 7.1.* not needed anymore
91 //currentContentValues.put("content_data",currentContent.getContentData());
92 String date = (String)currentContentValues.get("date");
93 String year = date.substring(0,4);
94 String month = date.substring(4,6);
96 htmlFileName = producerDocRoot
97 + "/" + year + "/" + month + "/" + currentContentValues.get("id") + ".shtml";
99 currentContentValues.put("content_data",StringUtil.deleteForbiddenTags((String)currentContentValues.get("content_data")));
100 currentContentValues.put("description",StringUtil.deleteForbiddenTags((String)currentContentValues.get("description")));
103 //create http-links and email-links
104 if (currentContentValues.get("is_html").equals("0")) {
105 String temp = (String)currentContentValues.get("content_data");
106 if(temp!=null && temp.length()>0){
107 temp = StringUtil.createHTML(temp,imageRoot,mailLinkName,extLinkName,intLinkName);
108 temp = StringUtil.decodeHTMLinTags(temp);
109 currentContentValues.put("content_data",temp);
111 temp = (String)currentContentValues.get("description");
112 if(temp!=null && temp.length()>0){
113 temp = StringUtil.createHTML(temp,imageRoot,mailLinkName,extLinkName,intLinkName);
114 temp = StringUtil.decodeHTMLinTags(temp);
115 currentContentValues.put("description",temp);
118 String temp = (String)currentContentValues.get("content_data");
119 if(temp!=null && temp.length()>0){
120 temp = StringUtil.decodeHTMLinTags(temp);
121 currentContentValues.put("content_data",temp);
123 temp = (String)currentContentValues.get("description");
124 if(temp!=null && temp.length()>0){
125 temp = StringUtil.decodeHTMLinTags(temp);
126 currentContentValues.put("description",temp);
130 //create the freemarker-model
131 SimpleHash mergeData = HTMLTemplateProcessor.makeSimpleHash(currentContentValues);
134 EntityList currentMedia = DatabaseContentToMedia.getInstance().getMedia(currentContent);
135 if (currentMedia!=null && currentMedia.getCount()>=1) {
136 SimpleList mediaList = HTMLTemplateProcessor.makeSimpleList(currentMedia);
137 mergeData.put("to_media", mediaList);
140 currentMediaId = currentContent.getValue("to_media");
141 if (currentMediaId!=null && !currentMediaId.equals("")) {
142 imageHash.put(currentMediaId, HTMLTemplateProcessor.makeSimpleHash(imageModule.getById(currentMediaId)));
144 mergeData.put("images", imageHash);
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.");