|
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 |
12
| public UploadPart(FileItem fileItem)
|
|
38 |
| { |
|
39 |
12
| Defense.notNull(fileItem, "fileItem");
|
|
40 |
| |
|
41 |
12
| _fileItem = fileItem;
|
|
42 |
| } |
|
43 |
| |
|
44 |
9
| public String getContentType()
|
|
45 |
| { |
|
46 |
9
| return _fileItem.getContentType();
|
|
47 |
| } |
|
48 |
| |
|
49 |
| |
|
50 |
| |
|
51 |
| |
|
52 |
18
| public String getFileName()
|
|
53 |
| { |
|
54 |
18
| File file = new File(this.getFilePath());
|
|
55 |
| |
|
56 |
18
| return file.getName();
|
|
57 |
| } |
|
58 |
| |
|
59 |
| |
|
60 |
| |
|
61 |
| |
|
62 |
| |
|
63 |
36
| public String getFilePath()
|
|
64 |
| { |
|
65 |
36
| return _fileItem.getName();
|
|
66 |
| } |
|
67 |
| |
|
68 |
9
| public InputStream getStream()
|
|
69 |
| { |
|
70 |
9
| try
|
|
71 |
| { |
|
72 |
9
| 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 |
12
| public void cleanup()
|
|
87 |
| { |
|
88 |
12
| _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 |
9
| public long getSize()
|
|
116 |
| { |
|
117 |
9
| return _fileItem.getSize();
|
|
118 |
| } |
|
119 |
| |
|
120 |
| |
|
121 |
| |
|
122 |
| |
|
123 |
9
| public boolean isInMemory()
|
|
124 |
| { |
|
125 |
9
| return _fileItem.isInMemory();
|
|
126 |
| } |
|
127 |
| |
|
128 |
| } |