1 package mircoders.producer;
7 import freemarker.template.*;
15 import mircoders.media.*;
16 import mircoders.entity.*;
17 import mircoders.storage.*;
22 public class ProducerMedia extends Producer {
24 public static void main(String argv[]){
26 new ProducerContent().handle(new PrintWriter(System.out), null, false,false);
27 } catch(Exception e) { System.err.println(e.toString()); }
30 public void handle(PrintWriter htmlout, EntityUsers user, boolean force, boolean sync)
31 throws StorageObjectException, ModuleException {
32 handle(htmlout,user,force,sync,null);
35 public void handle(PrintWriter htmlout, EntityUsers user, boolean force, boolean sync, String id)
36 throws StorageObjectException, ModuleException
38 long sessionConnectTime = 0;
39 long startTime = (new java.util.Date()).getTime();
40 boolean iconProduced = false;
41 boolean mediaProduced = false;
49 String productionPath;
51 EntityList batchEntityList;
53 int contentBatchsize = Integer.parseInt(MirConfig.getProp("Producer.Content.Batchsize"));
55 // get batch of non-produced medias, that are to be published
56 whereClause="is_published='1'";
58 whereClause += " and id="+id;
59 if (force==false) whereClause += " and is_produced='0'";
61 batchEntityList = uploadedMediaModule.getByWhereClause(whereClause, null, 0, contentBatchsize);
63 while (batchEntityList != null) {
64 for(int i=0;i<batchEntityList.size();i++) {
66 currentMedia = (Entity)batchEntityList.elementAt(i);
68 Entity currentMediaType = DatabaseUploadedMedia.getInstance().getMediaType(currentMedia);
69 String mediaHandlerName = currentMediaType.getValue("classname");
70 Class mediaHandlerClass = Class.forName("mircoders.media.MediaHandler"+mediaHandlerName);
71 MirMedia currentMediaHandler = (MirMedia)mediaHandlerClass.newInstance();
73 String date = currentMedia.getValue("date");
74 String datePath = StringUtil.webdbDate2path(date);
77 if (!currentMedia.getValue("icon_is_produced").equals("1")) {
78 iconPath = currentMediaHandler.getIconStoragePath();
79 iconFilename = producerDocRoot+iconPath+datePath+
80 currentMedia.getId()+"."+currentMediaType.getValue("name");
81 iconProduced = produceFile(iconFilename, currentMediaHandler.getIcon(currentMedia), htmlout, true);
83 currentMedia.setValueForProperty("icon_path",iconFilename);
84 logHTML(htmlout,"icon : " + iconFilename + (( iconProduced==true )? " succeded":" <font color=\"Red\"> failed!</font>"));
91 //now produce the media content
93 mediaHost = currentMediaHandler.getPublishHost();
94 mediaPath = currentMediaHandler.getStoragePath();
95 id2 = currentMedia.getId();
96 mediaFilename = currentMedia.getId()+"."+currentMediaType.getValue("name");
97 //hack: make this a config option. -mh
98 productionPath = mediaPath+datePath+"/"+ mediaFilename ;
99 //productionPath = mediaPath+"/"+mediaFilename ;
101 //hack: see above. -mh.
102 currentMedia.setValueForProperty("publish_path",datePath+"/"+mediaFilename);
103 //currentMedia.setValueForProperty("publish_path",mediaFilename);
104 currentMedia.setValueForProperty("publish_server", mediaHost);
106 theLog.printError("ABOUT OT FILE"+id2);
107 mediaProduced = produceFile(productionPath, currentMediaHandler.get(currentMedia, currentMediaType), htmlout, false);
108 logHTML(htmlout,"media: " + productionPath + ((mediaProduced==true)?" succeded":" <font color=\"Red\"> failed!</font>"));
111 if (iconProduced && mediaProduced) {
112 currentMedia.setValueForProperty("icon_is_produced", "1");
113 currentMedia.setValueForProperty("is_produced", "1");
114 currentMedia.update();
116 } catch (MirMediaException e) {
117 theLog.printError("media exception: "+id+e.toString());
118 logHTML(htmlout, "problem with media id: "
119 +id+" <font color=\"Red\"> failed!</font>: "
121 } catch (Exception e) {
122 theLog.printError("failed in reflection: "+id+e.toString());
123 logHTML(htmlout, "reflection problem in media id: "
124 +id+" <font color=\"Red\"> failed!</font>: "
129 // if next batch get it...
130 if (batchEntityList.hasNextBatch()){
131 batchEntityList = uploadedMediaModule.getByWhereClause(whereClause, null, batchEntityList.getNextBatch(),contentBatchsize);
133 batchEntityList=null;
137 sessionConnectTime = new java.util.Date().getTime() - startTime;
138 logHTML(htmlout, "Producer.Media finished: " + sessionConnectTime + " ms.");