Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
PortletMultipartDecoderFilter |
|
| 1.5;1.5 |
1 | // Copyright 2006 The Apache Software Foundation |
|
2 | // |
|
3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
|
4 | // you may not use this file except in compliance with the License. |
|
5 | // You may obtain a copy of the License at |
|
6 | // |
|
7 | // http://www.apache.org/licenses/LICENSE-2.0 |
|
8 | // |
|
9 | // Unless required by applicable law or agreed to in writing, software |
|
10 | // distributed under the License is distributed on an "AS IS" BASIS, |
|
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
12 | // See the License for the specific language governing permissions and |
|
13 | // limitations under the License. |
|
14 | package org.apache.tapestry.portlet.multipart; |
|
15 | ||
16 | import java.io.IOException; |
|
17 | ||
18 | import javax.portlet.ActionRequest; |
|
19 | import javax.portlet.ActionResponse; |
|
20 | import javax.portlet.PortletException; |
|
21 | ||
22 | import org.apache.tapestry.portlet.ActionRequestServicer; |
|
23 | import org.apache.tapestry.portlet.ActionRequestServicerFilter; |
|
24 | ||
25 | /** |
|
26 | * @author Raphael Jean |
|
27 | */ |
|
28 | 0 | public class PortletMultipartDecoderFilter implements |
29 | ActionRequestServicerFilter |
|
30 | { |
|
31 | ||
32 | private PortletMultipartDecoder _decoder; |
|
33 | ||
34 | public void service(ActionRequest request, ActionResponse response, |
|
35 | ActionRequestServicer servicer) |
|
36 | throws IOException, PortletException |
|
37 | { |
|
38 | 0 | String contentType = request.getContentType(); |
39 | ||
40 | // contentType is occasionally null in testing. The browser tacks on |
|
41 | // additional |
|
42 | // information onto the contentType to indicate where the boundaries are |
|
43 | // in |
|
44 | // the stream. |
|
45 | ||
46 | 0 | boolean encoded = contentType != null |
47 | && contentType.startsWith("multipart/form-data"); |
|
48 | ||
49 | try |
|
50 | { |
|
51 | 0 | ActionRequest newRequest = encoded ? _decoder.decode(request) |
52 | : request; |
|
53 | ||
54 | 0 | servicer.service(newRequest, response); |
55 | } |
|
56 | finally |
|
57 | { |
|
58 | 0 | if (encoded) _decoder.cleanup(); |
59 | } |
|
60 | 0 | } |
61 | ||
62 | public void setDecoder(PortletMultipartDecoder decoder) |
|
63 | { |
|
64 | 0 | this._decoder = decoder; |
65 | 0 | } |
66 | ||
67 | } |