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: FileUpload.java 3634 2007-01-08 21:42:24Z gbevin $
07: */
08: package com.uwyn.rife.engine.testelements.submission;
09:
10: import com.uwyn.rife.engine.Element;
11: import com.uwyn.rife.engine.UploadedFile;
12: import com.uwyn.rife.engine.exceptions.EngineException;
13: import com.uwyn.rife.tools.FileUtils;
14: import com.uwyn.rife.tools.exceptions.FileUtilsErrorException;
15:
16: public class FileUpload extends Element {
17: public void processElement() {
18: if (hasSubmission("upload")) {
19: if (hasUploadedFile("doc1")) {
20: if (isFileEmpty("doc1")) {
21: if (getUploadedFile("doc1").wasSizeExceeded()) {
22: print("file 1 size exceeded");
23: } else {
24: print("empty file 1");
25: }
26: } else {
27: UploadedFile[] files = getUploadedFiles("doc1");
28: for (int i = 0; i < files.length; i++) {
29: try {
30: print(FileUtils.readString(files[i]
31: .getFile()));
32: } catch (FileUtilsErrorException e) {
33: throw new EngineException(e);
34: }
35:
36: if (i < files.length - 1) {
37: print(",");
38: }
39: }
40: }
41: } else {
42: print("no file 1");
43: }
44: print(";");
45: if (hasUploadedFile("doc2")) {
46: if (isFileEmpty("doc2")) {
47: if (getUploadedFile("doc2").wasSizeExceeded()) {
48: print("file 2 size exceeded");
49: } else {
50: print("empty file 2");
51: }
52: } else {
53: UploadedFile[] files = getUploadedFiles("doc2");
54: for (int i = 0; i < files.length; i++) {
55: try {
56: print(FileUtils.readString(files[i]
57: .getFile()));
58: } catch (FileUtilsErrorException e) {
59: throw new EngineException(e);
60: }
61:
62: if (i < files.length - 1) {
63: print(",");
64: }
65: }
66: }
67: } else {
68: print("no file 2");
69: }
70: print(";");
71: print(getParameter("purpose"));
72: return;
73: }
74:
75: print("<html><body>\n");
76: print("<form action=\""
77: + getSubmissionFormUrl()
78: + "\" method=\"post\" enctype=\"multipart/form-data\">\n");
79: print(getSubmissionFormParameters("upload") + "\n");
80: print("<input name=\"purpose\" type=\"text\">\n");
81: print("<input name=\"doc1\" type=\"file\">\n");
82: print("<input name=\"doc1\" type=\"file\">\n");
83: print("<input name=\"doc2\" type=\"file\">\n");
84: print("<input type=\"submit\">\n");
85: print("</form>\n");
86: print("</body></html>\n");
87: }
88: }
|