1 16 17 package org.apache.cocoon.servlet.multipart; 18 19 import java.io.File ; 20 import java.io.IOException ; 21 import java.util.Hashtable ; 22 23 import javax.servlet.http.HttpServletRequest ; 24 25 31 public class RequestFactory { 32 33 private boolean saveUploadedFilesToDisk; 34 35 private File uploadDirectory; 36 37 private boolean allowOverwrite; 38 39 private boolean silentlyRename; 40 41 private String defaultCharEncoding; 42 43 private int maxUploadSize; 44 45 public RequestFactory (boolean saveUploadedFilesToDisk, 46 File uploadDirectory, 47 boolean allowOverwrite, 48 boolean silentlyRename, 49 int maxUploadSize, 50 String defaultCharEncoding) { 51 this.saveUploadedFilesToDisk = saveUploadedFilesToDisk; 52 this.uploadDirectory = uploadDirectory; 53 this.allowOverwrite = allowOverwrite; 54 this.silentlyRename = silentlyRename; 55 this.maxUploadSize = maxUploadSize; 56 this.defaultCharEncoding = defaultCharEncoding; 57 58 if (saveUploadedFilesToDisk) { 59 File [] files = uploadDirectory.listFiles(); 61 for (int i = 0; i < files.length; i++) { 62 files[i].delete(); 63 } 64 } 65 } 66 67 72 public HttpServletRequest getServletRequest(HttpServletRequest request) throws IOException , MultipartException { 73 HttpServletRequest req = request; 74 String contentType = request.getContentType(); 75 76 if ((contentType != null) && (contentType.toLowerCase().indexOf("multipart/form-data") > -1)) { 77 78 String charEncoding = request.getCharacterEncoding(); 79 if (charEncoding == null || charEncoding.equals("")) { 80 charEncoding = this.defaultCharEncoding; 81 } 82 83 MultipartParser parser = new MultipartParser( 84 this.saveUploadedFilesToDisk, 85 this.uploadDirectory, 86 this.allowOverwrite, 87 this.silentlyRename, 88 this.maxUploadSize, 89 charEncoding); 90 91 Hashtable parts = parser.getParts(request); 92 93 req = new MultipartHttpServletRequest(request,parts); 94 } 95 96 return req; 97 } 98 99 } | Popular Tags |