first cut of merge of STABLE-pre1_0 into HEAD. I won't even guarantee that it
[mir.git] / source / mircoders / producer / ProducerStartPage.java
1 package mircoders.producer;
2
3 import java.io.*;
4 import java.util.*;
5
6 import freemarker.template.*;
7
8 import mir.entity.*;
9 import mir.misc.*;
10 import mir.module.*;
11 import mir.storage.*;
12 import mircoders.module.*;
13 import mircoders.storage.*;
14 import mircoders.entity.*;
15
16
17 public class ProducerStartPage extends Producer {
18
19   private static String startPageTemplate = MirConfig.getProp("Producer.StartPage.Template");
20   private static int itemsPerPage = Integer.parseInt(MirConfig.getProp("Producer.StartPage.Items"));
21   private static int newsPerPage = Integer.parseInt(MirConfig.getProp("Producer.StartPage.Newswire"));
22
23   public static void main(String argv[]){
24     try {
25       // Why are we reloading the configuration here?
26       // is there something I'm missing?
27       // mh. <heckmann@hbe.ca>
28       // Configuration.initConfig(argv[0]);
29       new ProducerStartPage().handle(new PrintWriter(System.out), null);
30     } catch(Exception e) {
31       System.err.println(e.toString());
32     }
33   }
34
35   public void handle(PrintWriter htmlout, EntityUsers user, boolean force,boolean sync)
36     throws StorageObjectException, ModuleException
37   {
38     long    startTime = System.currentTimeMillis();
39     printHTML(htmlout, "Producer.StartPage: started");
40     SimpleHash startPageModel = new SimpleHash();
41
42     // breaking news
43     ModuleBreaking breakingModule = new ModuleBreaking(DatabaseBreaking.getInstance());
44     startPageModel.put("breakingnews", breakingModule.getBreakingNews());
45     startPageModel.put("topics", topicsModule.getTopicsList());
46     startPageModel.put("newswire", contentModule.getNewsWire(0,newsPerPage));
47     startPageModel.put("startspecial", contentModule.getStartArticle());
48     startPageModel.put("features", contentModule.getFeatures(0,itemsPerPage));
49
50     /** @todo switch to compressed */
51     produce(startPageTemplate, producerDocRoot + "/index.shtml", startPageModel, htmlout);
52
53     // finished
54     logHTMLFinish(htmlout, "Startpage", 1, startTime, System.currentTimeMillis());
55
56     if(sync==true){
57       logHTML(htmlout, "Producer.Startpage: rsyncing...");
58       Helper.rsync();
59       logHTML(htmlout, "Producer.Startpage: rsync done");
60     }
61   }
62 }
63