1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.cafesip.gwtcomp.examples.server;
20
21 import java.io.File;
22 import java.util.HashMap;
23 import java.util.Iterator;
24 import java.util.Map;
25
26 import javax.servlet.http.HttpServlet;
27 import javax.servlet.http.HttpServletRequest;
28 import javax.servlet.http.HttpServletResponse;
29
30 import org.cafesip.gwtcomp.server.FileUploadAction;
31 import org.cafesip.gwtcomp.server.FormResponse;
32
33
34
35
36
37 public class FileUploadActionSample implements FileUploadAction
38 {
39 private String name;
40
41 private String email;
42
43 private String address;
44
45 private String city;
46
47 private String county;
48
49 private String caption;
50
51 private String description;
52
53 private HashMap<String, File> files;
54
55
56
57
58
59 public FormResponse onSubmit(HttpServlet servlet, HttpServletRequest request)
60 {
61 System.out.println("The user entered the following values: ");
62 System.out.println("Name: " + name);
63 System.out.println("Email: " + email);
64 System.out.println("Address: " + address);
65 System.out.println("City: " + city);
66 System.out.println("County: " + county);
67 System.out.println("Caption: " + caption);
68 System.out.println("Description: " + description);
69
70 System.out.println("Uploaded File(s):");
71 Iterator<Map.Entry<String, File>> i = files.entrySet().iterator();
72 while (i.hasNext())
73 {
74 Map.Entry<String, File> entry = i.next();
75 System.out.println(entry.getKey() + ": " + entry.getValue());
76 }
77
78 return validate();
79 }
80
81 private FormResponse validate()
82 {
83 if ((name == null) || (name.trim().length() == 0))
84 {
85 return new FormResponse(HttpServletResponse.SC_BAD_REQUEST,
86 "You have not entered your name", true);
87 }
88
89 if ((email == null) || (email.trim().length() == 0))
90 {
91 return new FormResponse(HttpServletResponse.SC_BAD_REQUEST,
92 "You have not entered your email address", true);
93 }
94
95 if ((caption == null) || (caption.trim().length() == 0))
96 {
97 return new FormResponse(HttpServletResponse.SC_BAD_REQUEST,
98 "You have not entered the caption", true);
99 }
100
101 if ((files == null) || (files.size() == 0))
102 {
103 return new FormResponse(HttpServletResponse.SC_BAD_REQUEST,
104 "You have not provided a file to upload", true);
105 }
106
107 return new FormResponse(HttpServletResponse.SC_OK, "OK", true);
108 }
109
110
111
112
113 public void setFileList(HashMap<String, File> files)
114 {
115 this.files = files;
116 }
117
118
119
120
121 public String getAddress()
122 {
123 return address;
124 }
125
126
127
128
129
130 public void setAddress(String address)
131 {
132 this.address = address;
133 }
134
135
136
137
138 public String getCaption()
139 {
140 return caption;
141 }
142
143
144
145
146
147 public void setCaption(String caption)
148 {
149 this.caption = caption;
150 }
151
152
153
154
155 public String getCity()
156 {
157 return city;
158 }
159
160
161
162
163
164 public void setCity(String city)
165 {
166 this.city = city;
167 }
168
169
170
171
172 public String getCounty()
173 {
174 return county;
175 }
176
177
178
179
180
181 public void setCounty(String county)
182 {
183 this.county = county;
184 }
185
186
187
188
189 public String getDescription()
190 {
191 return description;
192 }
193
194
195
196
197
198 public void setDescription(String description)
199 {
200 this.description = description;
201 }
202
203
204
205
206 public String getEmail()
207 {
208 return email;
209 }
210
211
212
213
214
215 public void setEmail(String email)
216 {
217 this.email = email;
218 }
219
220
221
222
223 public String getName()
224 {
225 return name;
226 }
227
228
229
230
231
232 public void setName(String name)
233 {
234 this.name = name;
235 }
236
237 }