1 package mircoders.producer;
8 import freemarker.template.*;
10 import com.icl.saxon.trax.Transformer;
17 import mircoders.entity.*;
18 import mircoders.storage.*;
21 public class ProducerContent extends Producer {
25 public static void main(String argv[]){
27 Configuration.initConfig("config");
29 System.out.println(Configuration.getProperty("Producer.DocRoot"));
33 new ProducerContent().handle(new PrintWriter(System.out), null, false,false);
35 } catch(Exception e) { System.err.println(e.toString()); }
41 public void handle(PrintWriter htmlout, EntityUsers user, boolean force, boolean sync)
43 throws StorageObjectException, ModuleException {
45 handle(htmlout,user,force,sync,null);
53 public void handle(PrintWriter htmlout, EntityUsers user, boolean force, boolean sync, String id)
55 throws StorageObjectException, ModuleException
61 String contentTemplate = Configuration.getProperty("Producer.Content.Template");
63 int contentBatchsize = Integer.parseInt(Configuration.getProperty("Producer.Content.Batchsize"));
65 String extLinkName = Configuration.getProperty("Producer.ExtLinkName");
67 String intLinkName = Configuration.getProperty("Producer.IntLinkName");
69 String mailLinkName = Configuration.getProperty("Producer.MailLinkName");
71 String imageRoot = Configuration.getProperty("Producer.ImageRoot");
73 long sessionConnectTime = 0;
74 long startTime = (new java.util.Date()).getTime();
75 String whereClause = " ";
77 String htmlFileName = null;
78 String currentMediaId;
79 EntityContent currentContent;
80 EntityList batchEntityList;
82 HashMap currentContentValues;
84 SimpleHash imageHash = new SimpleHash();
86 EntityGruppen userEntity=null;
90 // production of the content-pages
92 orderBy="date desc, webdb_lastchange desc";
96 whereClause="is_published='1'";
100 // if true: produces a single content item
104 whereClause += " AND id="+id;
108 batchEntityList = contentModule.getContent(whereClause, orderBy, 0, contentBatchsize, userEntity);
112 whereClause="is_produced='0' AND is_published='1'";
116 //if true produces a single contentitem
120 whereClause += " AND id="+id;
124 batchEntityList = contentModule.getContent(whereClause, orderBy, 0, contentBatchsize, userEntity);
130 while (batchEntityList != null) {
132 for(int i=0;i<batchEntityList.size();i++) {
134 currentContent = (EntityContent)batchEntityList.elementAt(i);
136 currentContentValues = currentContent.getValues();
138 //currentContentValues.put("content_data",currentContent.getContentData());
144 String date = (String)currentContentValues.get("date");
146 String year = date.substring(0,4);
148 String month = date.substring(4,6);
152 htmlFileName = producerDocRoot
154 + "/" + year + "/" + month + "/" + currentContentValues.get("id") + ".shtml";
158 currentContentValues.put("content_data",StringUtil.deleteForbiddenTags((String)currentContentValues.get("content_data")));
160 currentContentValues.put("description",StringUtil.deleteForbiddenTags((String)currentContentValues.get("description")));
164 if (currentContentValues.get("is_html").equals("0")) {
166 String temp = (String)currentContentValues.get("content_data");
168 theLog.printDebugInfo("länge:"+temp.length());
170 if(temp!=null && temp.length()>0){
172 temp = StringUtil.createHTML(temp,imageRoot,mailLinkName,extLinkName,intLinkName);
174 temp = StringUtil.decodeHTMLinTags(temp);
176 currentContentValues.put("content_data",temp);
180 temp = (String)currentContentValues.get("description");
182 if(temp!=null && temp.length()>0){
184 temp = StringUtil.createHTML(temp,imageRoot,mailLinkName,extLinkName,intLinkName);
186 temp = StringUtil.decodeHTMLinTags(temp);
188 currentContentValues.put("description",temp);
194 String temp = (String)currentContentValues.get("content_data");
196 if(temp!=null && temp.length()>0){
198 temp = StringUtil.decodeHTMLinTags(temp);
200 currentContentValues.put("content_data",temp);
204 temp = (String)currentContentValues.get("description");
206 if(temp!=null && temp.length()>0){
208 temp = StringUtil.decodeHTMLinTags(temp);
210 currentContentValues.put("description",temp);
218 SimpleHash mergeData = HTMLTemplateProcessor.makeSimpleHash(currentContentValues);
224 currentMediaId = currentContent.getValue("to_media");
226 if (currentMediaId!=null && !currentMediaId.equals("")) {
228 imageHash.put(currentMediaId, HTMLTemplateProcessor.makeSimpleHash(imageModule.getById(currentMediaId)));
232 mergeData.put("images", imageHash);
236 // get the comments for the article
238 mergeData.put("comments", currentContent.getComments());
242 // get the topics of this article
243 mergeData.put("topics",HTMLTemplateProcessor.makeSimpleList(DatabaseContentToTopics.getInstance().getTopics(currentContent)));
245 boolean retVal = produce(contentTemplate, htmlFileName, mergeData, htmlout);
246 sessionConnectTime = new java.util.Date().getTime() - startTime;
247 if (retVal == true && !"1".equals(currentContent.getValue("is_produced")))
248 currentContent.setProduced(true);
251 if (batchEntityList.hasNextBatch()){
253 batchEntityList = contentModule.getContent(whereClause, orderBy, batchEntityList.getNextBatch(),contentBatchsize, userEntity);
255 //theLog.printDebugInfo("producing next batch");
259 batchEntityList=null;
267 sessionConnectTime = new java.util.Date().getTime() - startTime;
269 logHTML(htmlout, "Producer.Content finished: " + sessionConnectTime + " ms.");