KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > openedit > archive > ImageMaker


1 /*
2  * Created on Jun 8, 2005
3  *
4  * TODO To change the template for this generated file go to
5  * Window - Preferences - Java - Code Style - Code Templates
6  */

7 package com.openedit.archive;
8
9 import java.io.File JavaDoc;
10 import java.util.Iterator JavaDoc;
11 import java.util.List JavaDoc;
12
13 import org.apache.commons.logging.Log;
14 import org.apache.commons.logging.LogFactory;
15
16 import com.openedit.store.Product;
17 import com.openedit.store.edit.AutoImageCreator;
18 import com.openedit.util.FileUtils;
19
20 /**
21  * @author admin
22  *
23  * TODO To change the template for this generated type comment go to
24  * Window - Preferences - Java - Code Style - Code Templates
25  */

26 public class ImageMaker extends AutoImageCreator {
27
28     private static final Log log = LogFactory.getLog(ImageMaker.class);
29     Archive fieldArchive;
30     
31     protected File JavaDoc getOriginalDocument(Product inProd)
32     {
33         return getArchive().getOriginalDocument(inProd);
34     }
35     public Archive getArchive()
36     {
37         return fieldArchive;
38     }
39     public void setArchive(Archive inArchive)
40     {
41         fieldArchive = inArchive;
42         setStore(inArchive.getStore());
43     }
44     public void backUpOriginals() throws Exception JavaDoc
45     {
46         //skip things if the originals is the not being locally cached
47
if ( getArchive().getOriginalsRootDirectory() == null )
48         {
49             return;
50         }
51         List JavaDoc products = getStore().getProductArchive().listAllProductIds();
52         log.info("Locally caching " + products.size() + " images");
53         FileUtils util = new FileUtils();
54         for (Iterator JavaDoc iter = products.iterator(); iter.hasNext();)
55         {
56             String JavaDoc productid = (String JavaDoc) iter.next();
57             //check for medium size. If not then convert to jpg and render
58
Product product = getStore().getProduct(productid);
59             if ( product != null)
60             {
61                 String JavaDoc path = product.get("originalpath");
62                 File JavaDoc source = new File JavaDoc( path );
63                 File JavaDoc dest = getArchive().findCachedFile(product);
64                 if( dest != null && !dest.exists())
65                 {
66                     dest.getParentFile().mkdirs();
67                     util.copyFiles(source, dest);
68                 }
69                 getStore().getProductArchive().clearProduct(product);
70             }
71         }
72     }
73     
74     protected String JavaDoc ext()
75     {
76         if ( isUse100s())
77         {
78             return "-100.jpg";
79         }
80         return ".jpg";
81     }
82
83 }
84
85
Popular Tags