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;
43 String orderBy = "date desc, webdb_lastchange desc";
45 int contentBatchsize = Integer.parseInt(MirConfig.getProp("Producer.Content.Batchsize"));
46 String imageHost = MirConfig.getProp("Producer.Image.Host");
47 String imagePath = MirConfig.getProp("Producer.Image.Path");
48 String iconPath = MirConfig.getProp("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, orderBy, 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 = (EntityImages)batchEntityList.elementAt(i);
67 String date = currentImage.getValue("date");
69 iconFilename = producerDocRoot + iconPath + StringUtil.webdbDate2path(date) +
70 currentImage.getId() + (( currentImage.getValue("to_img_type").equals("0") ) ? ".jpg":".gif");
72 imageFilename = currentImage.getId() + (( currentImage.getValue("to_img_type").equals("0") ) ? ".jpg":".gif");
73 productionPath = imagePath + "/" + imageFilename ;
75 currentImage.setValueForProperty("icon_path",iconFilename);
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();
94 } catch (Exception e) {
95 logHTML(htmlout, "Producer.Images ERROR with: image ID " + currentImage.getId() + " <font color=\"Red\"> failed!</font>");
99 // if next batch get it...
100 if (batchEntityList.hasNextBatch()){
101 batchEntityList = imageModule.getByWhereClause(whereClause,
102 orderBy, batchEntityList.getNextBatch(),
105 batchEntityList=null;
109 sessionConnectTime = new java.util.Date().getTime() - startTime;
110 logHTML(htmlout, "Producer.Images finished: " + sessionConnectTime + " ms.");