1 33 package net.myvietnam.mvncore.web.impl; 34 35 import java.io.File ; 36 import java.util.List ; 37 38 import net.myvietnam.mvncore.web.FileUploadParser; 39 import net.myvietnam.mvncore.web.GenericRequest; 40 import net.myvietnam.mvncore.web.fileupload.FileUploadException; 41 import net.myvietnam.mvncore.web.fileupload.disk.DiskFileItemFactory; 42 import net.myvietnam.mvncore.web.fileupload.servlet.ServletFileUpload; 43 44 public class FileUploadParserServletImpl implements FileUploadParser { 45 46 public List parseRequest(GenericRequest request, int sizeMax, int sizeThreshold, String repository, String headerEncoding) 47 throws FileUploadException { 48 49 DiskFileItemFactory factory = new DiskFileItemFactory(); 50 51 if (repository != null) { 52 factory.setRepository(new File (repository)); 53 } 54 55 factory.setSizeThreshold(sizeThreshold); 56 57 List fileItems = null; 58 59 if (request.isServletRequest()) { 60 ServletFileUpload upload = new ServletFileUpload(factory); 61 upload.setSizeMax(sizeMax); 62 if (headerEncoding != null) { 63 upload.setHeaderEncoding(headerEncoding); 64 } 65 fileItems = upload.parseRequest(request.getServletRequest()); 66 } else { 67 throw new IllegalStateException ("Not implemeneted for portlet."); 68 } 69 return fileItems; 70 } 71 } 72 | Popular Tags |