language fix
[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 String featuresRSSTemplate = MirConfig.getProp("Producer.FeaturesRSS.Template");
21   private static int itemsPerPage = Integer.parseInt(MirConfig.getProp("Producer.StartPage.Items"));
22   private static int newsPerPage = Integer.parseInt(MirConfig.getProp("Producer.StartPage.Newswire"));
23
24   public static void main(String argv[]){
25     try {
26       // Why are we reloading the configuration here?
27       // is there something I'm missing?
28       // mh. <heckmann@hbe.ca>
29       // Configuration.initConfig(argv[0]);
30       new ProducerStartPage().handle(new PrintWriter(System.out), null);
31     } catch(Exception e) {
32       System.err.println(e.toString());
33     }
34   }
35
36   public void handle(PrintWriter htmlout, EntityUsers user, boolean force,boolean sync)
37     throws StorageObjectException, ModuleException
38   {
39     long    startTime = System.currentTimeMillis();
40     printHTML(htmlout, "Producer.StartPage: started");
41     SimpleHash startPageModel = new SimpleHash();
42
43     // breaking news
44     ModuleBreaking breakingModule = new ModuleBreaking(DatabaseBreaking.getInstance());
45     startPageModel.put("breakingnews", breakingModule.getBreakingNews());
46     startPageModel.put("topics", topicsModule.getTopicsList());
47     startPageModel.put("newswire", contentModule.getNewsWire(0,newsPerPage));
48     startPageModel.put("startspecial", contentModule.getStartArticle());
49     startPageModel.put("features", contentModule.getFeatures(0,itemsPerPage));
50     startPageModel.put("dc_now", new SimpleScalar(StringUtil.date2w3DateTime(new GregorianCalendar())));
51
52
53     /* @todo switch to compressed */
54     produce(startPageTemplate, "/index.shtml", startPageModel, htmlout);
55     
56     /* should be mandatory in light of new www.indy newswire.
57      *  but remember Mir is not indy specific. -mh. 
58      *  Also should it really always be produced in UTF8 chars -mh? 
59      */
60     produce(featuresRSSTemplate, "/features.1-0.rdf", startPageModel, htmlout, "UTF8");
61
62     // finished
63     logHTMLFinish(htmlout, "Startpage", 1, startTime, System.currentTimeMillis());
64
65     if(sync==true){
66       logHTML(htmlout, "Producer.Startpage: rsyncing...");
67       Helper.rsync();
68       printHTML(htmlout, "Producer.Startpage: rsync done");
69     }
70   }
71 }
72