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
35 //Configuration.initConfig("config");
36 System.out.println(MirConfig.getProp("Producer.DocRoot"));
39 new ProducerContent().handle(new PrintWriter(System.out), null,
41 } catch(Exception e) {
42 System.err.println(e.toString());
48 public void handle(PrintWriter htmlout, EntityUsers user, boolean force,
50 throws StorageObjectException, ModuleException {
52 handle(htmlout,user,force,sync,null);
55 public void handle(PrintWriter htmlout, EntityUsers user, boolean force,
56 boolean sync, String id) throws StorageObjectException, ModuleException
59 long startTime = System.currentTimeMillis();
62 String whereClause = " ";
64 String htmlFileName = null;
65 EntityContent currentContent;
66 EntityList batchEntityList;
67 EntityUsers userEntity=null;
69 // production of the content-pages
71 /** @todo this should be moved to ModuleContent */
72 orderBy="date desc, webdb_lastchange desc";
74 whereClause="is_published='1'";
75 // if true: produces a single content item
77 whereClause += " AND id="+id;
79 batchEntityList = contentModule.getContent(whereClause, orderBy, 0,
82 whereClause="is_produced='0' AND is_published='1'";
83 //if true produces a single contentitem
85 whereClause += " AND id="+id;
87 batchEntityList = contentModule.getContent(whereClause, orderBy, 0,
91 if (batchEntityList!=null) {
92 for(int i=0;i<batchEntityList.size();i++) {
93 currentContent = (EntityContent)batchEntityList.elementAt(i);
97 SimpleHash mergeData=new SimpleHash();
98 mergeData.put("content", currentContent);
99 String date = currentContent.getValue("date");
100 String year = date.substring(0,4);
101 String month = date.substring(4,6);
102 htmlFileName = producerDocRoot + "/" + year + "/" + month + "/" +
103 currentContent.getValue("id") + ".shtml";
106 boolean retVal = produce(contentTemplate, htmlFileName, mergeData, htmlout);
107 if ( retVal ) currentContent.setProduced(true);
112 String errorText = "Producer.Content ERROR while producing content ID:"
113 + currentContent.getId()+", skipping it :: "+e.toString();
114 logHTML(htmlout, errorText);
115 theLog.printError(errorText);
120 // timing and message to browser
121 long overall = System.currentTimeMillis() - startTime;
122 long ppm = pageCount / (overall/60000);
123 logHTML(htmlout, "Producer.Content finished producing: " +
124 overall + " ms for "+ pageCount+" Pages = " +ppm + " pages/min");
125 logHTML(htmlout, "Back to <a href=\""+actionRoot+"\">Admin-Startage</a>");
127 /** @todo why no syncing here? */