1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47 package org.melati.template;
48
49 import java.io.InputStream;
50 import java.io.IOException;
51 import java.util.Hashtable;
52 import java.util.Enumeration;
53 import java.util.Map;
54
55 import javax.servlet.http.HttpSession;
56 import org.melati.Melati;
57 import org.melati.servlet.MultipartFormField;
58 import org.melati.servlet.MultipartFormDataDecoder;
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73 public class MultipartTemplateContext implements ServletTemplateContext {
74 ServletTemplateContext peer;
75 Hashtable<String,MultipartFormField> fields;
76 Melati melati;
77
78
79
80
81
82
83 public MultipartTemplateContext(Melati melati, ServletTemplateContext context)
84 throws IOException {
85 peer = context;
86 this.melati = melati;
87 try {
88 InputStream in = melati.getRequest().getInputStream();
89 MultipartFormDataDecoder decoder=
90 new MultipartFormDataDecoder(
91 melati,
92 in,
93 melati.getRequest().getContentType(),
94 melati.getConfig().getFormDataAdaptorFactory());
95 fields = decoder.parseData();
96 }
97 catch (IOException e) {
98 fields = new Hashtable<String,MultipartFormField>();
99 throw e;
100 }
101 }
102
103
104
105
106
107
108
109 public MultipartTemplateContext(Melati melati, ServletTemplateContext context,
110 int maxSize)
111 throws IOException {
112 peer = context;
113 this.melati = melati;
114 try {
115 InputStream in = melati.getRequest().getInputStream();
116 MultipartFormDataDecoder decoder=
117 new MultipartFormDataDecoder(melati,
118 in,
119 melati.getRequest().getContentType(),
120 melati.getConfig().getFormDataAdaptorFactory(),
121 maxSize);
122 fields = decoder.parseData();
123 }
124 catch (IOException e) {
125 fields = new Hashtable<String,MultipartFormField>();
126 throw e;
127 }
128 }
129
130
131
132
133
134 public Object put(String s, Object o) {
135 return peer.put(s,o);
136 }
137
138
139
140
141
142 public String getFormField(String s) {
143 MultipartFormField field = (MultipartFormField)fields.get(s);
144 if (field == null)
145 return peer.getFormField(s);
146 return field.getDataString(melati.getResponse().getCharacterEncoding());
147 }
148
149
150
151
152
153 public MultipartFormField getMultipartFormField(String s) {
154 return (MultipartFormField)fields.get(s);
155 }
156
157
158
159
160 public Enumeration<String> getFieldNames() {
161 return fields.keys();
162 }
163
164
165
166
167
168 public Object get(String s) {
169 return peer.get(s);
170 }
171
172
173
174
175
176 public HttpSession getSession() {
177 return peer.getSession();
178 }
179
180
181
182
183
184 public Object getContext() {
185 return peer.getContext();
186 }
187
188
189
190
191
192 public void setPassbackExceptionHandling() {
193 peer.setPassbackExceptionHandling();
194 }
195
196
197
198
199
200 public void setPropagateExceptionHandling() {
201 peer.setPropagateExceptionHandling();
202 }
203
204 @Override
205 public void putAll(Map<String, ?> m) {
206 peer.putAll(m);
207 }
208 }
209
210
211
212
213
214