producer debugging
[mir.git] / source / mircoders / producer / ProducerStartPage.java
index 20248da..8ae3e5b 100755 (executable)
 package mircoders.producer;
 
 import java.io.*;
-import java.lang.*;
 import java.util.*;
 
 import freemarker.template.*;
 
-import webdb.misc.*;
-import webdb.storage.*;
-import webdb.module.*;
-import webdb.entity.*;
-
+import mir.entity.*;
+import mir.misc.*;
 import mir.module.*;
 import mir.storage.*;
-import mir.entity.*;
+import mircoders.module.*;
+import mircoders.storage.*;
+import mircoders.entity.*;
 
 
 public class ProducerStartPage extends Producer {
 
-       private static String startPageTemplate = Configuration.getProperty("Producer.StartPage.Template");
-       private static int itemsPerPage = Integer.parseInt(Configuration.getProperty("Producer.StartPage.Items"));
-  private static int newsPerPage = Integer.parseInt(Configuration.getProperty("Producer.StartPage.Newswire"));
-
-       public static void main(String argv[]){
-               try {
-                       Configuration.initConfig(argv[0]);
-                       new ProducerStartPage().handle(new PrintWriter(System.out), null);
-               } catch(Exception e) {
-                       System.err.println(e.toString());
-               }
-       }
-
-       public void handle(PrintWriter htmlout, EntityUsers user, boolean force,boolean sync)
-               throws StorageObjectException, ModuleException
-       {
-               printHTML(htmlout, "Producer.StartPage: started");
-
-               String extLinkName = Configuration.getProperty("Producer.ExtLinkName");
-               String intLinkName = Configuration.getProperty("Producer.IntLinkName");
-               String mailLinkName = Configuration.getProperty("Producer.MailLinkName");
-               String imageRoot = Configuration.getProperty("Producer.ImageRoot");
-
-               long                sessionConnectTime = 0;
-               long                startTime = (new java.util.Date()).getTime();
-               String              nowWebdbDate = StringUtil.date2webdbDate(new GregorianCalendar());
-               String              whereClause;
-               String              orderBy;
-               FileWriter          outputFile;
-               String              htmlFileName;
-               EntityContent       currentContent;
-               EntityList          entityList;
-               SimpleHash          startPageModel;
-               SimpleList          contentList;
-               String              currentMediaId;
-               SimpleHash          imageHash = new SimpleHash();
-
-               // get the topiclist
-               entityList = topicsModule.getByWhereClause("","title",-1);
-               SimpleList topicList = HTMLTemplateProcessor.makeSimpleList(entityList);
-
-               // get the newswire
-               whereClause="is_published=true AND to_article_type >= 1";
-               entityList = contentModule.getContent(whereClause,"date desc, webdb_create desc",0,newsPerPage);
-               SimpleList newsWireList = HTMLTemplateProcessor.makeSimpleList(entityList);
-
-               // get the startarticle and the related images
-               whereClause="is_published=true AND to_article_type=4";
-               entityList = contentModule.getContent(whereClause,"date desc, webdb_create desc",0,1);
-               //if no startspecial exists
-               if (entityList==null || entityList.size()==0){
-                       whereClause="is_published=true AND to_article_type=3";
-                       entityList = contentModule.getContent(whereClause,"date desc, webdb_create desc",0,1);
-               }
-               SimpleList startItemList = HTMLTemplateProcessor.makeSimpleList(entityList);
-               for (int i=0; i < entityList.size();i++) {
-                       currentContent = (EntityContent)entityList.elementAt(i);
-                       currentMediaId = currentContent.getValue("to_media");
-                       if (currentMediaId!=null && !currentMediaId.equals("")) {
-                               imageHash.put(currentMediaId, HTMLTemplateProcessor.makeSimpleHash(imageModule.getById(currentMediaId)));
-                       }
-               }
-
-               // get the breaking news
-               // only the first 5
-               ModuleBreaking breakingModule = new ModuleBreaking(DatabaseBreaking.getInstance());
-               entityList = breakingModule.getByWhereClause(null,"webdb_create desc",0,5);
-               SimpleList breakingList = HTMLTemplateProcessor.makeSimpleList(entityList);
-
-               // get the articles
-               whereClause="is_published=true AND to_article_type=2";
-               orderBy="date desc, webdb_create desc";
-               entityList = contentModule.getContent(whereClause, orderBy, 0, itemsPerPage);
-               for (int i=0; i < entityList.size();i++) {
-                       currentContent = (EntityContent)entityList.elementAt(i);
-                       /**
-                       if (currentContent.get("is_html").equals("0")) {
-                               currentContent.put("content_data",StringUtil.createHTML((String)currentContent.get("content_data"),imageRoot,mailLinkName,extLinkName,intLinkName));
-                               currentContent.put("description",StringUtil.createHTML((String)currentContent.get("description"),imageRoot,mailLinkName,extLinkName,intLinkName));
-                       }
-                       */
-                       currentMediaId = currentContent.getValue("to_media");
-                       if (currentMediaId!=null && !currentMediaId.equals("")) {
-                               imageHash.put(currentMediaId, HTMLTemplateProcessor.makeSimpleHash(imageModule.getById(currentMediaId)));
-                       }
-               }
-               SimpleList itemList = HTMLTemplateProcessor.makeSimpleList(entityList);
-
-               // Zusaetzlich Informationen
-               startPageModel = new SimpleHash();
-               startPageModel.put("breaking", breakingList);
-               startPageModel.put("topics", topicList);
-               startPageModel.put("newswire", newsWireList);
-               startPageModel.put("start", startItemList);
-               startPageModel.put("items", itemList);
-               startPageModel.put("images", imageHash);
-
-               htmlFileName = producerDocRoot + "/index.shtml";
-
-               produce(startPageTemplate, htmlFileName, startPageModel, new LineFilterWriter(htmlout));
-
-               // Finish
-               sessionConnectTime = new java.util.Date().getTime() - startTime;
-               logHTML(htmlout, "Producer.Startseite finished: " + sessionConnectTime + " ms.");
-               if(sync==true){
-                       Helper.rsync();
-                       logHTML(htmlout, "Producer.Startseite: rsync done");
-               }
-       }
+  private static String startPageTemplate = MirConfig.getProp("Producer.StartPage.Template");
+  private static int itemsPerPage = Integer.parseInt(MirConfig.getProp("Producer.StartPage.Items"));
+  private static int newsPerPage = Integer.parseInt(MirConfig.getProp("Producer.StartPage.Newswire"));
+
+  public static void main(String argv[]){
+    try {
+      // Why are we reloading the configuration here?
+      // is there something I'm missing?
+      // mh. <heckmann@hbe.ca>
+      // Configuration.initConfig(argv[0]);
+      new ProducerStartPage().handle(new PrintWriter(System.out), null);
+    } catch(Exception e) {
+      System.err.println(e.toString());
+    }
+  }
+
+  public void handle(PrintWriter htmlout, EntityUsers user, boolean force,boolean sync)
+    throws StorageObjectException, ModuleException
+  {
+    long    startTime = System.currentTimeMillis();
+    printHTML(htmlout, "Producer.StartPage: started");
+    SimpleHash startPageModel = new SimpleHash();
+
+    // breaking news
+    ModuleBreaking breakingModule = new ModuleBreaking(DatabaseBreaking.getInstance());
+    startPageModel.put("breakingnews", breakingModule.getBreakingNews());
+    startPageModel.put("topics", topicsModule.getTopicsList());
+    startPageModel.put("newswire", contentModule.getNewsWire(0,newsPerPage));
+    startPageModel.put("startspecial", contentModule.getStartArticle());
+    startPageModel.put("features", contentModule.getFeatures(0,itemsPerPage));
+
+    /** @todo switch to compressed */
+    produce(startPageTemplate, producerDocRoot + "/index.shtml", startPageModel, htmlout);
+
+    // finished
+    logHTMLFinish(htmlout, "Startpage", 1, startTime, System.currentTimeMillis());
+
+    if(sync==true){
+      logHTML(htmlout, "Producer.Startpage: rsyncing...");
+      Helper.rsync();
+      logHTML(htmlout, "Producer.Startpage: rsync done");
+    }
+  }
 }