- made a producer for startpages per topic
[mir.git] / source / mircoders / producer / StartPageProducer.java
1 package mircoders.producer;
2
3 import java.io.*;
4 import java.util.*;
5
6 import mir.misc.*;
7 import mir.entity.*;
8 import mir.producer.*;
9 import mir.generator.*;
10
11 import mircoders.localizer.*;
12 import mircoders.global.*;
13 import mircoders.entity.*;
14
15 import mircoders.module.*;
16
17 import org.apache.struts.util.MessageResources;
18
19 public class StartPageProducer implements mir.producer.Producer {
20
21   private String generatorIdentifier;
22   private String resourceBundle;
23   private String outputFile;
24   private EntityList newswireItems;
25   private EntityList features;
26   private EntityList topics;
27   private EntityList breakingNews;
28
29   EntityBrowser browser;
30
31   public StartPageProducer(
32     String aGeneratorIdentifier,
33     String aResourceBundle,
34     String anOutputFile,
35
36     EntityList aNewswireItems,
37     EntityList aFeatures,
38     EntityList aTopics,
39     EntityList aBreakingNews) {
40
41     generatorIdentifier=aGeneratorIdentifier;
42     resourceBundle=aResourceBundle;
43     outputFile=anOutputFile;
44     newswireItems = aNewswireItems;
45     features = aFeatures;
46     topics = aTopics;
47     breakingNews = aBreakingNews;
48   }
49
50   public void produce( PrintWriter aLogger ) throws ProducerException {
51     Map configMap = new HashMap();
52     Map generationValues = new HashMap();
53     Map dataMap = new HashMap();
54
55     try {
56                   configMap.put("producerDocRoot", MirGlobal.getConfigProperty("Producer.DocRoot"));
57                   configMap.put("storageRoot", MirGlobal.getConfigProperty("Producer.StorageRoot"));
58       configMap.put("productionHost", MirGlobal.getConfigProperty("Producer.ProductionHost"));
59                   configMap.put("openAction", MirGlobal.getConfigProperty("Producer.OpenAction"));
60                   configMap.put("docRoot", MirGlobal.getConfigProperty("RootUri"));
61                   configMap.put("now", StringUtil.date2readableDateTime(new GregorianCalendar()));
62                   configMap.put("videoHost", MirGlobal.getConfigProperty("Producer.Video.Host"));
63                   configMap.put("audioHost", MirGlobal.getConfigProperty("Producer.Audio.Host"));
64                   configMap.put("imageHost", MirGlobal.getConfigProperty("Producer.Image.Host"));
65                   configMap.put("imagePath", MirGlobal.getConfigProperty("Producer.Image.Path"));
66                   configMap.put("mirVersion", MirGlobal.getConfigProperty("Mir.Version"));
67                   configMap.put("compressWhitespace", new freemarker.template.utility.CompressWhitespace() );
68
69       generationValues.put("config", configMap);
70
71                   MessageResources messages = MessageResources.getMessageResources(resourceBundle);
72                   generationValues.put("lang", new MessageMethodModel(null, messages) );
73
74                   generationValues.put("data", dataMap);
75
76       dataMap.put("dc_now", StringUtil.date2w3DateTime(new GregorianCalendar()));
77       dataMap.put("newswire", newswireItems);
78       dataMap.put("features", features);
79                   dataMap.put("breakingnews", breakingNews);
80       dataMap.put("topics", topics);
81
82
83       Generator generator = MirGlobal.localizer().generators().makeGenerator(generatorIdentifier);
84
85       aLogger.println("StartPageProducer.produce:");
86       aLogger.println("generatorIdentifier = " + generatorIdentifier);
87
88       File file = new File(outputFile);
89       FileWriter fileWriter = new FileWriter(file);
90       PrintWriter printWriter = new PrintWriter(fileWriter);
91
92       aLogger.println("generating: " + outputFile);
93       generator.generate(printWriter, generationValues, aLogger);
94       printWriter.close();
95       fileWriter.close();
96       aLogger.println("done");
97     }
98     catch (Exception e) {
99       aLogger.println("exception while generating " + outputFile + ":");
100       aLogger.println(e.getMessage());
101       e.printStackTrace(aLogger);
102       aLogger.flush();
103     }
104   }
105 }