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;
48 String productionPath;
50 EntityList batchEntityList;
52 int contentBatchsize = Integer.parseInt(MirConfig.getProp("Producer.Content.Batchsize"));
54 // get batch of non-produced medias, that are to be published
55 whereClause="is_published='1'";
57 whereClause += " and id="+id;
58 if (force==false) whereClause += " and is_produced='0'";
60 batchEntityList = uploadedMediaModule.getByWhereClause(whereClause, null, 0, contentBatchsize);
62 while (batchEntityList != null) {
63 for(int i=0;i<batchEntityList.size();i++) {
65 currentMedia = (Entity)batchEntityList.elementAt(i);
67 Entity currentMediaType = DatabaseUploadedMedia.getInstance().getMediaType(currentMedia);
68 String mediaHandlerName = currentMediaType.getValue("classname");
69 Class mediaHandlerClass = Class.forName("mir.media.MediaHandler"+mediaHandlerName);
70 MirMedia currentMediaHandler = (MirMedia)mediaHandlerClass.newInstance();
72 String date = currentMedia.getValue("date");
73 String datePath = StringUtil.webdbDate2path(date);
76 if (!currentMedia.getValue("icon_is_produced").equals("1")) {
77 iconPath = currentMediaHandler.getIconStoragePath();
78 iconFilename = producerDocRoot+iconPath+datePath+
79 currentMedia.getId()+"."+currentMediaType.getValue("name");
80 iconProduced = produceFile(iconFilename, currentMediaHandler.getIcon(currentMedia), htmlout, true);
82 currentMedia.setValueForProperty("icon_path",iconFilename);
83 logHTML(htmlout,"icon : " + iconFilename + (( iconProduced==true )? " succeded":" <font color=\"Red\"> failed!</font>"));
90 //now produce the media content
92 mediaHost = currentMediaHandler.getPublishHost();
93 mediaPath = currentMediaHandler.getStoragePath();
94 id2 = currentMedia.getId();
95 mediaFilename = currentMedia.getId()+"."+currentMediaType.getValue("name");
96 //hack: make this a config option. -mh
97 productionPath = mediaPath+datePath+"/"+ mediaFilename ;
98 //productionPath = mediaPath+"/"+mediaFilename ;
100 //hack: see above. -mh.
101 currentMedia.setValueForProperty("publish_path",datePath+"/"+mediaFilename);
102 //currentMedia.setValueForProperty("publish_path",mediaFilename);
103 currentMedia.setValueForProperty("publish_server", mediaHost);
105 theLog.printError("ABOUT OT FILE"+id2);
106 mediaProduced = produceFile(productionPath, currentMediaHandler.get(currentMedia, currentMediaType), htmlout, false);
107 logHTML(htmlout,"media: " + productionPath + ((mediaProduced==true)?" succeded":" <font color=\"Red\"> failed!</font>"));
110 if (iconProduced && mediaProduced) {
111 currentMedia.setValueForProperty("icon_is_produced", "1");
112 currentMedia.setValueForProperty("is_produced", "1");
113 currentMedia.update();
115 } catch (MirMediaException e) {
116 theLog.printError("media exception: "+id+e.toString());
117 logHTML(htmlout, "problem with media id: "
118 +id+" <font color=\"Red\"> failed!</font>: "
120 } catch (Exception e) {
121 theLog.printError("failed in reflection: "+id+e.toString());
122 logHTML(htmlout, "reflection problem in media id: "
123 +id+" <font color=\"Red\"> failed!</font>: "
128 // if next batch get it...
129 if (batchEntityList.hasNextBatch()){
130 batchEntityList = uploadedMediaModule.getByWhereClause(whereClause, null, batchEntityList.getNextBatch(),contentBatchsize);
132 batchEntityList=null;
136 sessionConnectTime = new java.util.Date().getTime() - startTime;
137 logHTML(htmlout, "Producer.Media finished: " + sessionConnectTime + " ms.");