mass update mir codeswitch
[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 = Configuration.getProperty("Producer.Wap.Template");
28                 itemsPerPage = Integer.parseInt(Configuration.getProperty("Producer.Wap.Items"));
29         }
30
31         public static void main(String argv[]){
32                 try {
33                         Configuration.initConfig(argv[0]);
34                         new ProducerWap().handle(new PrintWriter(System.out), null);
35                 } catch(Exception e) {
36                         System.err.println(e.toString());
37                 }
38         }
39
40         public void handle(PrintWriter htmlout, EntityUsers user, boolean force, boolean sync)
41                 throws StorageObjectException, ModuleException
42         {
43                 printHTML(htmlout, "Producer.StartPage: started");
44
45                 long                sessionConnectTime = 0;
46                 long                startTime = (new java.util.Date()).getTime();
47                 String              nowWebdbDate = StringUtil.date2webdbDate(new GregorianCalendar());
48                 String              whereClause;
49                 String              orderBy;
50                 FileWriter          outputFile;
51                 String              xmlFileName;
52                 String              wmlFileName;
53                 EntityContent       currentContent;
54                 EntityList          entityList;
55                 SimpleHash          wapPageModel;
56                 SimpleList          contentList;
57                 String              currentMediaId;
58                 SimpleHash          imageHash = new SimpleHash();
59
60
61                 // get the breaking news
62                 // only the first 5
63                 ModuleBreaking breakingModule = new ModuleBreaking(DatabaseBreaking.getInstance());
64                 entityList = breakingModule.getByWhereClause(null,"webdb_create desc",0,itemsPerPage);
65                 SimpleList breakingList = HTMLTemplateProcessor.makeSimpleList(entityList);
66
67
68
69                 // Zusaetzlich Informationen
70                 wapPageModel = new SimpleHash();
71                 wapPageModel.put("breaking", breakingList);
72
73                 xmlFileName = producerDocRoot + "/wap/index.xml";
74                 wmlFileName = producerDocRoot + "/wap/index.wml";
75
76                 produce(wapTemplate, xmlFileName, wapPageModel, new LineFilterWriter(htmlout));
77
78                 XmlSaxonStyler styler = XmlSaxonStyler.getInstance();
79                 // clear XSL-Cache
80                 // XslStyleCache.clear();
81
82                 try {
83                         InputStream is = new FileInputStream(producerStorageRoot+xmlFileName);
84                         OutputStream os = new FileOutputStream(producerStorageRoot+wmlFileName);
85                         String contentXsl = Configuration.getProperty("Home") + "templates/" + Configuration.getProperty("Xsl.Wap");
86                         logHTML(htmlout,"using style " + contentXsl);
87                         styler.style(contentXsl,is,os);
88       is.close();
89       os.close();
90                         logHTML(htmlout,"styling done.");
91                         logHTML(htmlout, "html erstellt: <a href=\"" + producerProductionHost+  wmlFileName + "\">" + wmlFileName + "</a>");
92                 } catch (FileNotFoundException e) {
93                         System.err.println(e.toString());
94                 } catch (IOException e) {
95                         System.err.println(e.toString());
96                 } catch (org.xml.sax.SAXException e) {
97                         logHTML(htmlout,e.toString());
98                         System.err.println(e.toString());
99                 }
100
101                 // Finish
102                 sessionConnectTime = new java.util.Date().getTime() - startTime;
103                 logHTML(htmlout, "Producer.Startseite finished: " + sessionConnectTime + " ms.");
104         }
105 }
106