View Javadoc

1   package http.utils.multipartrequest;
2   
3   import java.io.PrintWriter;
4   import java.io.IOException;
5   
6   import javax.servlet.ServletRequest;
7   import javax.servlet.http.HttpServletRequest;
8   
9   /***
10      A Multipart form data parser.  Parses an input stream and writes out any files found, 
11      making available a hashtable of other url parameters.  As of version 1.17 the files can
12      be saved to memory, and optionally written to a database, etc.
13      
14      <BR>
15      <BR>
16      Copyright (c)2001-2003 Jason Pell.
17      <BR>
18  
19      <PRE>
20      This library is free software; you can redistribute it and/or
21      modify it under the terms of the GNU Lesser General Public
22      License as published by the Free Software Foundation; either
23      version 2.1 of the License, or (at your option) any later version.
24      <BR>
25      This library is distributed in the hope that it will be useful,
26      but WITHOUT ANY WARRANTY; without even the implied warranty of
27      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
28      Lesser General Public License for more details.
29      <BR>
30      You should have received a copy of the GNU Lesser General Public
31      License along with this library; if not, write to the Free Software
32      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
33      <BR>    
34      Email:  jasonpell@hotmail.com
35      Url:    http://www.geocities.com/jasonpell
36      </PRE>
37  	Wrapper for MultipartRequest
38  */
39  public class ServletMultipartRequest extends MultipartRequest
40  {
41  	/***
42  	 * @deprecated Replaced by ServletMultipartRequest(ServletRequest, String, int, boolean, String)
43  	 */
44  	public ServletMultipartRequest(HttpServletRequest request, String strSaveDirectory) throws IllegalArgumentException, IOException
45  	{
46   	    super(null,
47  			request.getContentType(),
48  			request.getContentLength(),
49  			request.getInputStream(),
50  			strSaveDirectory,
51  			MultipartRequest.MAX_READ_BYTES);
52  	}
53  
54  	/***
55  	 * @deprecated Replaced by ServletMultipartRequest(ServletRequest, String, int, boolean, String)
56  	 */
57  	public ServletMultipartRequest(HttpServletRequest request, String strSaveDirectory, int intMaxReadBytes) throws IllegalArgumentException, IOException
58  	{
59   	    super(null,
60  			request.getContentType(),
61  			request.getContentLength(),
62  			request.getInputStream(),
63  			strSaveDirectory,
64  			intMaxReadBytes);
65  	}
66  
67  	/***
68  	 * @deprecated Replaced by ServletMultipartRequest(ServletRequest, int, boolean, String)
69  	 */
70  	public ServletMultipartRequest(HttpServletRequest request, int intMaxReadBytes) throws IllegalArgumentException, IOException
71  	{
72   	    super(null,
73  			request.getContentType(),
74  			request.getContentLength(),
75  			request.getInputStream(),
76  			intMaxReadBytes);
77  	}
78  
79  	/***
80  	 * Standard Constructor
81  	 *
82  	 * @param request				The ServletRequest will be used to initialise the MultipartRequest super class.
83  	 * @param strSaveDirectory		The temporary directory to save the file from where they can then be moved to wherever by the
84  	 * 								calling process.  <b>If you specify <u>null</u> for this parameter, then any files uploaded
85  	 *								will be silently ignored.</B>
86  	 * @param intMaxReadBytes		Overrides the MAX_BYTES_READ value, to allow arbitrarily long files.
87  	 * @param encoding              Sets the encoding to use. If null, ISO-8859-1 will be used.
88  	 *
89  	 * @exception IllegalArgumentException 	If the request.getContentType() does not contain a Content-Type of "multipart/form-data" or the boundary is not found.
90  	 * @exception IOException				If the request.getContentLength() is higher than MAX_READ_BYTES or strSaveDirectory is invalid or cannot be written to.
91  	 *
92  	 * @see MultipartRequest#MAX_READ_BYTES
93  	 */
94  	public ServletMultipartRequest(ServletRequest request,
95  								    String strSaveDirectory,
96  									int intMaxReadBytes,
97  									String encoding) throws IllegalArgumentException, IOException
98  	{
99   	    super(null, //debug
100 			request.getContentType(),
101 			request.getContentLength(),
102 			request.getInputStream(),
103 			strSaveDirectory,
104 			intMaxReadBytes,
105 			MultipartRequest.ABORT_IF_MAX_BYES_EXCEEDED,
106 			encoding);
107 	}
108 
109 	/***
110 	 * Memory Constructor
111 	 *
112 	 * @param request				The ServletRequest will be used to initialise the MultipartRequest super class.
113 	 * @param intMaxReadBytes		Overrides the MA_BYTES_READ value, to allow arbitrarily long files.
114 	 * @param encoding              Sets the encoding to use. If null, ISO-8859-1 will be used.
115 	 *
116 	 * @exception IllegalArgumentException 	If the request.getContentType() does not contain a Content-Type of "multipart/form-data" or the boundary is not found.
117 	 * @exception IOException				If the request.getContentLength() is higher than MAX_READ_BYTES or strSaveDirectory is invalid or cannot be written to.
118 	 *
119 	 * @see MultipartRequest#MAX_READ_BYTES
120 	 */
121 	public ServletMultipartRequest(ServletRequest request,
122 								int intMaxReadBytes,
123 								String encoding) throws IllegalArgumentException, IOException
124 	{
125  	    super(null, //debug
126 			request.getContentType(),
127 			request.getContentLength(),
128 			request.getInputStream(),
129 			intMaxReadBytes,
130 			MultipartRequest.ABORT_IF_MAX_BYES_EXCEEDED,
131 			encoding);
132 	}
133 
134 	/***
135 	 * Standard Constructor
136 	 *
137 	 * @param request				The ServletRequest will be used to initialise the MultipartRequest super class.
138 	 * @param strSaveDirectory		The temporary directory to save the file from where they can then be moved to wherever by the
139 	 * 								calling process.  <b>If you specify <u>null</u> for this parameter, then any files uploaded
140 	 *								will be silently ignored.</B>
141 	 * @param intMaxReadBytes		Overrides the MAX_BYTES_READ value, to allow arbitrarily long files.
142 	 * @param maxBytesExceededMode	This controls how the parser will process a request which is in excess of the intMaxReadBytes
143 	 * 								parameter.  The possible modes are:
144 	 *                              <ul>
145 	 *                              <li>MultipartRequest.ABORT_IF_MAX_BYES_EXCEEDED - The parser will throw a MaxBytesReadException</li>
146 	 *                              <li>MultipartRequest.IGNORE_FILES_IF_MAX_BYES_EXCEEDED - All parameters will be processed, but any file
147 	 *                              content will be discarded.  <b><u>WARNING: There is still potential for a Denial-of-Service.  For instance, an attacker can send
148 	 *                              many megabytes of non-file form data.</u></b></li>
149 	 * 								<ul>
150 	 * @param encoding              Sets the encoding to use. If null, ISO-8859-1 will be used.
151 	 *
152 	 * @exception IllegalArgumentException 	If the request.getContentType() does not contain a Content-Type of "multipart/form-data" or the boundary is not found.
153 	 * @exception IOException				If the request.getContentLength() is higher than MAX_READ_BYTES or strSaveDirectory is invalid or cannot be written to.
154 	 *
155 	 * @see MultipartRequest#MAX_READ_BYTES
156 	 */
157 	public ServletMultipartRequest(ServletRequest request,
158 								    String strSaveDirectory,
159 									int intMaxReadBytes,
160 									int maxBytesExceededMode,
161 									String encoding) throws IllegalArgumentException, IOException
162 	{
163  	    super(null, //debug
164 			request.getContentType(),
165 			request.getContentLength(),
166 			request.getInputStream(),
167 			strSaveDirectory,
168 			intMaxReadBytes,
169 			maxBytesExceededMode,
170 			encoding);
171 	}
172 
173 	/***
174 	 * Memory Constructor
175 	 *
176 	 * @param request				The ServletRequest will be used to initialise the MultipartRequest super class.
177 	 * @param intMaxReadBytes		Overrides the MA_BYTES_READ value, to allow arbitrarily long files.
178 	 * @param maxBytesExceededMode	This controls how the parser will process a request which is in excess of the intMaxReadBytes
179 	 * 								parameter.  The possible modes are:
180 	 *                              <ul>
181 	 *                              <li>MultipartRequest.ABORT_IF_MAX_BYES_EXCEEDED - The parser will throw a MaxBytesReadException</li>
182 	 *                              <li>MultipartRequest.IGNORE_FILES_IF_MAX_BYES_EXCEEDED - All parameters will be processed, but any file
183 	 *                              content will be discarded.  <b><u>WARNING: There is still potential for a Denial-of-Service.  For instance, an attacker can send
184 	 *                              many megabytes of non-file form data.</u></b></li>
185 	 * 								<ul>
186 	 * @param encoding              Sets the encoding to use. If null, ISO-8859-1 will be used.
187 	 *
188 	 * @exception IllegalArgumentException 	If the request.getContentType() does not contain a Content-Type of "multipart/form-data" or the boundary is not found.
189 	 * @exception IOException				If the request.getContentLength() is higher than MAX_READ_BYTES or strSaveDirectory is invalid or cannot be written to.
190 	 *
191 	 * @see MultipartRequest#MAX_READ_BYTES
192 	 */
193 	public ServletMultipartRequest(ServletRequest request,
194 								int intMaxReadBytes,
195 								int maxBytesExceededMode,
196 								String encoding) throws IllegalArgumentException, IOException
197 	{
198  	    super(null, //debug
199 			request.getContentType(),
200 			request.getContentLength(),
201 			request.getInputStream(),
202 			intMaxReadBytes,
203 			maxBytesExceededMode,
204 			encoding);
205 	}
206 }