1 4 package com.openedit.generators; 5 6 import java.io.File ; 7 8 import org.apache.commons.logging.Log; 9 import org.apache.commons.logging.LogFactory; 10 11 import com.openedit.OpenEditException; 12 import com.openedit.WebPageRequest; 13 import com.openedit.page.Page; 14 import com.openedit.page.manage.PageManager; 15 import com.openedit.util.PageZipUtil; 16 import com.openedit.util.PathUtilities; 17 18 public class ZipGenerator extends BaseGenerator 19 { 20 File fieldRoot; 21 protected PageManager pageManager; 22 private static final Log log = LogFactory.getLog(ZipGenerator.class); 23 public void generate(WebPageRequest inReq, Page inPage, Output inOut) throws OpenEditException 24 { 25 String path = inReq.getRequestParameter("path"); 26 if (path.indexOf("..") > -1) 27 { 28 throw new OpenEditException("Illegal path name"); 29 } 30 if( inReq.getUser() == null) 32 { 33 throw new OpenEditException("Illegal user"); 34 } 35 path = PathUtilities.resolveRelativePath( path, "/"); 36 37 try 39 { 40 log.info("Zip up:" + path); 41 PageZipUtil pageZipUtil = new PageZipUtil(getPageManager()); 42 pageZipUtil.setRoot(getRoot()); 43 pageZipUtil.zipFile(path, inOut.getStream()); 44 } 45 catch ( Exception ex) 46 { 47 log.error(ex); 48 } 49 } 50 51 protected File getRoot() 52 { 53 return fieldRoot; 54 } 55 56 public void setRoot(File inRoot) 57 { 58 fieldRoot = inRoot; 59 } 60 public boolean canGenerate(WebPageRequest inReq) 61 { 62 return true; 63 } 64 65 public PageManager getPageManager() 66 { 67 return pageManager; 68 } 69 70 public void setPageManager(PageManager inPageManager) 71 { 72 pageManager = inPageManager; 73 } 74 75 } 76 | Popular Tags |