mass update mir codeswitch
[mir.git] / source / mircoders / producer / ProducerContent.java
1 package mircoders.producer;
2
3 import java.io.*;
4 import java.lang.*;
5 import java.util.*;
6
7
8 import freemarker.template.*;
9
10 import com.icl.saxon.trax.Transformer;
11
12 import mir.misc.*;
13 import mir.storage.*;
14 import mir.module.*;
15 import mir.entity.*;
16
17 import mircoders.entity.*;
18 import mircoders.storage.*;
19
20
21 public class ProducerContent extends Producer {
22
23
24
25         public static void main(String argv[]){
26
27                 Configuration.initConfig("config");
28
29                 System.out.println(Configuration.getProperty("Producer.DocRoot"));
30
31                 try {
32
33                         new ProducerContent().handle(new PrintWriter(System.out), null, false,false);
34
35                 } catch(Exception e) { System.err.println(e.toString()); }
36
37         }
38
39
40
41         public void handle(PrintWriter htmlout, EntityUsers user, boolean force, boolean sync)
42
43                 throws StorageObjectException, ModuleException {
44
45                 handle(htmlout,user,force,sync,null);
46
47         }
48
49
50
51
52
53         public void handle(PrintWriter htmlout, EntityUsers user, boolean force, boolean sync, String id)
54
55                 throws StorageObjectException, ModuleException
56
57         {
58
59
60
61                 String contentTemplate = Configuration.getProperty("Producer.Content.Template");
62
63                 int contentBatchsize = Integer.parseInt(Configuration.getProperty("Producer.Content.Batchsize"));
64
65                 String extLinkName = Configuration.getProperty("Producer.ExtLinkName");
66
67                 String intLinkName = Configuration.getProperty("Producer.IntLinkName");
68
69                 String mailLinkName = Configuration.getProperty("Producer.MailLinkName");
70
71                 String imageRoot = Configuration.getProperty("Producer.ImageRoot");
72
73                 long                sessionConnectTime = 0;
74                 long                startTime = (new java.util.Date()).getTime();
75                 String              whereClause = " ";
76                 String              orderBy = " ";
77                 String              htmlFileName = null;
78                 String              currentMediaId;
79                 EntityContent       currentContent;
80                 EntityList          batchEntityList;
81
82                 HashMap             currentContentValues;
83
84                 SimpleHash          imageHash = new SimpleHash();
85
86                 EntityGruppen       userEntity=null;
87
88
89
90                 // production of the content-pages
91
92                 orderBy="date desc, webdb_lastchange desc";
93
94                 if(force==true){
95
96                         whereClause="is_published='1'";
97
98
99
100                         // if true: produces a single content item
101
102                         if(id !=null){
103
104                                 whereClause += " AND id="+id;
105
106                         }
107
108                         batchEntityList = contentModule.getContent(whereClause, orderBy, 0, contentBatchsize, userEntity);
109
110                 } else {
111
112                         whereClause="is_produced='0' AND is_published='1'";
113
114
115
116                         //if true produces a single contentitem
117
118                         if(id !=null){
119
120                                 whereClause += " AND id="+id;
121
122                         }
123
124                         batchEntityList = contentModule.getContent(whereClause, orderBy, 0, contentBatchsize, userEntity);
125
126                 }
127
128
129
130                 while (batchEntityList != null) {
131
132                         for(int i=0;i<batchEntityList.size();i++) {
133
134                                 currentContent = (EntityContent)batchEntityList.elementAt(i);
135
136                                 currentContentValues = currentContent.getValues();
137
138                                 //currentContentValues.put("content_data",currentContent.getContentData());
139
140
141
142
143
144                                 String date = (String)currentContentValues.get("date");
145
146                                 String year = date.substring(0,4);
147
148                                 String month = date.substring(4,6);
149
150
151
152                                 htmlFileName =  producerDocRoot
153
154                                         + "/" + year + "/" + month + "/" +  currentContentValues.get("id") + ".shtml";
155
156
157
158                                 currentContentValues.put("content_data",StringUtil.deleteForbiddenTags((String)currentContentValues.get("content_data")));
159
160                                 currentContentValues.put("description",StringUtil.deleteForbiddenTags((String)currentContentValues.get("description")));
161
162
163
164         if (currentContentValues.get("is_html").equals("0")) {
165
166           String temp = (String)currentContentValues.get("content_data");
167
168           theLog.printDebugInfo("länge:"+temp.length());
169
170           if(temp!=null && temp.length()>0){
171
172             temp = StringUtil.createHTML(temp,imageRoot,mailLinkName,extLinkName,intLinkName);
173
174             temp = StringUtil.decodeHTMLinTags(temp);
175
176             currentContentValues.put("content_data",temp);
177
178           }
179
180           temp = (String)currentContentValues.get("description");
181
182           if(temp!=null && temp.length()>0){
183
184             temp = StringUtil.createHTML(temp,imageRoot,mailLinkName,extLinkName,intLinkName);
185
186             temp = StringUtil.decodeHTMLinTags(temp);
187
188             currentContentValues.put("description",temp);
189
190           }
191
192                                 } else {
193
194           String temp = (String)currentContentValues.get("content_data");
195
196           if(temp!=null && temp.length()>0){
197
198             temp = StringUtil.decodeHTMLinTags(temp);
199
200             currentContentValues.put("content_data",temp);
201
202           }
203
204           temp = (String)currentContentValues.get("description");
205
206           if(temp!=null && temp.length()>0){
207
208             temp = StringUtil.decodeHTMLinTags(temp);
209
210             currentContentValues.put("description",temp);
211
212           }
213
214         }
215
216
217
218                                 SimpleHash mergeData = HTMLTemplateProcessor.makeSimpleHash(currentContentValues);
219
220
221
222                                 // get the images
223
224                                 currentMediaId = currentContent.getValue("to_media");
225
226                                 if (currentMediaId!=null && !currentMediaId.equals("")) {
227
228                                         imageHash.put(currentMediaId, HTMLTemplateProcessor.makeSimpleHash(imageModule.getById(currentMediaId)));
229
230                                 }
231
232                                 mergeData.put("images", imageHash);
233
234
235
236                                 // get the comments for the article
237
238                                 mergeData.put("comments", currentContent.getComments());
239
240
241
242                                 // get the topics of this article
243                                 mergeData.put("topics",HTMLTemplateProcessor.makeSimpleList(DatabaseContentToTopics.getInstance().getTopics(currentContent)));
244
245                                 boolean retVal = produce(contentTemplate, htmlFileName, mergeData, htmlout);
246                                 sessionConnectTime = new java.util.Date().getTime() - startTime;
247                                 if (retVal == true && !"1".equals(currentContent.getValue("is_produced")))
248                                                 currentContent.setProduced(true);
249                         }
250
251                         if (batchEntityList.hasNextBatch()){
252
253                                 batchEntityList = contentModule.getContent(whereClause, orderBy, batchEntityList.getNextBatch(),contentBatchsize, userEntity);
254
255                                 //theLog.printDebugInfo("producing next batch");
256
257                         } else {
258
259                                 batchEntityList=null;
260
261                         }
262
263                 }
264
265                 // Finish
266
267                 sessionConnectTime = new java.util.Date().getTime() - startTime;
268
269                 logHTML(htmlout, "Producer.Content finished: " + sessionConnectTime + " ms.");
270
271
272
273         }
274
275
276
277 }