KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > webwork > dispatcher > multipart > MultiPartRequest


1 /*
2  * Copyright (c) 2002-2003 by OpenSymphony
3  * All rights reserved.
4  */

5 package com.opensymphony.webwork.dispatcher.multipart;
6
7 import org.apache.commons.logging.Log;
8 import org.apache.commons.logging.LogFactory;
9
10 import javax.servlet.http.HttpServletRequest JavaDoc;
11 import java.io.File JavaDoc;
12 import java.util.Enumeration JavaDoc;
13 import java.util.List JavaDoc;
14
15
16 /**
17  * Abstract wrapper class HTTP requests to handle multi-part data. <p>
18  *
19  * @author <a HREF="mailto:matt@smallleap.com">Matt Baldree</a>
20  * @author Patrick Lightbody
21  * @author Bill Lynch (docs)
22  */

23 public abstract class MultiPartRequest {
24     //~ Static fields/initializers /////////////////////////////////////////////
25

26     protected static Log log = LogFactory.getLog(MultiPartRequest.class);
27
28     //~ Methods ////////////////////////////////////////////////////////////////
29

30     /**
31      * Returns <tt>true</tt> if the request is multipart form data, <tt>false</tt> otherwise.
32      *
33      * @param request the http servlet request.
34      * @return <tt>true</tt> if the request is multipart form data, <tt>false</tt> otherwise.
35      */

36     public static boolean isMultiPart(HttpServletRequest JavaDoc request) {
37         String JavaDoc content_type = request.getContentType();
38         return content_type != null && content_type.indexOf("multipart/form-data") != -1;
39     }
40
41     /**
42      * Returns an enumeration of the parameter names for uploaded files
43      *
44      * @return an enumeration of the parameter names for uploaded files
45      */

46     public abstract Enumeration JavaDoc getFileParameterNames();
47
48     /**
49      * Returns the content type(s) of the file(s) associated with the specified field name
50      * (as supplied by the client browser), or <tt>null</tt> if no files are associated with the
51      * given field name.
52      *
53      * @param fieldName input field name
54      * @return an array of content encoding for the specified input field name or <tt>null</tt> if
55      * no content type was specified.
56      */

57     public abstract String JavaDoc[] getContentType(String JavaDoc fieldName);
58
59     /**
60      * Returns a {@link java.io.File} object for the filename specified or <tt>null</tt> if no files
61      * are associated with the given field name.
62      *
63      * @param fieldName input field name
64      * @return a File[] object for files associated with the specified input field name
65      */

66     public abstract File JavaDoc[] getFile(String JavaDoc fieldName);
67
68     /**
69      * Returns a String[] of file names for files associated with the specified input field name
70      *
71      * @param fieldName input field name
72      * @return a String[] of file names for files associated with the specified input field name
73      */

74     public abstract String JavaDoc[] getFileNames(String JavaDoc fieldName);
75
76     /**
77      * Returns the file system name(s) of files associated with the given field name or
78      * <tt>null</tt> if no files are associated with the given field name.
79      *
80      * @param fieldName input field name
81      * @return the file system name(s) of files associated with the given field name
82      */

83     public abstract String JavaDoc[] getFilesystemName(String JavaDoc fieldName);
84
85     /**
86      * Returns the specified request parameter.
87      *
88      * @param name the name of the parameter to get
89      * @return the parameter or <tt>null</tt> if it was not found.
90      */

91     public abstract String JavaDoc getParameter(String JavaDoc name);
92
93     /**
94      * Returns an enumeration of String parameter names.
95      *
96      * @return an enumeration of String parameter names.
97      */

98     public abstract Enumeration JavaDoc getParameterNames();
99
100     /**
101      * Returns a list of all parameter values associated with a parameter name. If there is only
102      * one parameter value per name the resulting array will be of length 1.
103      *
104      * @param name the name of the parameter.
105      * @return an array of all values associated with the parameter name.
106      */

107     public abstract String JavaDoc[] getParameterValues(String JavaDoc name);
108
109     /**
110      * Returns a list of error messages that may have occurred while processing the request.
111      * If there are no errors, an empty list is returned. If the underlying implementation
112      * (ie: pell, cos, jakarta, etc) cannot support providing these errors, an empty list is
113      * also returned. This list of errors is repoted back to the
114      * {@link MultiPartRequestWrapper#errors} field.
115      *
116      * @return a list of Strings that represent various errors during parsing
117      */

118     public abstract List JavaDoc getErrors();
119 }
120
Popular Tags