1 package mircoders.producer;
5 import java.lang.reflect.*;
8 import freemarker.template.*;
16 import mircoders.entity.*;
17 import mircoders.storage.*;
20 public class ProducerContent extends Producer {
22 public static void main(String argv[]){
24 * Why are we reloading the config here?
25 * Can someone please explain this?
26 * Hope I didn't break anything
27 * -mh. <heckmann@hbe.ca>
29 //Configuration.initConfig("config");
30 System.out.println(MirConfig.getProp("Producer.DocRoot"));
33 new ProducerContent().handle(new PrintWriter(System.out), null, false,false);
34 } catch(Exception e) {
35 System.err.println(e.toString());
41 public void handle(PrintWriter htmlout, EntityUsers user, boolean force, boolean sync)
42 throws StorageObjectException, ModuleException {
44 handle(htmlout,user,force,sync,null);
51 public void handle(PrintWriter htmlout, EntityUsers user, boolean force, boolean sync, String id)
52 throws StorageObjectException, ModuleException {
54 String contentTemplate = MirConfig.getProp("Producer.Content.Template");
55 int contentBatchsize = Integer.parseInt(MirConfig.getProp("Producer.Content.Batchsize"));
56 String extLinkName = MirConfig.getProp("Producer.ExtLinkName");
57 String intLinkName = MirConfig.getProp("Producer.IntLinkName");
58 String mailLinkName = MirConfig.getProp("Producer.MailLinkName");
59 String imageRoot = MirConfig.getProp("Producer.ImageRoot");
61 long sessionConnectTime = 0;
62 long startTime = (new java.util.Date()).getTime();
63 String whereClause = " ";
65 String htmlFileName = null;
66 String currentMediaId;
67 EntityContent currentContent;
68 EntityList batchEntityList;
69 HashMap currentContentValues;
70 SimpleHash imageHash = new SimpleHash();
71 EntityUsers userEntity=null;
74 SimpleHash upMediaSimpleHash;
75 Class mediaHandlerClass;
76 Class mediaStorageClass;
77 String mediaStorageName;
78 String mediaHandlerName=null;
79 MirMedia mediaHandler=null;
80 Database mediaStorage=null;
84 // production of the content-pages
85 orderBy="date desc, webdb_lastchange desc";
87 whereClause="is_published='1'";
88 // if true: produces a single content item
90 whereClause += " AND id="+id;
92 batchEntityList = contentModule.getContent(whereClause, orderBy, 0, contentBatchsize, userEntity);
94 whereClause="is_produced='0' AND is_published='1'";
95 //if true produces a single contentitem
97 whereClause += " AND id="+id;
99 batchEntityList = contentModule.getContent(whereClause, orderBy, 0, contentBatchsize, userEntity);
102 while (batchEntityList != null) {
103 for(int i=0;i<batchEntityList.size();i++) {
104 currentContent = (EntityContent)batchEntityList.elementAt(i);
105 currentContentValues = currentContent.getValues();
107 //because of postgres 7.1.* not needed anymore
108 //currentContentValues.put("content_data",currentContent.getContentData());
109 String date = (String)currentContentValues.get("date");
110 String year = date.substring(0,4);
111 String month = date.substring(4,6);
113 htmlFileName = producerDocRoot
114 + "/" + year + "/" + month + "/" + currentContentValues.get("id") + ".shtml";
116 currentContentValues.put("content_data",StringUtil.deleteForbiddenTags((String)currentContentValues.get("content_data")));
117 currentContentValues.put("description",StringUtil.deleteForbiddenTags((String)currentContentValues.get("description")));
120 //create http-links and email-links
121 if (currentContentValues.get("is_html").equals("0")) {
122 String temp = (String)currentContentValues.get("content_data");
123 if(temp!=null && temp.length()>0){
124 temp = StringUtil.createHTML(temp,imageRoot,mailLinkName,extLinkName,intLinkName);
125 temp = StringUtil.decodeHTMLinTags(temp);
126 currentContentValues.put("content_data",temp);
128 temp = (String)currentContentValues.get("description");
129 if(temp!=null && temp.length()>0){
130 temp = StringUtil.createHTML(temp,imageRoot,mailLinkName,extLinkName,intLinkName);
131 temp = StringUtil.decodeHTMLinTags(temp);
132 currentContentValues.put("description",temp);
135 String temp = (String)currentContentValues.get("content_data");
136 if(temp!=null && temp.length()>0){
137 temp = StringUtil.decodeHTMLinTags(temp);
138 currentContentValues.put("content_data",temp);
140 temp = (String)currentContentValues.get("description");
141 if(temp!=null && temp.length()>0){
142 temp = StringUtil.decodeHTMLinTags(temp);
143 currentContentValues.put("description",temp);
147 //create the freemarker-model
148 SimpleHash mergeData = HTMLTemplateProcessor.makeSimpleHash(currentContentValues);
150 // get the uploaded media
151 EntityList currentMediaList = DatabaseContentToMedia.getInstance().getUploadedMedia(currentContent);
152 if (currentMediaList!=null && currentMediaList.getCount()>=1) {
153 SimpleList mediaList = new SimpleList();
154 for (int n=0; n < currentMediaList.size();n++) {
155 upMedia = currentMediaList.elementAt(n);
156 upMediaSimpleHash = HTMLTemplateProcessor.makeSimpleHash(upMedia);
157 mediaType = ((EntityUploadedMedia)upMedia).getMediaType();
158 //must be a non-existant to_media_type entry..
159 if (mediaType != null) {
161 mediaHandlerName = mediaType.getValue("classname");
162 mediaStorageName = mediaType.getValue("tablename");
163 mediaStorageClass = Class.forName("mircoders.storage.Database"+mediaStorageName);
164 mediaHandlerClass = Class.forName("mir.media.MediaHandler"+mediaHandlerName);
165 mediaHandler = (MirMedia)mediaHandlerClass.newInstance();
166 if(!mediaStorageName.equals(new String("UploadedMedia"))) {
167 Method m = mediaStorageClass.getMethod("getInstance", null);
168 mediaStorage = (Database)m.invoke(null, null);
169 //we most likely need further info
170 upMedia = mediaStorage.selectById(upMedia.getId());
172 } catch (Exception e) {
173 theLog.printError("ProducerStartpage:problem in reflection: "+mediaHandlerName);
175 upMediaSimpleHash.put("url", mediaHandler.getURL(upMedia, mediaType));
176 mediaList.add(upMediaSimpleHash);
177 } //end if media_type != null
179 mergeData.put("to_media", mediaList);
180 } //end if currentMediaList != null
182 // get the comments for the article
184 SimpleList commentList = currentContent.getComments();
186 if(commentList.isEmpty()==false){
187 while(commentList.hasNext()){
188 SimpleHash comment = (SimpleHash)commentList.next();
189 SimpleScalar commentText = (SimpleScalar)comment.get("description");
190 comment.put("description",new SimpleScalar(StringUtil.createHTML(commentText.getAsString(),imageRoot,mailLinkName,extLinkName,intLinkName)));
193 } catch(Exception e){}
194 mergeData.put("comments", commentList);
196 // get the topics of this article
197 mergeData.put("topics",HTMLTemplateProcessor.makeSimpleList(DatabaseContentToTopics.getInstance().getTopics(currentContent)));
200 boolean retVal = produce(contentTemplate, htmlFileName, mergeData, htmlout);
201 sessionConnectTime = new java.util.Date().getTime() - startTime;
202 if (retVal == true && !"1".equals(currentContent.getValue("is_produced")))
203 currentContent.setProduced(true);
206 if (batchEntityList.hasNextBatch()){
207 batchEntityList = contentModule.getContent(whereClause, orderBy, batchEntityList.getNextBatch(),contentBatchsize, userEntity);
209 batchEntityList=null;
213 // timing an message to browser
214 sessionConnectTime = new java.util.Date().getTime() - startTime;
215 logHTML(htmlout, "Producer.Content finished: " + sessionConnectTime + " ms.");