Initial revision
[mir.git] / source / mircoders / producer / ProducerWap.java
diff --git a/source/mircoders/producer/ProducerWap.java b/source/mircoders/producer/ProducerWap.java
new file mode 100755 (executable)
index 0000000..68ff47f
--- /dev/null
@@ -0,0 +1,106 @@
+package mircoders.producer;
+
+import java.io.*;
+import java.lang.*;
+import java.util.*;
+
+import freemarker.template.*;
+
+import webdb.misc.*;
+import webdb.storage.*;
+import webdb.module.*;
+import webdb.entity.*;
+
+import mir.module.*;
+import mir.storage.*;
+import mir.entity.*;
+
+
+public class ProducerWap extends Producer {
+
+       static String           wapTemplate;
+       static int              itemsPerPage;
+       static int              newsPerPage;
+
+       // Initialierung
+       static {
+               wapTemplate = Configuration.getProperty("Producer.Wap.Template");
+               itemsPerPage = Integer.parseInt(Configuration.getProperty("Producer.Wap.Items"));
+       }
+
+       public static void main(String argv[]){
+               try {
+                       Configuration.initConfig(argv[0]);
+                       new ProducerWap().handle(new PrintWriter(System.out), null);
+               } catch(Exception e) {
+                       System.err.println(e.toString());
+               }
+       }
+
+       public void handle(PrintWriter htmlout, EntityUsers user, boolean force, boolean sync)
+               throws StorageObjectException, ModuleException
+       {
+               printHTML(htmlout, "Producer.StartPage: started");
+
+               long                sessionConnectTime = 0;
+               long                startTime = (new java.util.Date()).getTime();
+               String              nowWebdbDate = StringUtil.date2webdbDate(new GregorianCalendar());
+               String              whereClause;
+               String              orderBy;
+               FileWriter          outputFile;
+               String              xmlFileName;
+               String              wmlFileName;
+               EntityContent       currentContent;
+               EntityList          entityList;
+               SimpleHash          wapPageModel;
+               SimpleList          contentList;
+               String              currentMediaId;
+               SimpleHash          imageHash = new SimpleHash();
+
+
+               // get the breaking news
+               // only the first 5
+               ModuleBreaking breakingModule = new ModuleBreaking(DatabaseBreaking.getInstance());
+               entityList = breakingModule.getByWhereClause(null,"webdb_create desc",0,itemsPerPage);
+               SimpleList breakingList = HTMLTemplateProcessor.makeSimpleList(entityList);
+
+
+
+               // Zusaetzlich Informationen
+               wapPageModel = new SimpleHash();
+               wapPageModel.put("breaking", breakingList);
+
+               xmlFileName = producerDocRoot + "/wap/index.xml";
+               wmlFileName = producerDocRoot + "/wap/index.wml";
+
+               produce(wapTemplate, xmlFileName, wapPageModel, new LineFilterWriter(htmlout));
+
+               XmlSaxonStyler styler = XmlSaxonStyler.getInstance();
+               // clear XSL-Cache
+               // XslStyleCache.clear();
+
+               try {
+                       InputStream is = new FileInputStream(producerStorageRoot+xmlFileName);
+                       OutputStream os = new FileOutputStream(producerStorageRoot+wmlFileName);
+                       String contentXsl = Configuration.getProperty("Home") + "templates/" + Configuration.getProperty("Xsl.Wap");
+                       logHTML(htmlout,"using style " + contentXsl);
+                       styler.style(contentXsl,is,os);
+      is.close();
+      os.close();
+                       logHTML(htmlout,"styling done.");
+                       logHTML(htmlout, "html erstellt: <a href=\"" + producerProductionHost+  wmlFileName + "\">" + wmlFileName + "</a>");
+               } catch (FileNotFoundException e) {
+                       System.err.println(e.toString());
+               } catch (IOException e) {
+                       System.err.println(e.toString());
+               } catch (org.xml.sax.SAXException e) {
+                       logHTML(htmlout,e.toString());
+                       System.err.println(e.toString());
+               }
+
+               // Finish
+               sessionConnectTime = new java.util.Date().getTime() - startTime;
+               logHTML(htmlout, "Producer.Startseite finished: " + sessionConnectTime + " ms.");
+       }
+}
+