282c85ba7ccbe7e4511bdc5050e5f7d9ce4d3ce1
[mir.git] / source / mircoders / producer / ProducerWap.java
1 package mircoders.producer;
2
3 import java.io.*;
4 import java.lang.*;
5 import java.util.*;
6
7 import freemarker.template.*;
8
9 import mir.misc.*;
10 import mir.storage.*;
11 import mir.module.*;
12 import mir.entity.*;
13
14 import mircoders.module.*;
15 import mircoders.storage.*;
16 import mircoders.entity.*;
17
18
19 public class ProducerWap extends Producer {
20
21         static String           wapTemplate;
22         static int              itemsPerPage;
23         static int              newsPerPage;
24
25         // Initialierung
26         static {
27                 wapTemplate = MirConfig.getProp("Producer.Wap.Template");
28                 itemsPerPage = Integer.parseInt(MirConfig.getProp("Producer.Wap.Items"));
29         }
30
31         public static void main(String argv[]){
32                 try {
33             // do we need the following? -mh <heckmann@hbe.ca>
34                         //Configuration.initConfig(argv[0]);
35                         new ProducerWap().handle(new PrintWriter(System.out), null);
36                 } catch(Exception e) {
37                         System.err.println(e.toString());
38                 }
39         }
40
41         public void handle(PrintWriter htmlout, EntityUsers user, boolean force, boolean sync)
42                 throws StorageObjectException, ModuleException
43         {
44                 printHTML(htmlout, "Producer.StartPage: started");
45
46                 long                sessionConnectTime = 0;
47                 long                startTime = (new java.util.Date()).getTime();
48                 String              nowWebdbDate = StringUtil.date2webdbDate(new GregorianCalendar());
49                 String              whereClause;
50                 String              orderBy;
51                 FileWriter          outputFile;
52                 String              xmlFileName;
53                 String              wmlFileName;
54                 EntityContent       currentContent;
55                 EntityList          entityList;
56                 SimpleHash          wapPageModel;
57                 SimpleList          contentList;
58                 String              currentMediaId;
59                 SimpleHash          imageHash = new SimpleHash();
60
61
62                 // get the breaking news
63                 // only the first 5
64                 ModuleBreaking breakingModule = new ModuleBreaking(DatabaseBreaking.getInstance());
65                 entityList = breakingModule.getByWhereClause(null,"webdb_create desc",0,itemsPerPage);
66                 SimpleList breakingList = HTMLTemplateProcessor.makeSimpleList(entityList);
67
68
69
70                 // Zusaetzlich Informationen
71                 wapPageModel = new SimpleHash();
72                 wapPageModel.put("breaking", breakingList);
73
74                 xmlFileName = producerDocRoot + "/wap/index.xml";
75                 wmlFileName = producerDocRoot + "/wap/index.wml";
76
77                 produce(wapTemplate, xmlFileName, wapPageModel, new LineFilterWriter(htmlout));
78
79                 XmlSaxonStyler styler = XmlSaxonStyler.getInstance();
80                 // clear XSL-Cache
81                 // XslStyleCache.clear();
82
83                 try {
84                         InputStream is = new FileInputStream(producerStorageRoot+xmlFileName);
85                         OutputStream os = new FileOutputStream(producerStorageRoot+wmlFileName);
86                         String contentXsl = MirConfig.getProp("Home") + "templates/" + MirConfig.getProp("Xsl.Wap");
87                         logHTML(htmlout,"using style " + contentXsl);
88                         styler.style(contentXsl,is,os);
89       is.close();
90       os.close();
91                         logHTML(htmlout,"styling done.");
92                         logHTML(htmlout, "html erstellt: <a href=\"" + producerProductionHost+  wmlFileName + "\">" + wmlFileName + "</a>");
93                 } catch (FileNotFoundException e) {
94                         System.err.println(e.toString());
95                 } catch (IOException e) {
96                         System.err.println(e.toString());
97                 } catch (org.xml.sax.SAXException e) {
98                         logHTML(htmlout,e.toString());
99                         System.err.println(e.toString());
100                 }
101
102                 // Finish
103                 sessionConnectTime = new java.util.Date().getTime() - startTime;
104                 logHTML(htmlout, "Producer.Startseite finished: " + sessionConnectTime + " ms.");
105         }
106 }
107