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: FileUploadInjection.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 FileUploadInjection extends Element {
17: private UploadedFile doc1;
18:
19: public void setDoc1(UploadedFile doc1) {
20: this .doc1 = doc1;
21: }
22:
23: public void processElement() {
24: if (hasSubmission("upload")) {
25: if (doc1 != null) {
26: try {
27: print(FileUtils.readString(doc1.getFile()));
28: } catch (FileUtilsErrorException e) {
29: throw new EngineException(e);
30: }
31: } else {
32: print("no file 1");
33: }
34: print(";");
35: print(getParameter("purpose"));
36: return;
37: }
38:
39: print("<html><body>\n");
40: print("<form action=\""
41: + getSubmissionFormUrl()
42: + "\" method=\"post\" enctype=\"multipart/form-data\">\n");
43: print(getSubmissionFormParameters("upload") + "\n");
44: print("<input name=\"purpose\" type=\"text\">\n");
45: print("<input name=\"doc1\" type=\"file\">\n");
46: print("<input name=\"doc1\" type=\"file\">\n");
47: print("<input name=\"doc2\" type=\"file\">\n");
48: print("<input type=\"submit\">\n");
49: print("</form>\n");
50: print("</body></html>\n");
51: }
52: }
|