01: /*
02: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: * $Id: FileUploadRegexp.java 3634 2007-01-08 21:42:24Z gbevin $
07: */
08: package com.uwyn.rife.engine.testelements.submission;
09:
10: import java.util.ArrayList;
11:
12: import com.uwyn.rife.engine.Element;
13: import com.uwyn.rife.engine.exceptions.EngineException;
14: import com.uwyn.rife.tools.FileUtils;
15: import com.uwyn.rife.tools.SortListComparables;
16: import com.uwyn.rife.tools.exceptions.FileUtilsErrorException;
17:
18: public class FileUploadRegexp extends Element {
19: public void processElement() {
20: if (hasSubmission("upload")) {
21: try {
22: SortListComparables sort = new SortListComparables();
23: ArrayList<String> files = new ArrayList<String>(
24: getUploadedFileNames());
25: sort.sort(files);
26: for (String file : files) {
27: print(FileUtils.readString(getUploadedFile(file)
28: .getFile()));
29: print(",");
30: }
31: print("\n");
32:
33: files = new ArrayList<String>(
34: getUploadedFileNames(".*doc.*"));
35: sort.sort(files);
36: for (String file : files) {
37: print(FileUtils.readString(getUploadedFile(file)
38: .getFile()));
39: print(",");
40: }
41: } catch (FileUtilsErrorException e) {
42: throw new EngineException(e);
43: }
44: return;
45: }
46:
47: print("<html><body>\n");
48: print("<form action=\""
49: + getSubmissionFormUrl()
50: + "\" method=\"post\" enctype=\"multipart/form-data\">\n");
51: print(getSubmissionFormParameters("upload") + "\n");
52: print("<input name=\"somefile\" type=\"file\">\n");
53: print("<input name=\"yourdoc1\" type=\"file\">\n");
54: print("<input name=\"hisdoc1\" type=\"file\">\n");
55: print("<input name=\"thisdoc2\" type=\"file\">\n");
56: print("<input type=\"submit\">\n");
57: print("</form>\n");
58: print("</body></html>\n");
59: }
60: }
|