1 package mircoders.producer;
7 //import freemarker.template.*;
15 import mircoders.media.*;
16 import mircoders.entity.*;
17 import mircoders.storage.*;
19 abstract public class ProducerMedia extends Producer {
21 abstract Database getStorage() throws StorageObjectException;
23 public void handle(PrintWriter htmlout, EntityUsers user, boolean force,
24 boolean sync) throws StorageObjectException, ModuleException {
25 handle(htmlout,user,force,sync,null);
28 public void handle(PrintWriter htmlout,EntityUsers user,boolean force,
29 boolean sync, String id) throws StorageObjectException, ModuleException
31 long sessionConnectTime = 0;
32 long startTime = (new java.util.Date()).getTime();
36 MirMedia currentMediaHandler;
37 EntityList batchEntityList;
39 int contentBatchsize =
40 Integer.parseInt(MirConfig.getProp("Producer.Content.Batchsize"));
41 orderBy = "date desc, webdb_lastchange desc";
43 // get batch of non-produced medias, that are to be published
44 whereClause="is_published='1'";
46 whereClause += " and id="+id;
47 // optimization to avoid select count(*)..
48 contentBatchsize = -1;
50 if (force==false) whereClause += " and is_produced='0'";
52 batchEntityList = getStorage().selectByWhereClause(whereClause,
53 orderBy, 0, contentBatchsize);
55 while (batchEntityList != null) {
56 for(int i=0;i<batchEntityList.size();i++) {
57 currentMedia = (Entity)batchEntityList.elementAt(i);
59 Entity currentMediaType =
60 DatabaseUploadedMedia.getInstance().getMediaType(currentMedia);
61 currentMediaHandler = MediaHelper.getHandler( currentMediaType );
64 currentMediaHandler.produce(currentMedia,currentMediaType);
65 currentMedia.setValueForProperty("publish_server",
66 currentMediaHandler.getPublishHost());
67 currentMedia.setValueForProperty("icon_is_produced", "1");
68 currentMedia.setValueForProperty("is_produced", "1");
69 currentMedia.update();
70 logHTML(htmlout,"produced media id "+currentMedia.getId()
71 +": "+currentMediaType.getValue("mime_type")+" success");
72 } catch (Exception e) {
73 // don't throw and exception here, just log.
74 // we don't want to make the admin interface unuseable
75 theLog.printError("media exception: "+currentMedia.getId()+
77 logHTML(htmlout, "problem with media id: "+currentMedia.getId()+
78 " <font color=\"Red\"> failed!</font>: "+e.toString());
79 e.printStackTrace(htmlout);
83 // if next batch get it...
84 if (batchEntityList.hasNextBatch()){
85 batchEntityList = uploadedMediaModule.getByWhereClause(whereClause,
86 orderBy, batchEntityList.getNextBatch(),contentBatchsize);
92 sessionConnectTime = new java.util.Date().getTime() - startTime;
93 logHTML(htmlout, "Producer.Media finished: " + sessionConnectTime + " ms.");