1 package mircoders.producer;
7 import freemarker.template.*;
14 import mircoders.entity.*;
15 import mircoders.storage.*;
18 public class ProducerContent extends Producer {
20 public static void main(String argv[]){
22 * Why are we reloading the config here?
23 * Can someone please explain this?
24 * Hope I didn't break anything
25 * -mh. <heckmann@hbe.ca>
27 //Configuration.initConfig("config");
28 System.out.println(MirConfig.getProp("Producer.DocRoot"));
31 new ProducerContent().handle(new PrintWriter(System.out), null, false,false);
32 } catch(Exception e) {
33 System.err.println(e.toString());
39 public void handle(PrintWriter htmlout, EntityUsers user, boolean force, boolean sync)
40 throws StorageObjectException, ModuleException {
42 handle(htmlout,user,force,sync,null);
46 public void handle(PrintWriter htmlout, EntityUsers user, boolean force, boolean sync, String id)
47 throws StorageObjectException, ModuleException {
49 String contentTemplate = MirConfig.getProp("Producer.Content.Template");
50 int contentBatchsize = Integer.parseInt(MirConfig.getProp("Producer.Content.Batchsize"));
52 long sessionConnectTime = 0;
53 long startTime = (new java.util.Date()).getTime();
54 String whereClause = " ";
56 String htmlFileName = null;
57 EntityContent currentContent;
58 EntityList batchEntityList;
59 EntityUsers userEntity=null;
62 // production of the content-pages
63 orderBy="date desc, webdb_lastchange desc";
65 whereClause="is_published='1'";
66 // if true: produces a single content item
68 whereClause += " AND id="+id;
70 batchEntityList = contentModule.getContent(whereClause, orderBy, 0, contentBatchsize, userEntity);
72 whereClause="is_produced='0' AND is_published='1'";
73 //if true produces a single contentitem
75 whereClause += " AND id="+id;
77 batchEntityList = contentModule.getContent(whereClause, orderBy, 0, contentBatchsize, userEntity);
80 while (batchEntityList != null) {
81 for(int i=0;i<batchEntityList.size();i++) {
82 currentContent = (EntityContent)batchEntityList.elementAt(i);
84 String date = currentContent.getValue("date");
85 String year = date.substring(0,4);
86 String month = date.substring(4,6);
87 htmlFileName = producerDocRoot
88 + "/" + year + "/" + month + "/" + currentContent.getValue("id") + ".shtml";
90 boolean retVal = produce(contentTemplate, htmlFileName, currentContent, htmlout);
91 sessionConnectTime = new java.util.Date().getTime() - startTime;
92 if (retVal == true && !"1".equals(currentContent.getValue("is_produced")))
93 currentContent.setProduced(true);
94 } catch(Exception e) {
95 logHTML(htmlout, "Producer.Content ERROR while producing content ID: " + currentContent.getId()+",skipping it :: "+e.toString());
96 theLog.printError("Producer.Content ERROR while producing content ID: " + currentContent.getId() +",skipping it :: "+e.toString());
101 if (batchEntityList.hasNextBatch()){
102 batchEntityList = contentModule.getContent(whereClause, orderBy, batchEntityList.getNextBatch(),contentBatchsize, userEntity);
104 batchEntityList=null;
108 // timing and message to browser
109 sessionConnectTime = new java.util.Date().getTime() - startTime;
110 logHTML(htmlout, "Producer.Content finished: " + sessionConnectTime + " ms.");