1 16 package org.apache.cocoon.portlet.multipart; 17 18 import org.apache.cocoon.servlet.multipart.MultipartException; 19 import org.apache.cocoon.servlet.multipart.MultipartParser; 20 21 import javax.portlet.ActionRequest; 22 23 import java.io.File ; 24 import java.io.IOException ; 25 import java.util.Hashtable ; 26 27 33 public class RequestFactory { 34 35 private boolean saveUploadedFilesToDisk; 36 private File uploadDirectory; 37 private boolean allowOverwrite; 38 private boolean silentlyRename; 39 private String defaultCharEncoding; 40 private int maxUploadSize; 41 42 public RequestFactory(boolean saveUploadedFilesToDisk, 43 File uploadDirectory, 44 boolean allowOverwrite, 45 boolean silentlyRename, 46 int maxUploadSize, 47 String defaultCharEncoding) { 48 this.saveUploadedFilesToDisk = saveUploadedFilesToDisk; 49 this.uploadDirectory = uploadDirectory; 50 this.allowOverwrite = allowOverwrite; 51 this.silentlyRename = silentlyRename; 52 this.maxUploadSize = maxUploadSize; 53 this.defaultCharEncoding = defaultCharEncoding; 54 } 55 56 61 public ActionRequest getServletRequest(ActionRequest request) 62 throws IOException , MultipartException { 63 ActionRequest req = request; 64 String contentType = request.getContentType(); 65 66 if ((contentType != null) && (contentType.toLowerCase().indexOf("multipart/form-data") > -1)) { 67 if (request.getContentLength() > maxUploadSize) { 68 throw new IOException ("Content length exceeds maximum upload size."); 69 } 70 71 String charEncoding = request.getCharacterEncoding(); 72 if (charEncoding == null || charEncoding.equals("")) { 73 charEncoding = this.defaultCharEncoding; 74 } 75 76 MultipartParser parser = 77 new MultipartParser( 78 this.saveUploadedFilesToDisk, 79 this.uploadDirectory, 80 this.allowOverwrite, 81 this.silentlyRename, 82 this.maxUploadSize, 83 charEncoding); 84 85 Hashtable parts = parser.getParts(request.getContentLength(), 86 request.getContentType(), 87 request.getPortletInputStream()); 88 89 req = new MultipartActionRequest(request, parts); 90 } 91 92 return req; 93 } 94 } 95 | Popular Tags |