1 7 package com.openedit.archive; 8 9 import java.io.File ; 10 import java.util.Iterator ; 11 import java.util.List ; 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 26 public class ImageMaker extends AutoImageCreator { 27 28 private static final Log log = LogFactory.getLog(ImageMaker.class); 29 Archive fieldArchive; 30 31 protected File 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 45 { 46 if ( getArchive().getOriginalsRootDirectory() == null ) 48 { 49 return; 50 } 51 List products = getStore().getProductArchive().listAllProductIds(); 52 log.info("Locally caching " + products.size() + " images"); 53 FileUtils util = new FileUtils(); 54 for (Iterator iter = products.iterator(); iter.hasNext();) 55 { 56 String productid = (String ) iter.next(); 57 Product product = getStore().getProduct(productid); 59 if ( product != null) 60 { 61 String path = product.get("originalpath"); 62 File source = new File ( path ); 63 File 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 ext() 75 { 76 if ( isUse100s()) 77 { 78 return "-100.jpg"; 79 } 80 return ".jpg"; 81 } 82 83 } 84 85 | Popular Tags |