1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| package org.apache.tapestry.multipart; |
16 |
| |
17 |
| import java.io.File; |
18 |
| import java.io.IOException; |
19 |
| import java.io.InputStream; |
20 |
| |
21 |
| import org.apache.commons.fileupload.FileItem; |
22 |
| import org.apache.hivemind.ApplicationRuntimeException; |
23 |
| import org.apache.hivemind.util.Defense; |
24 |
| import org.apache.tapestry.Tapestry; |
25 |
| import org.apache.tapestry.request.IUploadFile; |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
| public class UploadPart extends Object implements IUploadFile |
34 |
| { |
35 |
| private FileItem _fileItem; |
36 |
| |
37 |
4
| public UploadPart(FileItem fileItem)
|
38 |
| { |
39 |
4
| Defense.notNull(fileItem, "fileItem");
|
40 |
| |
41 |
4
| _fileItem = fileItem;
|
42 |
| } |
43 |
| |
44 |
3
| public String getContentType()
|
45 |
| { |
46 |
3
| return _fileItem.getContentType();
|
47 |
| } |
48 |
| |
49 |
| |
50 |
| |
51 |
| |
52 |
6
| public String getFileName()
|
53 |
| { |
54 |
6
| File file = new File(this.getFilePath());
|
55 |
| |
56 |
6
| return file.getName();
|
57 |
| } |
58 |
| |
59 |
| |
60 |
| |
61 |
| |
62 |
| |
63 |
12
| public String getFilePath()
|
64 |
| { |
65 |
12
| return _fileItem.getName();
|
66 |
| } |
67 |
| |
68 |
3
| public InputStream getStream()
|
69 |
| { |
70 |
3
| try
|
71 |
| { |
72 |
3
| return _fileItem.getInputStream();
|
73 |
| } |
74 |
| catch (IOException ex) |
75 |
| { |
76 |
0
| throw new ApplicationRuntimeException(MultipartMessages.unableToOpenContentFile(
|
77 |
| this, |
78 |
| ex), ex); |
79 |
| } |
80 |
| } |
81 |
| |
82 |
| |
83 |
| |
84 |
| |
85 |
| |
86 |
4
| public void cleanup()
|
87 |
| { |
88 |
4
| _fileItem.delete();
|
89 |
| } |
90 |
| |
91 |
| |
92 |
| |
93 |
| |
94 |
| |
95 |
| |
96 |
| |
97 |
0
| public void write(File file)
|
98 |
| { |
99 |
0
| try
|
100 |
| { |
101 |
0
| _fileItem.write(file);
|
102 |
| } |
103 |
| catch (Exception ex) |
104 |
| { |
105 |
0
| throw new ApplicationRuntimeException(Tapestry.format(
|
106 |
| "UploadPart.write-failure", |
107 |
| file, |
108 |
| ex.getMessage()), ex); |
109 |
| } |
110 |
| } |
111 |
| |
112 |
| |
113 |
| |
114 |
| |
115 |
3
| public long getSize()
|
116 |
| { |
117 |
3
| return _fileItem.getSize();
|
118 |
| } |
119 |
| |
120 |
| |
121 |
| |
122 |
| |
123 |
3
| public boolean isInMemory()
|
124 |
| { |
125 |
3
| return _fileItem.isInMemory();
|
126 |
| } |
127 |
| |
128 |
| } |