KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > web > portlet > multipart > PortletMultipartResolver


1 /*
2  * Copyright 2002-2007 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.web.portlet.multipart;
18
19 import javax.portlet.ActionRequest;
20
21 import org.springframework.web.multipart.MultipartException;
22
23 /**
24  * Portlet version of Spring's multipart resolution strategy for file uploads
25  * as defined in <a HREF="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a>.
26  *
27  * <p>Implementations are typically usable both within any application context
28  * and standalone.
29  *
30  * <p>There is one concrete implementation included in Spring:
31  * <ul>
32  * <li>{@link org.springframework.web.multipart.commons.CommonsMultipartResolver}
33  * for Jakarta Commons FileUpload
34  * </ul>
35  *
36  * <p>There is no default resolver implementation used for Spring
37  * {@link org.springframework.web.portlet.DispatcherPortlet DispatcherPortlets},
38  * as an application might choose to parse its multipart requests itself. To
39  * define an implementation, create a bean with the id
40  * {@link org.springframework.web.portlet.DispatcherPortlet#MULTIPART_RESOLVER_BEAN_NAME "portletMultipartResolver"}
41  * in a <code>DispatcherPortlet's</code> application context. Such a resolver
42  * gets applied to all requests handled by that <code>DispatcherPortlet</code>.
43  *
44  * <p>If a <code>DispatcherPortlet</code> detects a multipart request, it will
45  * resolve it via the configured
46  * {@link org.springframework.web.multipart.MultipartResolver} and pass on a
47  * wrapped Portlet {@link ActionRequest}.
48  * {@link org.springframework.web.portlet.mvc.Controller Controllers} can then
49  * cast their given request to the {@link MultipartActionRequest} interface,
50  * being able to access <code>MultipartFiles</code>. Note that this cast is
51  * only supported in case of an actual multipart request.
52  *
53  * <pre class="code"> public void handleActionRequest(ActionRequest request, ActionResponse response) {
54  * MultipartActionRequest multipartRequest = (MultipartActionRequest) request;
55  * MultipartFile multipartFile = multipartRequest.getFile("image");
56  * ...
57  * }</pre>
58  *
59  * Instead of direct access, command or form controllers can register a
60  * {@link org.springframework.web.multipart.support.ByteArrayMultipartFileEditor}
61  * or {@link org.springframework.web.multipart.support.StringMultipartFileEditor}
62  * with their data binder, to automatically apply multipart content to command
63  * bean properties.
64  *
65  * <p>Note: There is hardly ever a need to access the
66  * <code>MultipartResolver</code> itself from application code. It will simply
67  * do its work behind the scenes, making <code>MultipartActionRequests</code>
68  * available to controllers.
69  *
70  * @author Juergen Hoeller
71  * @since 2.0
72  * @see MultipartActionRequest
73  * @see org.springframework.web.multipart.MultipartFile
74  * @see CommonsPortletMultipartResolver
75  * @see org.springframework.web.multipart.support.ByteArrayMultipartFileEditor
76  * @see org.springframework.web.multipart.support.StringMultipartFileEditor
77  * @see org.springframework.web.portlet.DispatcherPortlet
78  */

79 public interface PortletMultipartResolver {
80
81     /**
82      * Determine if the given request contains multipart content.
83      * <p>Will typically check for content type
84      * "<code>multipart/form-data</code>", but the actually accepted requests
85      * might depend on the capabilities of the resolver implementation.
86      * @param request the portlet request to be evaluated
87      * @return whether the request contains multipart content
88      */

89     boolean isMultipart(ActionRequest request);
90
91     /**
92      * Parse the given portlet request into multipart files and parameters,
93      * and wrap the request inside a MultipartActionRequest object
94      * that provides access to file descriptors and makes contained
95      * parameters accessible via the standard PortletRequest methods.
96      * @param request the portlet request to wrap (must be of a multipart content type)
97      * @return the wrapped portlet request
98      * @throws org.springframework.web.multipart.MultipartException if the portlet request
99      * is not multipart, or if implementation-specific problems are encountered
100      * (such as exceeding file size limits)
101      * @see org.springframework.web.portlet.multipart.MultipartActionRequest#getFile
102      * @see org.springframework.web.portlet.multipart.MultipartActionRequest#getFileNames
103      * @see org.springframework.web.portlet.multipart.MultipartActionRequest#getFileMap
104      * @see javax.portlet.ActionRequest#getParameter
105      * @see javax.portlet.ActionRequest#getParameterNames
106      * @see javax.portlet.ActionRequest#getParameterMap
107      */

108     MultipartActionRequest resolveMultipart(ActionRequest request) throws MultipartException;
109
110     /**
111      * Cleanup any resources used for the multipart handling,
112      * such as storage for any uploaded file(s).
113      * @param request the request to cleanup resources for
114      */

115     void cleanupMultipart(MultipartActionRequest request);
116
117 }
118
Popular Tags