1 package mircoders.producer;
7 import freemarker.template.*;
14 import mircoders.entity.*;
19 public class ProducerImages extends Producer {
21 public static void main(String argv[]){
23 new ProducerContent().handle(new PrintWriter(System.out), null,
25 } catch(Exception e) { System.err.println(e.toString()); }
28 public void handle(PrintWriter htmlout, EntityUsers user, boolean force,
30 throws StorageObjectException, ModuleException {
31 handle(htmlout,user,force,sync,null);
34 public void handle(PrintWriter htmlout, EntityUsers user, boolean force,
35 boolean sync, String id)
36 throws StorageObjectException, ModuleException
38 long sessionConnectTime = 0;
39 long startTime = (new java.util.Date()).getTime();
43 String productionPath;
44 EntityImages currentImage;
45 EntityList batchEntityList;
46 String orderBy = "date desc, webdb_lastchange desc";
48 int contentBatchsize = Integer.parseInt(MirConfig.getProp(
49 "Producer.Content.Batchsize"));
50 String imageHost = MirConfig.getProp("Producer.Image.Host");
51 String imagePath = MirConfig.getProp("Producer.Image.Path");
52 String iconPath = MirConfig.getProp("Producer.Image.IconPath");
54 // get batch of non-produced images, that are to be published
55 whereClause="is_published='1'";
57 whereClause += " and id="+id;
58 if (force==false) whereClause += " and icon_is_produced='0'";
60 batchEntityList = imageModule.getByWhereClause(whereClause, orderBy, 0,
62 theLog.printDebugInfo("whereclause: " + whereClause);
65 while (batchEntityList != null) {
66 for(int i=0;i<batchEntityList.size();i++) {
67 theLog.printDebugInfo("trying image: " + i);
68 currentImage = (EntityImages)batchEntityList.elementAt(i);
72 String date = currentImage.getValue("date");
73 String datePath = StringUtil.webdbDate2path(date);
75 iconFilename=producerDocRoot + iconPath + datePath +
76 currentImage.getId() +
77 ((currentImage.getValue("to_img_type").equals("0"))
80 imageFilename=datePath + currentImage.getId() +
81 ((currentImage.getValue("to_img_type").equals("0"))
83 productionPath = imagePath + "/" + imageFilename ;
85 currentImage.setValueForProperty("icon_path",iconFilename);
86 currentImage.setValueForProperty("publish_path",imageFilename);
87 currentImage.setValueForProperty("publish_server", imageHost);
89 if (currentImage.getValue("icon_data")!= null &&
90 currentImage.getValue("image_data")!= null) {
92 boolean iconProduced = produceFile(iconFilename,
93 currentImage.getIcon(),
95 logHTML(htmlout,"icon : "+iconFilename+((
97 " succeded":" <font color=\"Red\" failed!</font>"));
99 boolean imageProduced = produceFile(productionPath,
100 currentImage.getImage(),
102 logHTML(htmlout,"image: "+productionPath +
103 ((imageProduced==true)?
104 " succeded":" <font color=\"Red\" failed!</font>"));
107 if (iconProduced && imageProduced) {
108 currentImage.setValueForProperty("icon_is_produced",
110 currentImage.update();
114 } catch (Exception e) {
115 logHTML(htmlout, "Producer.Images ERROR with: image ID "+
116 currentImage.getId() +
117 " <font color=\"Red\"> failed!</font>");
121 // if next batch get it...
122 if (batchEntityList.hasNextBatch()){
123 batchEntityList = imageModule.getByWhereClause(whereClause,
124 orderBy, batchEntityList.getNextBatch(),
127 batchEntityList=null;
131 sessionConnectTime = new java.util.Date().getTime() - startTime;
132 logHTML(htmlout, "Producer.Images finished: " + sessionConnectTime +