1 19 20 package com.sslexplorer.core; 21 22 import java.io.IOException ; 23 import java.io.InputStream ; 24 import java.io.OutputStream ; 25 26 import javax.servlet.http.HttpServletRequest ; 27 import javax.servlet.http.HttpServletResponse ; 28 29 import org.apache.struts.action.ActionForward; 30 import org.apache.struts.upload.FormFile; 31 32 import com.sslexplorer.boot.Repository; 33 import com.sslexplorer.boot.RepositoryFactory; 34 import com.sslexplorer.boot.RepositoryStore; 35 import com.sslexplorer.boot.Util; 36 import com.sslexplorer.vfs.UploadDetails; 37 38 public class RepositoryUploadHandler implements UploadHandler { 39 public static final String TYPE_REPOSITORY = "REPOSITORY"; 40 41 public RepositoryUploadHandler() { 42 super(); 43 } 44 45 public ActionForward performUpload(HttpServletRequest request, HttpServletResponse response, UploadDetails upload, FormFile uploadFile) 46 throws Exception { 47 try { 48 49 53 if(upload.getResourcePath() == null || upload.getResourcePath().length()==0) { 54 return upload.getUploadedForward(); 55 } 56 57 if(uploadFile.getFileName() == null || uploadFile.getFileName().trim().equals("")) { 58 return upload.getUploadedForward(); 59 } 60 61 Repository repository = RepositoryFactory.getRepository(); 63 if(upload.getExtraAttribute1() == null || upload.getExtraAttribute1().equals("")) { 64 throw new Exception ("No store name provided."); 65 } 66 RepositoryStore store = repository.getStore(upload.getExtraAttribute1()); 67 68 InputStream in = uploadFile.getInputStream(); 70 try { 71 OutputStream out = store.getEntryOutputStream(upload.getResourcePath()) ; 72 try { 73 Util.copy(in, out); 74 } 75 finally { 76 Util.closeStream(out); 77 } 78 } 79 finally { 80 Util.closeStream(in); 81 } 82 return upload.getUploadedForward(); 83 } 84 catch(Exception e) { 85 88 try { 89 request.getInputStream().close(); 90 } 91 catch(IOException ioe) { 92 throw ioe; 93 } 94 throw e ; 95 } 96 } 97 98 public boolean checkFileToUpload(HttpServletRequest request, HttpServletResponse response, UploadDetails fileUpload, FormFile file) throws IOException , Exception { 99 return false; 101 } 102 103 } 104 | Popular Tags |