01: /*
02: * File upload filter
03: * Copyright (C) 2004 Rick Knowles
04: *
05: * This program is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Library General Public License
07: * Version 2 as published by the Free Software Foundation.
08: *
09: * This program is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: * GNU General Public License Version 2 for more details.
13: *
14: * You should have received a copy of the GNU Library General Public License
15: * Version 2 along with this program; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17: */
18: package dinamica.upload;
19:
20: import java.io.IOException;
21: import javax.servlet.Filter;
22: import javax.servlet.FilterChain;
23: import javax.servlet.FilterConfig;
24: import javax.servlet.ServletException;
25: import javax.servlet.ServletRequest;
26: import javax.servlet.ServletResponse;
27:
28: /**
29: * Checks the content type, and wraps the request in a MultipartRequestWrapper if
30: * it's a multipart request.
31: *
32: * @author <a href="mailto:rick_knowles@hotmail.com">Rick Knowles</a>
33: * @version $Id: MultipartRequestFilter.java,v 1.1 2005/08/24 06:43:34 rickknowles Exp $
34: */
35: public class MultipartRequestFilter implements Filter {
36:
37: public void init(FilterConfig config) throws ServletException {
38: }
39:
40: public void destroy() {
41: }
42:
43: public void doFilter(ServletRequest request,
44: ServletResponse response, FilterChain chain)
45: throws IOException, ServletException {
46: String contentType = request.getContentType();
47: if ((contentType != null)
48: && contentType.startsWith("multipart/form-data")) {
49: try {
50: MultipartRequestWrapper req = new MultipartRequestWrapper(
51: request);
52: chain.doFilter(req, response);
53: } catch (OutOfMemoryError e) {
54: throw new ServletException(
55: "El servidor no tiene suficiente memoria para completar su solicitud.",
56: e);
57: }
58: } else {
59: chain.doFilter(request, response);
60: }
61: }
62: }
|