1 3 package jodd.servlet.upload; 4 5 import jodd.servlet.ServletUtil; 6 7 import javax.servlet.http.HttpServletRequestWrapper ; 8 import javax.servlet.http.HttpServletRequest ; 9 import java.util.Map ; 10 import java.util.HashMap ; 11 import java.util.Enumeration ; 12 import java.util.Collections ; 13 import java.io.IOException ; 14 15 19 public class MultipartRequestWrapper extends HttpServletRequestWrapper { 20 21 23 MultipartRequest mreq; 24 HttpServletRequest req; 25 26 public MultipartRequestWrapper(HttpServletRequest request, FileUploadFactory fileUploadFactory, String encoding) throws IOException { 27 super(request); 28 req = request; 29 if (ServletUtil.isMultipartRequest(request)) { 30 mreq = MultipartRequest.getParsedInstance(request, fileUploadFactory, encoding); 31 } 32 } 33 34 public MultipartRequestWrapper(HttpServletRequest request, FileUploadFactory fileUploadFactory) throws IOException { 35 super(request); 36 if (ServletUtil.isMultipartRequest(request)) { 37 mreq = MultipartRequest.getParsedInstance(request, fileUploadFactory); 38 } 39 } 40 41 public MultipartRequestWrapper(MultipartRequest mpreq) { 42 super(mpreq.getServletRequest()); 43 mreq = mpreq; 44 } 45 46 50 public MultipartRequest getMultipartRequest() { 51 return mreq; 52 } 53 54 57 public boolean isMultipart() { 58 return mreq != null; 59 } 60 61 63 66 public Enumeration getFileParameterNames() { 67 if (mreq == null) { 68 return null; 69 } 70 return Collections.enumeration(mreq.getFileParameterNames()); 71 } 72 73 79 public FileUpload[] getFiles(String fieldName) { 80 if (mreq == null) { 81 return null; 82 } 83 return mreq.getFiles(fieldName); 84 } 85 86 public FileUpload getFile(String fieldName) { 87 if (mreq == null) { 88 return null; 89 } 90 return mreq.getFile(fieldName); 91 } 92 93 94 97 public String getParameter(String name) { 98 if (mreq == null) { 99 return super.getParameter(name); 100 } 101 return mreq.getParameter(name); 102 } 103 104 107 public Map getParameterMap() { 108 if (mreq == null) { 109 return super.getParameterMap(); 110 } 111 Map map = new HashMap (); 112 Enumeration enumeration = getParameterNames(); 113 while (enumeration.hasMoreElements()) { 114 String name = (String ) enumeration.nextElement(); 115 map.put(name, this.getParameterValues(name)); 116 } 117 return map; 118 } 119 120 123 public Enumeration getParameterNames() { 124 if (mreq == null) { 125 return super.getParameterNames(); 126 } 127 return Collections.enumeration(mreq.getParameterNames()); 128 } 129 130 133 public String [] getParameterValues(String name) { 134 if (mreq == null) { 135 return super.getParameterValues(name); 136 } 137 return mreq.getParameterValues(name); 138 } 139 140 } 141 | Popular Tags |