1 package mircoders.producer;
\r
7 import freemarker.template.*;
\r
9 import com.icl.saxon.trax.Transformer;
\r
11 import webdb.misc.*;
\r
12 import webdb.storage.*;
\r
13 import webdb.module.*;
\r
14 import webdb.entity.*;
\r
16 import mir.module.*;
\r
17 import mir.entity.*;
\r
18 import mir.storage.*;
\r
21 public class ProducerContent extends Producer {
\r
23 public static void main(String argv[]){
\r
24 Configuration.initConfig("config");
\r
25 System.out.println(Configuration.getProperty("Producer.DocRoot"));
\r
27 new ProducerContent().handle(new PrintWriter(System.out), null, false,false);
\r
28 } catch(Exception e) { System.err.println(e.toString()); }
\r
31 public void handle(PrintWriter htmlout, EntityUsers user, boolean force, boolean sync)
\r
32 throws StorageObjectException, ModuleException {
\r
33 handle(htmlout,user,force,sync,null);
\r
37 public void handle(PrintWriter htmlout, EntityUsers user, boolean force, boolean sync, String id)
\r
38 throws StorageObjectException, ModuleException
\r
41 String contentTemplate = Configuration.getProperty("Producer.Content.Template");
\r
42 int contentBatchsize = Integer.parseInt(Configuration.getProperty("Producer.Content.Batchsize"));
\r
43 String extLinkName = Configuration.getProperty("Producer.ExtLinkName");
\r
44 String intLinkName = Configuration.getProperty("Producer.IntLinkName");
\r
45 String mailLinkName = Configuration.getProperty("Producer.MailLinkName");
\r
46 String imageRoot = Configuration.getProperty("Producer.ImageRoot");
\r
48 long sessionConnectTime = 0;
\r
49 long startTime = (new java.util.Date()).getTime();
\r
50 String whereClause = " ";
\r
51 String orderBy = " ";
\r
52 String htmlFileName = null;
\r
53 String currentMediaId;
\r
54 EntityContent currentContent;
\r
55 EntityList batchEntityList;
\r
56 HashMap currentContentValues;
\r
57 SimpleHash imageHash = new SimpleHash();
\r
58 EntityGruppen userEntity=null;
\r
60 // production of the content-pages
\r
61 orderBy="date desc, webdb_lastchange desc";
\r
63 whereClause="is_published='1'";
\r
65 // if true: produces a single content item
\r
67 whereClause += " AND id="+id;
\r
69 batchEntityList = contentModule.getContent(whereClause, orderBy, 0, contentBatchsize, userEntity);
\r
71 whereClause="is_produced='0' AND is_published='1'";
\r
73 //if true produces a single contentitem
\r
75 whereClause += " AND id="+id;
\r
77 batchEntityList = contentModule.getContent(whereClause, orderBy, 0, contentBatchsize, userEntity);
\r
80 while (batchEntityList != null) {
\r
81 for(int i=0;i<batchEntityList.size();i++) {
\r
82 currentContent = (EntityContent)batchEntityList.elementAt(i);
\r
83 currentContentValues = currentContent.getValues();
\r
84 //currentContentValues.put("content_data",currentContent.getContentData());
\r
87 String date = (String)currentContentValues.get("date");
\r
88 String year = date.substring(0,4);
\r
89 String month = date.substring(4,6);
\r
91 htmlFileName = producerDocRoot
\r
92 + "/" + year + "/" + month + "/" + currentContentValues.get("id") + ".shtml";
\r
94 currentContentValues.put("content_data",StringUtil.deleteForbiddenTags((String)currentContentValues.get("content_data")));
\r
95 currentContentValues.put("description",StringUtil.deleteForbiddenTags((String)currentContentValues.get("description")));
\r
97 if (currentContentValues.get("is_html").equals("0")) {
\r
98 String temp = (String)currentContentValues.get("content_data");
\r
99 theLog.printDebugInfo("länge:"+temp.length());
\r
100 if(temp!=null && temp.length()>0){
\r
101 temp = StringUtil.createHTML(temp,imageRoot,mailLinkName,extLinkName,intLinkName);
\r
102 temp = StringUtil.decodeHTMLinTags(temp);
\r
103 currentContentValues.put("content_data",temp);
\r
105 temp = (String)currentContentValues.get("description");
\r
106 if(temp!=null && temp.length()>0){
\r
107 temp = StringUtil.createHTML(temp,imageRoot,mailLinkName,extLinkName,intLinkName);
\r
108 temp = StringUtil.decodeHTMLinTags(temp);
\r
109 currentContentValues.put("description",temp);
\r
112 String temp = (String)currentContentValues.get("content_data");
\r
113 if(temp!=null && temp.length()>0){
\r
114 temp = StringUtil.decodeHTMLinTags(temp);
\r
115 currentContentValues.put("content_data",temp);
\r
117 temp = (String)currentContentValues.get("description");
\r
118 if(temp!=null && temp.length()>0){
\r
119 temp = StringUtil.decodeHTMLinTags(temp);
\r
120 currentContentValues.put("description",temp);
\r
124 SimpleHash mergeData = HTMLTemplateProcessor.makeSimpleHash(currentContentValues);
\r
127 currentMediaId = currentContent.getValue("to_media");
\r
128 if (currentMediaId!=null && !currentMediaId.equals("")) {
\r
129 imageHash.put(currentMediaId, HTMLTemplateProcessor.makeSimpleHash(imageModule.getById(currentMediaId)));
\r
131 mergeData.put("images", imageHash);
\r
133 // get the comments for the article
\r
134 mergeData.put("comments", currentContent.getComments());
\r
136 // get the topics of this article
\r
137 mergeData.put("topics",HTMLTemplateProcessor.makeSimpleList(DatabaseContentToTopics.getInstance().getTopics(currentContent)));
\r
139 boolean retVal = produce(contentTemplate, htmlFileName, mergeData, htmlout);
\r
140 sessionConnectTime = new java.util.Date().getTime() - startTime;
\r
141 if (retVal == true && !"1".equals(currentContent.getValue("is_produced")))
\r
142 currentContent.setProduced(true);
\r
144 if (batchEntityList.hasNextBatch()){
\r
145 batchEntityList = contentModule.getContent(whereClause, orderBy, batchEntityList.getNextBatch(),contentBatchsize, userEntity);
\r
146 //theLog.printDebugInfo("producing next batch");
\r
148 batchEntityList=null;
\r
152 sessionConnectTime = new java.util.Date().getTime() - startTime;
\r
153 logHTML(htmlout, "Producer.Content finished: " + sessionConnectTime + " ms.");
\r