1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
package org.apache.tapestry.portlet.multipart; |
15 | |
|
16 | |
import java.io.File; |
17 | |
import java.util.List; |
18 | |
import java.util.Map; |
19 | |
|
20 | |
import javax.portlet.ActionRequest; |
21 | |
|
22 | |
import org.apache.commons.fileupload.FileItemFactory; |
23 | |
import org.apache.commons.fileupload.FileUploadException; |
24 | |
import org.apache.commons.fileupload.disk.DiskFileItemFactory; |
25 | |
import org.apache.commons.fileupload.portlet.PortletFileUpload; |
26 | |
import org.apache.hivemind.ApplicationRuntimeException; |
27 | |
import org.apache.tapestry.multipart.AbstractMultipartDecoder; |
28 | |
import org.apache.tapestry.multipart.MultipartMessages; |
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | 0 | public class PortletMultipartDecoderImpl extends AbstractMultipartDecoder |
34 | |
implements PortletMultipartDecoder |
35 | |
{ |
36 | |
|
37 | |
public ActionRequest decode(ActionRequest request) |
38 | |
{ |
39 | 0 | _encoding = request.getCharacterEncoding(); |
40 | |
|
41 | 0 | PortletFileUpload upload = createFileUpload(); |
42 | |
|
43 | |
try |
44 | |
{ |
45 | 0 | List fileItems = upload.parseRequest(request); |
46 | |
|
47 | 0 | processFileItems(fileItems); |
48 | |
} |
49 | 0 | catch (FileUploadException ex) |
50 | |
{ |
51 | 0 | throw new ApplicationRuntimeException(MultipartMessages |
52 | |
.unableToDecode(ex), ex); |
53 | 0 | } |
54 | |
|
55 | 0 | Map parameterMap = buildParameterMap(); |
56 | |
|
57 | 0 | return new UploadFormPortletParametersWrapper(request, parameterMap); |
58 | |
} |
59 | |
|
60 | |
private PortletFileUpload createFileUpload() |
61 | |
{ |
62 | 0 | FileItemFactory factory = new DiskFileItemFactory(_thresholdSize, |
63 | |
new File(_repositoryPath)); |
64 | 0 | PortletFileUpload upload = new PortletFileUpload(factory); |
65 | |
|
66 | 0 | if (_encoding != null) upload.setHeaderEncoding(_encoding); |
67 | |
|
68 | 0 | return upload; |
69 | |
} |
70 | |
|
71 | |
} |