public class ProducerContent extends Producer {
- public static void main(String argv[]){
- /**
- * Why are we reloading the config here?
- * Can someone please explain this?
- * Hope I didn't break anything
- * -mh. <heckmann@hbe.ca>
- */
- //Configuration.initConfig("config");
- System.out.println(MirConfig.getProp("Producer.DocRoot"));
-
- try {
- new ProducerContent().handle(new PrintWriter(System.out), null,
- false,false);
- } catch(Exception e) {
- System.err.println(e.toString());
- }
- }
-
-
-
- public void handle(PrintWriter htmlout, EntityUsers user, boolean force,
- boolean sync)
- throws StorageObjectException, ModuleException {
-
- handle(htmlout,user,force,sync,null);
- }
-
- public void handle(PrintWriter htmlout, EntityUsers user, boolean force,
- boolean sync, String id)
- throws StorageObjectException, ModuleException {
-
- String contentTemplate = MirConfig.getProp("Producer.Content.Template");
- int contentBatchsize =
- Integer.parseInt(MirConfig.getProp("Producer.Content.Batchsize"));
-
- long sessionConnectTime = 0;
- long startTime = (new java.util.Date()).getTime();
- String whereClause = " ";
- String orderBy = " ";
- String htmlFileName = null;
- EntityContent currentContent;
- EntityList batchEntityList;
- EntityUsers userEntity=null;
-
-
- // production of the content-pages
- orderBy="date desc, webdb_lastchange desc";
- if(force==true){
- whereClause="is_published='1'";
- // if true: produces a single content item
- if(id !=null){
- whereClause += " AND id="+id;
- }
- batchEntityList = contentModule.getContent(whereClause, orderBy, 0,
+ private String contentTemplate=MirConfig.getProp("Producer.Content.Template");
+
+ public static void main(String argv[]){
+ /**
+ * Why are we reloading the config here?
+ * Can someone please explain this?
+ * Hope I didn't break anything
+ * -mh. <heckmann@hbe.ca>
+ *
+ * This is the entry point for standalone production. The code
+ * is then running in a new virtual machine, e.g. when called
+ * from cron-script. In that case the config has to be initliased.
+ * Don't know if is ok that way //rk
+ *
+ * ok, i figured that out a few months ago.. -mh
+ *
+ */
+ //Configuration.initConfig("config");
+ System.out.println(MirConfig.getProp("Producer.DocRoot"));
+
+ try {
+ new ProducerContent().handle(new PrintWriter(System.out), null,
+ false,false);
+ } catch(Exception e) {
+ System.err.println(e.toString());
+ }
+ }
+
+
+
+ public void handle(PrintWriter htmlout, EntityUsers user, boolean force,
+ boolean sync)
+ throws StorageObjectException, ModuleException {
+
+ handle(htmlout,user,force,sync,null);
+ }
+
+ public void handle(PrintWriter htmlout, EntityUsers user, boolean force,
+ boolean sync, String id) throws StorageObjectException,
+ ModuleException
+ {
+
+ long startTime = System.currentTimeMillis();
+ int pageCount=0;
+
+ String whereClause = " ";
+ String orderBy = " ";
+ String htmlFileName = null;
+ EntityContent currentContent;
+ EntityList batchEntityList;
+ EntityUsers userEntity=null;
+
+ int contentBatchsize =
+ Integer.parseInt(MirConfig.getProp("Producer.Content.Batchsize"));
+ // production of the content-pages
+
+ /** @todo this should be moved to ModuleContent */
+ orderBy="date desc, webdb_lastchange desc";
+ if(force==true){
+ whereClause="is_published='1'";
+ // if true: produces a single content item
+ if(id !=null){
+ whereClause += " AND id="+id;
+ // I think this avoids a select count(*)...
+ contentBatchsize=-1;
+ }
+ batchEntityList = contentModule.getContent(whereClause, orderBy, 0,
+ contentBatchsize, userEntity);
+ } else {
+ whereClause="is_produced='0' AND is_published='1'";
+ //if true produces a single contentitem
+ if(id !=null){
+ whereClause += " AND id="+id;
+ // this avoids a select count(*)...
+ contentBatchsize=-1;
+ }
+ batchEntityList = contentModule.getContent(whereClause, orderBy, 0,
+ contentBatchsize, userEntity);
+ }
+
+ while (batchEntityList!=null) {
+ for(int i=0;i<batchEntityList.size();i++) {
+ currentContent = (EntityContent)batchEntityList.elementAt(i);
+
+ try {
+
+ SimpleHash mergeData=new SimpleHash();
+ mergeData.put("content", currentContent);
+
+ /** @todo this should be assembled in entity */
+ String date = currentContent.getValue("date");
+ String year = date.substring(0,4);
+ String month = date.substring(4,6);
+ htmlFileName = producerDocRoot + "/" + year + "/" + month + "/" +
+ currentContent.getValue("id") + ".shtml";
+
+ //produce html
+ boolean retVal = produce(contentTemplate, htmlFileName, mergeData, htmlout);
+ if ( retVal ) currentContent.setProduced(true);
+
+ }
+ catch(Exception e)
+ {
+ String errorText = "Producer.Content <font color=red>ERROR</font> while producing content ID:"
+ + currentContent.getId()+", skipping it :: "+e.toString();
+ logHTML(htmlout, errorText);
+ theLog.printError(errorText);
+ }
+ pageCount++;
+ }//for
+ // if next batch get it...
+ if (batchEntityList.hasNextBatch()){
+ //batchEntityList = contentModule.getByWhereClause(whereClause,
+ // null, batchEntityList.getNextBatch(),
+ // contentBatchsize);
+ batchEntityList = contentModule.getContent(whereClause, orderBy,
+ batchEntityList.getNextBatch(),
contentBatchsize, userEntity);
- } else {
- whereClause="is_produced='0' AND is_published='1'";
- //if true produces a single contentitem
- if(id !=null){
- whereClause += " AND id="+id;
- }
- batchEntityList = contentModule.getContent(whereClause, orderBy, 0,
- contentBatchsize, userEntity);
- }
-
- while (batchEntityList != null) {
- for(int i=0;i<batchEntityList.size();i++) {
- currentContent = (EntityContent)batchEntityList.elementAt(i);
- try {
- String date = currentContent.getValue("date");
- String year = date.substring(0,4);
- String month = date.substring(4,6);
- htmlFileName = producerDocRoot
- + "/" + year + "/" + month + "/" +
- currentContent.getValue("id") + ".shtml";
- //produce html
- boolean retVal = produce(contentTemplate, htmlFileName,
- currentContent, htmlout);
- sessionConnectTime = new java.util.Date().getTime() - startTime;
- if (retVal == true &&
- !"1".equals(currentContent.getValue("is_produced")))
- currentContent.setProduced(true);
- } catch(Exception e) {
- logHTML(htmlout, "Producer.Content ERROR while producing content ID:"
- + currentContent.getId()+",skipping it :: "+e.toString());
- theLog.printError("Producer.Content ERR while producing content ID: "
- + currentContent.getId() +",skipping it :: "
- +e.toString());
- }
-
- }//for
-
- if (batchEntityList.hasNextBatch()){
- batchEntityList =
- contentModule.getContent(whereClause, orderBy,
- batchEntityList.getNextBatch(),
- contentBatchsize, userEntity);
- } else {
- batchEntityList=null;
- }
- }
-
- // timing and message to browser
- sessionConnectTime = new java.util.Date().getTime() - startTime;
- logHTML(htmlout, "Producer.Content finished: " + sessionConnectTime +
- " ms.");
- }
+ } else {
+ batchEntityList=null;
+ }
+
+ }
+
+
+
+ logHTMLFinish(htmlout, "Content", pageCount, startTime, System.currentTimeMillis());
+
+ /** @todo why no syncing here? */
+
+ }
}