mass update mir codeswitch
[mir.git] / source / mircoders / producer / ProducerContent.java
index c2a927c..d773910 100755 (executable)
-package mircoders.producer;\r
-\r
-import java.io.*;\r
-import java.lang.*;\r
-import java.util.*;\r
-\r
-import freemarker.template.*;\r
-\r
-import com.icl.saxon.trax.Transformer;\r
-\r
-import webdb.misc.*;\r
-import webdb.storage.*;\r
-import webdb.module.*;\r
-import webdb.entity.*;\r
-\r
-import mir.module.*;\r
-import mir.entity.*;\r
-import mir.storage.*;\r
-\r
-\r
-public class ProducerContent extends Producer {\r
-\r
-       public static void main(String argv[]){\r
-               Configuration.initConfig("config");\r
-               System.out.println(Configuration.getProperty("Producer.DocRoot"));\r
-               try {\r
-                       new ProducerContent().handle(new PrintWriter(System.out), null, false,false);\r
-               } catch(Exception e) { System.err.println(e.toString()); }\r
-       }\r
-\r
-       public void handle(PrintWriter htmlout, EntityUsers user, boolean force, boolean sync)\r
-               throws StorageObjectException, ModuleException {\r
-               handle(htmlout,user,force,sync,null);\r
-       }\r
-\r
-\r
-       public void handle(PrintWriter htmlout, EntityUsers user, boolean force, boolean sync, String id)\r
-               throws StorageObjectException, ModuleException\r
-       {\r
-\r
-               String contentTemplate = Configuration.getProperty("Producer.Content.Template");\r
-               int contentBatchsize = Integer.parseInt(Configuration.getProperty("Producer.Content.Batchsize"));\r
-               String extLinkName = Configuration.getProperty("Producer.ExtLinkName");\r
-               String intLinkName = Configuration.getProperty("Producer.IntLinkName");\r
-               String mailLinkName = Configuration.getProperty("Producer.MailLinkName");\r
-               String imageRoot = Configuration.getProperty("Producer.ImageRoot");\r
-\r
-               long                sessionConnectTime = 0;\r
-               long                startTime = (new java.util.Date()).getTime();\r
-               String              whereClause = " ";\r
-               String              orderBy = " ";\r
-               String              htmlFileName = null;\r
-               String              currentMediaId;\r
-               EntityContent       currentContent;\r
-               EntityList          batchEntityList;\r
-               HashMap             currentContentValues;\r
-               SimpleHash          imageHash = new SimpleHash();\r
-               EntityGruppen       userEntity=null;\r
-\r
-               // production of the content-pages\r
-               orderBy="date desc, webdb_lastchange desc";\r
-               if(force==true){\r
-                       whereClause="is_published='1'";\r
-\r
-                       // if true: produces a single content item\r
-                       if(id !=null){\r
-                               whereClause += " AND id="+id;\r
-                       }\r
-                       batchEntityList = contentModule.getContent(whereClause, orderBy, 0, contentBatchsize, userEntity);\r
-               } else {\r
-                       whereClause="is_produced='0' AND is_published='1'";\r
-\r
-                       //if true produces a single contentitem\r
-                       if(id !=null){\r
-                               whereClause += " AND id="+id;\r
-                       }\r
-                       batchEntityList = contentModule.getContent(whereClause, orderBy, 0, contentBatchsize, userEntity);\r
-               }\r
-\r
-               while (batchEntityList != null) {\r
-                       for(int i=0;i<batchEntityList.size();i++) {\r
-                               currentContent = (EntityContent)batchEntityList.elementAt(i);\r
-                               currentContentValues = currentContent.getValues();\r
-                               //currentContentValues.put("content_data",currentContent.getContentData());\r
-\r
-\r
-                               String date = (String)currentContentValues.get("date");\r
-                               String year = date.substring(0,4);\r
-                               String month = date.substring(4,6);\r
-\r
-                               htmlFileName =  producerDocRoot\r
-                                       + "/" + year + "/" + month + "/" +  currentContentValues.get("id") + ".shtml";\r
-\r
-                               currentContentValues.put("content_data",StringUtil.deleteForbiddenTags((String)currentContentValues.get("content_data")));\r
-                               currentContentValues.put("description",StringUtil.deleteForbiddenTags((String)currentContentValues.get("description")));\r
-\r
-        if (currentContentValues.get("is_html").equals("0")) {\r
-          String temp = (String)currentContentValues.get("content_data");\r
-          theLog.printDebugInfo("länge:"+temp.length());\r
-          if(temp!=null && temp.length()>0){\r
-            temp = StringUtil.createHTML(temp,imageRoot,mailLinkName,extLinkName,intLinkName);\r
-            temp = StringUtil.decodeHTMLinTags(temp);\r
-            currentContentValues.put("content_data",temp);\r
-          }\r
-          temp = (String)currentContentValues.get("description");\r
-          if(temp!=null && temp.length()>0){\r
-            temp = StringUtil.createHTML(temp,imageRoot,mailLinkName,extLinkName,intLinkName);\r
-            temp = StringUtil.decodeHTMLinTags(temp);\r
-            currentContentValues.put("description",temp);\r
-          }\r
-                               } else {\r
-          String temp = (String)currentContentValues.get("content_data");\r
-          if(temp!=null && temp.length()>0){\r
-            temp = StringUtil.decodeHTMLinTags(temp);\r
-            currentContentValues.put("content_data",temp);\r
-          }\r
-          temp = (String)currentContentValues.get("description");\r
-          if(temp!=null && temp.length()>0){\r
-            temp = StringUtil.decodeHTMLinTags(temp);\r
-            currentContentValues.put("description",temp);\r
-          }\r
-        }\r
-\r
-                               SimpleHash mergeData = HTMLTemplateProcessor.makeSimpleHash(currentContentValues);\r
-\r
-                               // get the images\r
-                               currentMediaId = currentContent.getValue("to_media");\r
-                               if (currentMediaId!=null && !currentMediaId.equals("")) {\r
-                                       imageHash.put(currentMediaId, HTMLTemplateProcessor.makeSimpleHash(imageModule.getById(currentMediaId)));\r
-                               }\r
-                               mergeData.put("images", imageHash);\r
-\r
-                               // get the comments for the article\r
-                               mergeData.put("comments", currentContent.getComments());\r
-\r
-                               // get the topics of this article\r
-                               mergeData.put("topics",HTMLTemplateProcessor.makeSimpleList(DatabaseContentToTopics.getInstance().getTopics(currentContent)));\r
-\r
-                               boolean retVal = produce(contentTemplate, htmlFileName, mergeData, htmlout);\r
-                               sessionConnectTime = new java.util.Date().getTime() - startTime;\r
-                               if (retVal == true && !"1".equals(currentContent.getValue("is_produced")))\r
-                                               currentContent.setProduced(true);\r
-                       }\r
-                       if (batchEntityList.hasNextBatch()){\r
-                               batchEntityList = contentModule.getContent(whereClause, orderBy, batchEntityList.getNextBatch(),contentBatchsize, userEntity);\r
-                               //theLog.printDebugInfo("producing next batch");\r
-                       } else {\r
-                               batchEntityList=null;\r
-                       }\r
-               }\r
-               // Finish\r
-               sessionConnectTime = new java.util.Date().getTime() - startTime;\r
-               logHTML(htmlout, "Producer.Content finished: " + sessionConnectTime + " ms.");\r
-\r
-       }\r
-\r
+package mircoders.producer;
+
+import java.io.*;
+import java.lang.*;
+import java.util.*;
+
+
+import freemarker.template.*;
+
+import com.icl.saxon.trax.Transformer;
+
+import mir.misc.*;
+import mir.storage.*;
+import mir.module.*;
+import mir.entity.*;
+
+import mircoders.entity.*;
+import mircoders.storage.*;
+
+
+public class ProducerContent extends Producer {
+
+
+
+       public static void main(String argv[]){
+
+               Configuration.initConfig("config");
+
+               System.out.println(Configuration.getProperty("Producer.DocRoot"));
+
+               try {
+
+                       new ProducerContent().handle(new PrintWriter(System.out), null, false,false);
+
+               } catch(Exception e) { System.err.println(e.toString()); }
+
+       }
+
+
+
+       public void handle(PrintWriter htmlout, EntityUsers user, boolean force, boolean sync)
+
+               throws StorageObjectException, ModuleException {
+
+               handle(htmlout,user,force,sync,null);
+
+       }
+
+
+
+
+
+       public void handle(PrintWriter htmlout, EntityUsers user, boolean force, boolean sync, String id)
+
+               throws StorageObjectException, ModuleException
+
+       {
+
+
+
+               String contentTemplate = Configuration.getProperty("Producer.Content.Template");
+
+               int contentBatchsize = Integer.parseInt(Configuration.getProperty("Producer.Content.Batchsize"));
+
+               String extLinkName = Configuration.getProperty("Producer.ExtLinkName");
+
+               String intLinkName = Configuration.getProperty("Producer.IntLinkName");
+
+               String mailLinkName = Configuration.getProperty("Producer.MailLinkName");
+
+               String imageRoot = Configuration.getProperty("Producer.ImageRoot");
+
+               long                sessionConnectTime = 0;
+               long                startTime = (new java.util.Date()).getTime();
+               String              whereClause = " ";
+               String              orderBy = " ";
+               String              htmlFileName = null;
+               String              currentMediaId;
+               EntityContent       currentContent;
+               EntityList          batchEntityList;
+
+               HashMap             currentContentValues;
+
+               SimpleHash          imageHash = new SimpleHash();
+
+               EntityGruppen       userEntity=null;
+
+
+
+               // production of the content-pages
+
+               orderBy="date desc, webdb_lastchange desc";
+
+               if(force==true){
+
+                       whereClause="is_published='1'";
+
+
+
+                       // if true: produces a single content item
+
+                       if(id !=null){
+
+                               whereClause += " AND id="+id;
+
+                       }
+
+                       batchEntityList = contentModule.getContent(whereClause, orderBy, 0, contentBatchsize, userEntity);
+
+               } else {
+
+                       whereClause="is_produced='0' AND is_published='1'";
+
+
+
+                       //if true produces a single contentitem
+
+                       if(id !=null){
+
+                               whereClause += " AND id="+id;
+
+                       }
+
+                       batchEntityList = contentModule.getContent(whereClause, orderBy, 0, contentBatchsize, userEntity);
+
+               }
+
+
+
+               while (batchEntityList != null) {
+
+                       for(int i=0;i<batchEntityList.size();i++) {
+
+                               currentContent = (EntityContent)batchEntityList.elementAt(i);
+
+                               currentContentValues = currentContent.getValues();
+
+                               //currentContentValues.put("content_data",currentContent.getContentData());
+
+
+
+
+
+                               String date = (String)currentContentValues.get("date");
+
+                               String year = date.substring(0,4);
+
+                               String month = date.substring(4,6);
+
+
+
+                               htmlFileName =  producerDocRoot
+
+                                       + "/" + year + "/" + month + "/" +  currentContentValues.get("id") + ".shtml";
+
+
+
+                               currentContentValues.put("content_data",StringUtil.deleteForbiddenTags((String)currentContentValues.get("content_data")));
+
+                               currentContentValues.put("description",StringUtil.deleteForbiddenTags((String)currentContentValues.get("description")));
+
+
+
+        if (currentContentValues.get("is_html").equals("0")) {
+
+          String temp = (String)currentContentValues.get("content_data");
+
+          theLog.printDebugInfo("länge:"+temp.length());
+
+          if(temp!=null && temp.length()>0){
+
+            temp = StringUtil.createHTML(temp,imageRoot,mailLinkName,extLinkName,intLinkName);
+
+            temp = StringUtil.decodeHTMLinTags(temp);
+
+            currentContentValues.put("content_data",temp);
+
+          }
+
+          temp = (String)currentContentValues.get("description");
+
+          if(temp!=null && temp.length()>0){
+
+            temp = StringUtil.createHTML(temp,imageRoot,mailLinkName,extLinkName,intLinkName);
+
+            temp = StringUtil.decodeHTMLinTags(temp);
+
+            currentContentValues.put("description",temp);
+
+          }
+
+                               } else {
+
+          String temp = (String)currentContentValues.get("content_data");
+
+          if(temp!=null && temp.length()>0){
+
+            temp = StringUtil.decodeHTMLinTags(temp);
+
+            currentContentValues.put("content_data",temp);
+
+          }
+
+          temp = (String)currentContentValues.get("description");
+
+          if(temp!=null && temp.length()>0){
+
+            temp = StringUtil.decodeHTMLinTags(temp);
+
+            currentContentValues.put("description",temp);
+
+          }
+
+        }
+
+
+
+                               SimpleHash mergeData = HTMLTemplateProcessor.makeSimpleHash(currentContentValues);
+
+
+
+                               // get the images
+
+                               currentMediaId = currentContent.getValue("to_media");
+
+                               if (currentMediaId!=null && !currentMediaId.equals("")) {
+
+                                       imageHash.put(currentMediaId, HTMLTemplateProcessor.makeSimpleHash(imageModule.getById(currentMediaId)));
+
+                               }
+
+                               mergeData.put("images", imageHash);
+
+
+
+                               // get the comments for the article
+
+                               mergeData.put("comments", currentContent.getComments());
+
+
+
+                               // get the topics of this article
+                               mergeData.put("topics",HTMLTemplateProcessor.makeSimpleList(DatabaseContentToTopics.getInstance().getTopics(currentContent)));
+
+                               boolean retVal = produce(contentTemplate, htmlFileName, mergeData, htmlout);
+                               sessionConnectTime = new java.util.Date().getTime() - startTime;
+                               if (retVal == true && !"1".equals(currentContent.getValue("is_produced")))
+                                               currentContent.setProduced(true);
+                       }
+
+                       if (batchEntityList.hasNextBatch()){
+
+                               batchEntityList = contentModule.getContent(whereClause, orderBy, batchEntityList.getNextBatch(),contentBatchsize, userEntity);
+
+                               //theLog.printDebugInfo("producing next batch");
+
+                       } else {
+
+                               batchEntityList=null;
+
+                       }
+
+               }
+
+               // Finish
+
+               sessionConnectTime = new java.util.Date().getTime() - startTime;
+
+               logHTML(htmlout, "Producer.Content finished: " + sessionConnectTime + " ms.");
+
+
+
+       }
+
+
+
 }
\ No newline at end of file