1 package mircoders.producer;
7 import freemarker.template.*;
15 import mircoders.entity.*;
16 import mircoders.storage.*;
21 public class ProducerMedia extends Producer {
23 public static void main(String argv[]){
25 new ProducerContent().handle(new PrintWriter(System.out), null, false,false);
26 } catch(Exception e) { System.err.println(e.toString()); }
29 public void handle(PrintWriter htmlout, EntityUsers user, boolean force, boolean sync)
30 throws StorageObjectException, ModuleException {
31 handle(htmlout,user,force,sync,null);
34 public void handle(PrintWriter htmlout, EntityUsers user, boolean force, boolean sync, String id)
35 throws StorageObjectException, ModuleException
37 long sessionConnectTime = 0;
38 long startTime = (new java.util.Date()).getTime();
39 boolean iconProduced = false;
40 boolean mediaProduced = false;
47 String productionPath;
49 EntityList batchEntityList;
51 int contentBatchsize = Integer.parseInt(MirConfig.getProp("Producer.Content.Batchsize"));
53 // get batch of non-produced medias, that are to be published
54 whereClause="is_published='1'";
56 whereClause += " and id="+id;
57 if (force==false) whereClause += " and is_produced='0'";
59 batchEntityList = uploadedMediaModule.getByWhereClause(whereClause, null, 0, contentBatchsize);
61 while (batchEntityList != null) {
62 for(int i=0;i<batchEntityList.size();i++) {
64 currentMedia = (Entity)batchEntityList.elementAt(i);
66 Entity currentMediaType = DatabaseUploadedMedia.getInstance().getMediaType(currentMedia);
67 String mediaHandlerName = currentMediaType.getValue("classname");
68 Class mediaHandlerClass = Class.forName("mir.media.MediaHandler"+mediaHandlerName);
69 MirMedia currentMediaHandler = (MirMedia)mediaHandlerClass.newInstance();
71 String date = currentMedia.getValue("date");
72 String datePath = StringUtil.webdbDate2path(date);
75 if (currentMedia.getValue("icon_is_produced") != "1") {
76 iconPath = currentMediaHandler.getIconStoragePath();
77 iconFilename = producerDocRoot+iconPath+datePath+
78 currentMedia.getId()+"."+currentMediaType.getValue("name");
79 iconProduced = produceFile(iconFilename, currentMediaHandler.getIcon(currentMedia), htmlout, true);
81 currentMedia.setValueForProperty("icon_path",iconFilename);
82 logHTML(htmlout,"icon : " + iconFilename + (( iconProduced==true )? " succeded":" <font color=\"Red\" failed!</font>"));
89 //now produce the media content
91 mediaHost = currentMediaHandler.getPublishHost();
92 mediaPath = currentMediaHandler.getStoragePath();
93 mediaFilename = currentMedia.getId()+"."+currentMediaType.getValue("name");
94 //hack: make this a config option. -mh
95 //productionPath = mediaPath+datePath+"/"+ mediaFilename ;
96 productionPath = mediaPath+"/"+mediaFilename ;
98 //hack: see above. -mh.
99 //currentMedia.setValueForProperty("publish_path",datePath+"/"+mediaFilename);
100 currentMedia.setValueForProperty("publish_path",mediaFilename);
101 currentMedia.setValueForProperty("publish_server", mediaHost);
103 mediaProduced = produceFile(productionPath, currentMediaHandler.get(currentMedia, currentMediaType), htmlout, false);
104 logHTML(htmlout,"media: " + productionPath + ((mediaProduced==true)?" succeded":" <font color=\"Red\" failed!</font>"));
107 if (iconProduced && mediaProduced) {
108 currentMedia.setValueForProperty("icon_is_produced", "1");
109 currentMedia.setValueForProperty("is_produced", "1");
110 currentMedia.update();
113 } catch (Exception e) {
114 theLog.printError("failed in reflection: "+e);
118 // if next batch get it...
119 if (batchEntityList.hasNextBatch()){
120 batchEntityList = uploadedMediaModule.getByWhereClause(whereClause, null, batchEntityList.getNextBatch(),contentBatchsize);
122 batchEntityList=null;
126 sessionConnectTime = new java.util.Date().getTime() - startTime;
127 logHTML(htmlout, "Producer.Media finished: " + sessionConnectTime + " ms.");