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 SimpleHash imageHash = new SimpleHash();
70 EntityUsers userEntity=null;
73 SimpleHash upMediaSimpleHash;
74 Class mediaHandlerClass;
75 Class mediaStorageClass;
76 String mediaStorageName;
77 String mediaHandlerName=null;
78 MirMedia mediaHandler=null;
79 Database mediaStorage=null;
83 // production of the content-pages
84 orderBy="date desc, webdb_lastchange desc";
86 whereClause="is_published='1'";
87 // if true: produces a single content item
89 whereClause += " AND id="+id;
91 batchEntityList = contentModule.getContent(whereClause, orderBy, 0, contentBatchsize, userEntity);
93 whereClause="is_produced='0' AND is_published='1'";
94 //if true produces a single contentitem
96 whereClause += " AND id="+id;
98 batchEntityList = contentModule.getContent(whereClause, orderBy, 0, contentBatchsize, userEntity);
101 while (batchEntityList != null) {
102 for(int i=0;i<batchEntityList.size();i++) {
103 currentContent = (EntityContent)batchEntityList.elementAt(i);
105 String date = currentContent.getValue("date");
106 String year = date.substring(0,4);
107 String month = date.substring(4,6);
109 htmlFileName = producerDocRoot
110 + "/" + year + "/" + month + "/" + currentContent.getValue("id") + ".shtml";
112 /** @todo all the following should take place in EntityContent */
113 // get the uploaded media
114 EntityList currentMediaList = DatabaseContentToMedia.getInstance().getUploadedMedia(currentContent);
115 if (currentMediaList!=null && currentMediaList.getCount()>=1) {
116 SimpleList mediaList = new SimpleList();
117 for (int n=0; n < currentMediaList.size();n++) {
118 upMedia = currentMediaList.elementAt(n);
119 upMediaSimpleHash = HTMLTemplateProcessor.makeSimpleHash(upMedia);
120 mediaType = ((EntityMedia)upMedia).getMediaType();
121 //must be a non-existant to_media_type entry..
122 if (mediaType != null) {
123 mediaHandlerName = mediaType.getValue("classname");
124 mediaStorageName = mediaType.getValue("tablename");
125 mediaStorageClass = Class.forName("mircoders.storage.Database"+mediaStorageName);
126 mediaHandlerClass = Class.forName("mir.media.MediaHandler"+mediaHandlerName);
127 mediaHandler = (MirMedia)mediaHandlerClass.newInstance();
128 Method m = mediaStorageClass.getMethod("getInstance", null);
129 mediaStorage = (Database)m.invoke(null, null);
130 //we most likely need further info
131 upMedia = mediaStorage.selectById(upMedia.getId());
132 upMediaSimpleHash.put("url", mediaHandler.getURL(upMedia, mediaType));
133 upMediaSimpleHash.put("type",mediaType.getValue("classname"));
134 mediaList.add(upMediaSimpleHash);
135 } //end if media_type != null
137 mergeData.put("to_media", mediaList);
138 } //end if currentMediaList != null
140 // get the comments for the article
141 SimpleList commentList = currentContent.getComments();
142 mergeData.put("comments", commentList);
144 // get the topics of this article
145 mergeData.put("topics",HTMLTemplateProcessor.makeSimpleList(DatabaseContentToTopics.getInstance().getTopics(currentContent)));
148 boolean retVal = produce(contentTemplate, htmlFileName, mergeData, htmlout);
149 sessionConnectTime = new java.util.Date().getTime() - startTime;
150 if (retVal == true && !"1".equals(currentContent.getValue("is_produced")))
151 currentContent.setProduced(true);
152 } catch(Exception e) {
153 logHTML(htmlout, "Producer.Content ERROR while producing content ID: " + currentContent.getId()+",skipping it :: "+e.toString());
154 theLog.printError("Producer.Content ERROR while producing content ID: " + currentContent.getId() +",skipping it :: "+e.toString());
160 if (batchEntityList.hasNextBatch()){
161 batchEntityList = contentModule.getContent(whereClause, orderBy, batchEntityList.getNextBatch(),contentBatchsize, userEntity);
163 batchEntityList=null;
167 // timing and message to browser
168 sessionConnectTime = new java.util.Date().getTime() - startTime;
169 logHTML(htmlout, "Producer.Content finished: " + sessionConnectTime + " ms.");