View Javadoc

1   package net.sourceforge.blogentis.utils.filters;
2   
3   import java.io.File;
4   import java.io.IOException;
5   import java.util.Enumeration;
6   import java.util.HashMap;
7   import java.util.Map;
8   
9   import javax.servlet.http.HttpServletRequest;
10  import javax.servlet.http.HttpServletRequestWrapper;
11  
12  import com.oreilly.servlet.MultipartRequest;
13  
14  /***
15   * A request wrapper to support MultipartFilter. The filter capability requires
16   * Servlet API 2.3.
17   * <p>
18   * See Jason Hunter's June 2001 article in JavaWorld for a full explanation of
19   * the class usage.
20   * 
21   * @author <b>Jason Hunter </b>, Copyright &#169; 2001
22   * @version 1.0, 2001/06/19
23   */
24  public class MultipartWrapper
25          extends HttpServletRequestWrapper {
26  
27      MultipartRequest mreq = null;
28  
29      public MultipartWrapper(HttpServletRequest req, String dir, String encoding)
30              throws IOException {
31          super(req);
32          mreq = new MultipartRequest(req, dir, encoding);
33      }
34  
35      // Methods to replace HSR methods
36      public Enumeration getParameterNames() {
37          return mreq.getParameterNames();
38      }
39  
40      public String getParameter(String name) {
41          return mreq.getParameter(name);
42      }
43  
44      public String[] getParameterValues(String name) {
45          return mreq.getParameterValues(name);
46      }
47  
48      public Map getParameterMap() {
49          Map map = new HashMap();
50          Enumeration enum = getParameterNames();
51          while (enum.hasMoreElements()) {
52              String name = (String)enum.nextElement();
53              map.put(name, mreq.getParameterValues(name));
54          }
55          return map;
56      }
57  
58      // Methods only in MultipartRequest
59      public Enumeration getFileNames() {
60          return mreq.getFileNames();
61      }
62  
63      public String getFilesystemName(String name) {
64          return mreq.getFilesystemName(name);
65      }
66  
67      public String getContentType(String name) {
68          return mreq.getContentType(name);
69      }
70  
71      public File getFile(String name) {
72          return mreq.getFile(name);
73      }
74  }