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, false,false);
24 } catch(Exception e) { System.err.println(e.toString()); }
27 public void handle(PrintWriter htmlout, EntityUsers user, boolean force, boolean sync)
28 throws StorageObjectException, ModuleException {
29 handle(htmlout,user,force,sync,null);
32 public void handle(PrintWriter htmlout, EntityUsers user, boolean force, boolean sync, String id)
33 throws StorageObjectException, ModuleException
35 long sessionConnectTime = 0;
36 long startTime = (new java.util.Date()).getTime();
40 String productionPath;
41 EntityImages currentImage;
42 EntityList batchEntityList;
44 int contentBatchsize = Integer.parseInt(MirConfig.getProp("Producer.Content.Batchsize"));
45 String imageHost = MirConfig.getProp("Producer.Image.Host");
46 String imagePath = MirConfig.getProp("Producer.Image.Path");
47 String iconPath = MirConfig.getProp("Producer.Image.IconPath");
49 // get batch of non-produced images, that are to be published
50 whereClause="is_published='1'";
52 whereClause += " and id="+id;
53 if (force==false) whereClause += " and icon_is_produced='0'";
55 batchEntityList = imageModule.getByWhereClause(whereClause, null, 0, contentBatchsize);
56 theLog.printDebugInfo("whereclause: " + whereClause);
59 while (batchEntityList != null) {
60 for(int i=0;i<batchEntityList.size();i++) {
61 theLog.printDebugInfo("trying image: " + i);
62 currentImage = (EntityImages)batchEntityList.elementAt(i);
66 String date = currentImage.getValue("date");
68 iconFilename = producerDocRoot + iconPath + StringUtil.webdbDate2path(date) +
69 currentImage.getId() + (( currentImage.getValue("to_img_type").equals("0") ) ? ".jpg":".gif");
71 imageFilename = currentImage.getId() + (( currentImage.getValue("to_img_type").equals("0") ) ? ".jpg":".gif");
72 productionPath = imagePath + "/" + imageFilename ;
74 currentImage.setValueForProperty("icon_path",iconFilename);
75 currentImage.setValueForProperty("publish_path",imageFilename);
76 currentImage.setValueForProperty("publish_server", imageHost);
78 if (currentImage.getValue("icon_data")!= null && currentImage.getValue("image_data")!= null) {
80 boolean iconProduced = produceFile(iconFilename, currentImage.getIcon(), htmlout, true);
81 logHTML(htmlout,"icon : " + iconFilename + (( iconProduced==true )? " succeded":" <font color=\"Red\" failed!</font>"));
83 boolean imageProduced = produceFile(productionPath, currentImage.getImage(), htmlout, false);
84 logHTML(htmlout,"image: " + productionPath + ((imageProduced==true)?" succeded":" <font color=\"Red\" failed!</font>"));
87 if (iconProduced && imageProduced) {
88 currentImage.setValueForProperty("icon_is_produced", "1");
89 currentImage.update();
93 } catch (Exception e) {
94 logHTML(htmlout, "Producer.Images ERROR with: image ID " + currentImage.getId() + " <font color=\"Red\"> failed!</font>");
98 // if next batch get it...
99 if (batchEntityList.hasNextBatch()){
100 batchEntityList = imageModule.getByWhereClause(whereClause,
101 null, batchEntityList.getNextBatch(),
104 batchEntityList=null;
108 sessionConnectTime = new java.util.Date().getTime() - startTime;
109 logHTML(htmlout, "Producer.Images finished: " + sessionConnectTime + " ms.");