Source Code Cross Referenced for CommonsMultipartResolver.java in  » J2EE » spring-framework-2.0.6 » org » springframework » web » multipart » commons » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » spring framework 2.0.6 » org.springframework.web.multipart.commons 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2002-2005 the original author or authors.
003:         * 
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         * 
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         * 
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:
017:        package org.springframework.web.multipart.commons;
018:
019:        import java.util.List;
020:
021:        import javax.servlet.ServletContext;
022:        import javax.servlet.http.HttpServletRequest;
023:
024:        import org.apache.commons.fileupload.FileItemFactory;
025:        import org.apache.commons.fileupload.FileUpload;
026:        import org.apache.commons.fileupload.FileUploadBase;
027:        import org.apache.commons.fileupload.FileUploadException;
028:        import org.apache.commons.fileupload.servlet.ServletFileUpload;
029:        import org.apache.commons.fileupload.servlet.ServletRequestContext;
030:
031:        import org.springframework.web.context.ServletContextAware;
032:        import org.springframework.web.multipart.MaxUploadSizeExceededException;
033:        import org.springframework.web.multipart.MultipartException;
034:        import org.springframework.web.multipart.MultipartHttpServletRequest;
035:        import org.springframework.web.multipart.MultipartResolver;
036:        import org.springframework.web.multipart.support.DefaultMultipartHttpServletRequest;
037:        import org.springframework.web.util.WebUtils;
038:
039:        /**
040:         * Servlet-based MultipartResolver implementation for
041:         * <a href="http://jakarta.apache.org/commons/fileupload">Jakarta Commons FileUpload</a>
042:         * 1.1 or higher.
043:         *
044:         * <p>Provides maxUploadSize, maxInMemorySize, and defaultEncoding settings as
045:         * bean properties (inherited from CommonsFileUploadSupport). See respective
046:         * ServletFileUpload / DiskFileItemFactory properties (sizeMax, sizeThreshold,
047:         * headerEncoding) for details in terms of defaults and accepted values.
048:         *
049:         * <p>Saves temporary files to the servlet container's temporary directory.
050:         * Needs to be initialized <i>either</i> by an application context <i>or</i>
051:         * via the constructor that takes a ServletContext (for standalone usage).
052:         *
053:         * <p><b>NOTE:</b> As of Spring 2.0, this multipart resolver requires
054:         * Commons FileUpload 1.1 or higher. The implementation does not use
055:         * any deprecated FileUpload 1.0 API anymore, to be compatible with future
056:         * Commons FileUpload releases.
057:         *
058:         * @author Trevor D. Cook
059:         * @author Juergen Hoeller
060:         * @since 29.09.2003
061:         * @see #CommonsMultipartResolver(ServletContext)
062:         * @see CommonsMultipartFile
063:         * @see org.springframework.web.portlet.multipart.PortletMultipartResolver
064:         * @see org.apache.commons.fileupload.servlet.ServletFileUpload
065:         * @see org.apache.commons.fileupload.disk.DiskFileItemFactory
066:         */
067:        public class CommonsMultipartResolver extends CommonsFileUploadSupport
068:                implements  MultipartResolver, ServletContextAware {
069:
070:            /**
071:             * Constructor for use as bean. Determines the servlet container's
072:             * temporary directory via the ServletContext passed in as through the
073:             * ServletContextAware interface (typically by a WebApplicationContext).
074:             * @see #setServletContext
075:             * @see org.springframework.web.context.ServletContextAware
076:             * @see org.springframework.web.context.WebApplicationContext
077:             */
078:            public CommonsMultipartResolver() {
079:                super ();
080:            }
081:
082:            /**
083:             * Constructor for standalone usage. Determines the servlet container's
084:             * temporary directory via the given ServletContext.
085:             * @param servletContext the ServletContext to use
086:             */
087:            public CommonsMultipartResolver(ServletContext servletContext) {
088:                this ();
089:                setServletContext(servletContext);
090:            }
091:
092:            /**
093:             * Initialize the underlying <code>org.apache.commons.fileupload.servlet.ServletFileUpload</code>
094:             * instance. Can be overridden to use a custom subclass, e.g. for testing purposes.
095:             * @param fileItemFactory the Commons FileItemFactory to use
096:             * @return the new ServletFileUpload instance
097:             */
098:            protected FileUpload newFileUpload(FileItemFactory fileItemFactory) {
099:                return new ServletFileUpload(fileItemFactory);
100:            }
101:
102:            public void setServletContext(ServletContext servletContext) {
103:                if (!isUploadTempDirSpecified()) {
104:                    getFileItemFactory().setRepository(
105:                            WebUtils.getTempDir(servletContext));
106:                }
107:            }
108:
109:            public boolean isMultipart(HttpServletRequest request) {
110:                return ServletFileUpload
111:                        .isMultipartContent(new ServletRequestContext(request));
112:            }
113:
114:            public MultipartHttpServletRequest resolveMultipart(
115:                    HttpServletRequest request) throws MultipartException {
116:                String encoding = determineEncoding(request);
117:                FileUpload fileUpload = prepareFileUpload(encoding);
118:                try {
119:                    List fileItems = ((ServletFileUpload) fileUpload)
120:                            .parseRequest(request);
121:                    MultipartParsingResult parsingResult = parseFileItems(
122:                            fileItems, encoding);
123:                    return new DefaultMultipartHttpServletRequest(request,
124:                            parsingResult.getMultipartFiles(), parsingResult
125:                                    .getMultipartParameters());
126:                } catch (FileUploadBase.SizeLimitExceededException ex) {
127:                    throw new MaxUploadSizeExceededException(fileUpload
128:                            .getSizeMax(), ex);
129:                } catch (FileUploadException ex) {
130:                    throw new MultipartException(
131:                            "Could not parse multipart servlet request", ex);
132:                }
133:            }
134:
135:            /**
136:             * Determine the encoding for the given request.
137:             * Can be overridden in subclasses.
138:             * <p>The default implementation checks the request encoding,
139:             * falling back to the default encoding specified for this resolver.
140:             * @param request current HTTP request
141:             * @return the encoding for the request (never <code>null</code>)
142:             * @see javax.servlet.ServletRequest#getCharacterEncoding
143:             * @see #setDefaultEncoding
144:             */
145:            protected String determineEncoding(HttpServletRequest request) {
146:                String encoding = request.getCharacterEncoding();
147:                if (encoding == null) {
148:                    encoding = getDefaultEncoding();
149:                }
150:                return encoding;
151:            }
152:
153:            public void cleanupMultipart(MultipartHttpServletRequest request) {
154:                cleanupFileItems(request.getFileMap().values());
155:            }
156:
157:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.