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 for(int i=0;i<batchEntityList.size();i++) {
92 currentContent = (EntityContent)batchEntityList.elementAt(i);
96 SimpleHash mergeData=new SimpleHash();
97 mergeData.put("content", currentContent);
98 String date = currentContent.getValue("date");
99 String year = date.substring(0,4);
100 String month = date.substring(4,6);
101 htmlFileName = producerDocRoot + "/" + year + "/" + month + "/" +
102 currentContent.getValue("id") + ".shtml";
105 boolean retVal = produce(contentTemplate, htmlFileName, mergeData, htmlout);
106 if ( retVal ) currentContent.setProduced(true);
111 String errorText = "Producer.Content ERROR while producing content ID:"
112 + currentContent.getId()+", skipping it :: "+e.toString();
113 logHTML(htmlout, errorText);
114 theLog.printError(errorText);
119 // timing and message to browser
120 logHTML(htmlout, "Producer.Content finished: " +
121 (System.currentTimeMillis() - startTime) + " ms.");
123 /** @todo here we should have a link back to admin logged */
124 /** @todo why no syncing here? */