1 package mircoders.producer;
7 import freemarker.template.*;
10 import webdb.storage.*;
11 import webdb.module.*;
12 import webdb.entity.*;
20 public class ProducerImages extends Producer {
22 public static void main(String argv[]){
24 new ProducerContent().handle(new PrintWriter(System.out), null, false,false);
25 } catch(Exception e) { System.err.println(e.toString()); }
28 public void handle(PrintWriter htmlout, EntityUsers user, boolean force, boolean sync)
29 throws StorageObjectException, ModuleException {
30 handle(htmlout,user,force,sync,null);
33 public void handle(PrintWriter htmlout, EntityUsers user, boolean force, boolean sync, String id)
34 throws StorageObjectException, ModuleException
36 long sessionConnectTime = 0;
37 long startTime = (new java.util.Date()).getTime();
41 String productionPath;
42 EntityImage currentImage;
43 EntityList batchEntityList;
45 int contentBatchsize = Integer.parseInt(Configuration.getProperty("Producer.Content.Batchsize"));
46 String imageHost = Configuration.getProperty("Producer.Image.Host");
47 String imagePath = Configuration.getProperty("Producer.Image.Path");
48 String iconPath = Configuration.getProperty("Producer.Image.IconPath");
50 // get batch of non-produced images, that are to be published
51 whereClause="is_published='1'";
53 whereClause += " and id="+id;
54 if (force==false) whereClause += " and icon_is_produced='0'";
56 batchEntityList = imageModule.getByWhereClause(whereClause, null, 0, contentBatchsize);
57 theLog.printDebugInfo("whereclause: " + whereClause);
60 while (batchEntityList != null) {
61 for(int i=0;i<batchEntityList.size();i++) {
62 theLog.printDebugInfo("trying image: " + i);
63 currentImage = (EntityImage)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","imc/germany/" + imageFilename);
76 currentImage.setValueForProperty("publish_path",imageFilename);
77 currentImage.setValueForProperty("publish_server", imageHost);
79 if (currentImage.getValue("icon_data")!= null && currentImage.getValue("image_data")!= null) {
81 boolean iconProduced = produceFile(iconFilename, currentImage.getIcon(), htmlout, true);
82 logHTML(htmlout,"icon : " + iconFilename + (( iconProduced==true )? " succeded":" <font color=\"Red\" failed!</font>"));
84 boolean imageProduced = produceFile(productionPath, currentImage.getImage(), htmlout, false);
85 logHTML(htmlout,"image: " + productionPath + ((imageProduced==true)?" succeded":" <font color=\"Red\" failed!</font>"));
88 if (iconProduced && imageProduced) {
89 currentImage.setValueForProperty("icon_is_produced", "1");
90 currentImage.update();
96 // if next batch get it...
97 if (batchEntityList.hasNextBatch()){
98 batchEntityList = imageModule.getByWhereClause(whereClause, null, batchEntityList.getNextBatch(),contentBatchsize);
100 batchEntityList=null;
104 sessionConnectTime = new java.util.Date().getTime() - startTime;
105 logHTML(htmlout, "Producer.Images finished: " + sessionConnectTime + " ms.");