1 package mircoders.producer;
7 import freemarker.template.*;
14 import mircoders.entity.*;
15 import mircoders.storage.*;
18 public class ProducerContent extends Producer {
20 private String contentTemplate=MirConfig.getProp("Producer.Content.Template");
22 public static void main(String argv[]){
24 * Why are we reloading the config here?
25 * Can someone please explain this?
26 * Hope I didn't break anything
27 * -mh. <heckmann@hbe.ca>
29 * This is the entry point for standalone production. The code
30 * is then running in a new virtual machine, e.g. when called
31 * from cron-script. In that case the config has to be initliased.
32 * Don't know if is ok that way //rk
34 * ok, i figured that out a few months ago.. -mh
37 //Configuration.initConfig("config");
38 System.out.println(MirConfig.getProp("Producer.DocRoot"));
41 new ProducerContent().handle(new PrintWriter(System.out), null,
43 } catch(Exception e) {
44 System.err.println(e.toString());
50 public void handle(PrintWriter htmlout, EntityUsers user, boolean force,
52 throws StorageObjectException, ModuleException {
54 handle(htmlout,user,force,sync,null);
57 public void handle(PrintWriter htmlout, EntityUsers user, boolean force,
58 boolean sync, String id) throws StorageObjectException,
62 long startTime = System.currentTimeMillis();
65 String whereClause = " ";
67 String htmlFileName = null;
68 EntityContent currentContent;
69 EntityList batchEntityList;
70 EntityUsers userEntity=null;
72 int contentBatchsize =
73 Integer.parseInt(MirConfig.getProp("Producer.Content.Batchsize"));
74 // production of the content-pages
76 /** @todo this should be moved to ModuleContent */
77 orderBy="date desc, webdb_lastchange desc";
79 whereClause="is_published='1'";
80 // if true: produces a single content item
82 whereClause += " AND id="+id;
83 // I think this avoids a select count(*)...
86 batchEntityList = contentModule.getContent(whereClause, orderBy, 0,
87 contentBatchsize, userEntity);
89 whereClause="is_produced='0' AND is_published='1'";
90 //if true produces a single contentitem
92 whereClause += " AND id="+id;
93 // I think this avoids a select count(*)...
96 batchEntityList = contentModule.getContent(whereClause, orderBy, 0,
97 contentBatchsize, userEntity);
100 while (batchEntityList!=null) {
101 for(int i=0;i<batchEntityList.size();i++) {
102 currentContent = (EntityContent)batchEntityList.elementAt(i);
106 SimpleHash mergeData=new SimpleHash();
107 mergeData.put("content", currentContent);
108 String date = currentContent.getValue("date");
109 String year = date.substring(0,4);
110 String month = date.substring(4,6);
111 htmlFileName = producerDocRoot + "/" + year + "/" + month + "/" +
112 currentContent.getValue("id") + ".shtml";
115 boolean retVal = produce(contentTemplate, htmlFileName, mergeData, htmlout);
116 if ( retVal ) currentContent.setProduced(true);
121 String errorText = "Producer.Content <font color=red>ERROR</font> while producing content ID:"
122 + currentContent.getId()+", skipping it :: "+e.toString();
123 logHTML(htmlout, errorText);
124 theLog.printError(errorText);
128 // if next batch get it...
129 if (batchEntityList.hasNextBatch()){
130 batchEntityList = contentModule.getByWhereClause(whereClause,
131 null, batchEntityList.getNextBatch(),
134 batchEntityList=null;
141 logHTMLFinish(htmlout, "Content", pageCount, startTime, System.currentTimeMillis());
143 /** @todo why no syncing here? */