001: /*
002: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
003: * Distributed under the terms of either:
004: * - the common development and distribution license (CDDL), v1.0; or
005: * - the GNU Lesser General Public License, v2.1 or later
006: * $Id: FillBeanNormal.java 3693 2007-03-14 10:55:56Z gbevin $
007: */
008: package com.uwyn.rife.engine.testelements.submission;
009:
010: import com.uwyn.rife.engine.Element;
011: import com.uwyn.rife.engine.exceptions.EngineException;
012: import com.uwyn.rife.resources.ResourceFinderClasspath;
013: import com.uwyn.rife.resources.exceptions.ResourceFinderErrorException;
014: import com.uwyn.rife.site.ValidationError;
015: import com.uwyn.rife.tools.FileUtils;
016: import com.uwyn.rife.tools.InnerClassException;
017: import com.uwyn.rife.tools.InputStreamUser;
018: import com.uwyn.rife.tools.exceptions.FileUtilsErrorException;
019: import java.io.InputStream;
020: import java.io.StringBufferInputStream;
021: import java.util.Arrays;
022: import java.util.Set;
023:
024: public class FillBeanNormal extends Element {
025: public void processElement() {
026: print("<form name=\"submissionform\" action=\""
027: + getSubmissionFormUrl()
028: + "\" method=\"post\" enctype=\"multipart/form-data\">");
029: print(getSubmissionFormParameters("bean"));
030: print("<input type=\"text\" name=\"enum\">");
031: print("<input type=\"text\" name=\"string\">");
032: print("<input type=\"text\" name=\"boolean\">");
033: print("<input type=\"text\" name=\"string\">");
034: print("<input type=\"text\" name=\"stringbuffer\">");
035: print("<input type=\"text\" name=\"int\">");
036: print("<input type=\"text\" name=\"integer\">");
037: print("<input type=\"text\" name=\"char\">");
038: print("<input type=\"text\" name=\"character\">");
039: print("<input type=\"text\" name=\"boolean\">");
040: print("<input type=\"text\" name=\"booleanObject\">");
041: print("<input type=\"text\" name=\"byte\">");
042: print("<input type=\"text\" name=\"byteObject\">");
043: print("<input type=\"text\" name=\"double\">");
044: print("<input type=\"text\" name=\"doubleObject\">");
045: print("<input type=\"text\" name=\"float\">");
046: print("<input type=\"text\" name=\"floatObject\">");
047: print("<input type=\"text\" name=\"long\">");
048: print("<input type=\"text\" name=\"longObject\">");
049: print("<input type=\"text\" name=\"short\">");
050: print("<input type=\"text\" name=\"shortObject\">");
051: print("<input type=\"file\" name=\"stringFile\"/>");
052: print("<input type=\"file\" name=\"bytesFile\"/>");
053: print("<input type=\"file\" name=\"streamFile\"/>");
054: print("</form");
055: }
056:
057: public void doBean() {
058: BeanImpl bean = new BeanImpl();
059:
060: bean.setString("string");
061: bean.setStringbuffer(new StringBuffer("stringbuffer"));
062: bean.setInt(999);
063: bean.setInteger(new Integer(111));
064: bean.setChar('a');
065: bean.setCharacter(new Character('b'));
066: bean.setBoolean(false);
067: bean.setBooleanObject(new Boolean(true));
068: bean.setByte((byte) 22);
069: bean.setByteObject(new Byte((byte) 33));
070: bean.setDouble(123.45d);
071: bean.setDoubleObject(new Double(234.56d));
072: bean.setFloat(321.54f);
073: bean.setFloatObject(new Float(432.65f));
074: bean.setLong(44L);
075: bean.setLongObject(new Long(55L));
076: bean.setShort((short) 66);
077: bean.setShortObject(new Short((short) 77));
078: bean.setStringFile("stringFile");
079: bean.setBytesFile(new byte[] { 1, 2, 3 });
080: bean.setStreamFile(new StringBufferInputStream("streamFile"));
081:
082: fillSubmissionBean(bean);
083:
084: boolean notnumeric_int = false;
085: boolean notnumeric_double = false;
086: boolean notnumeric_longobject = false;
087:
088: Set<ValidationError> errors = bean.getValidationErrors();
089: for (ValidationError error : errors) {
090: print(error.getIdentifier() + " : " + error.getSubject()
091: + "\n");
092: }
093: print(bean.getEnum() + "," + bean.getString() + ","
094: + bean.getStringbuffer() + "," + bean.getInt() + ","
095: + bean.getInteger() + "," + bean.getChar() + ","
096: + bean.getCharacter() + "," + bean.isBoolean() + ","
097: + bean.getBooleanObject() + "," + bean.getByte() + ","
098: + bean.getByteObject() + "," + bean.getDouble() + ","
099: + bean.getDoubleObject() + "," + bean.getFloat() + ","
100: + bean.getFloatObject() + "," + bean.getLong() + ","
101: + bean.getLongObject() + "," + bean.getShort() + ","
102: + bean.getShortObject());
103: print("," + bean.getStringFile());
104:
105: try {
106: byte[] image_bytes = ResourceFinderClasspath.getInstance()
107: .useStream("uwyn.png", new InputStreamUser() {
108: public Object useInputStream(InputStream stream)
109: throws InnerClassException {
110: try {
111: return FileUtils.readBytes(stream);
112: } catch (FileUtilsErrorException e) {
113: throwException(e);
114: }
115:
116: return null;
117: }
118: });
119:
120: if (null == bean.getBytesFile()) {
121: print(",null");
122: } else {
123: print(","
124: + Arrays.equals(image_bytes, bean
125: .getBytesFile()));
126: }
127: print(","
128: + bean.getConstrainedProperty("bytesFile")
129: .getName());
130:
131: if (null == bean.getStreamFile()) {
132: print(",null");
133: } else {
134: print(","
135: + Arrays.equals(image_bytes, FileUtils
136: .readBytes(bean.getStreamFile())));
137: }
138: } catch (ResourceFinderErrorException e) {
139: throw new EngineException(e);
140: } catch (FileUtilsErrorException e) {
141: throw new EngineException(e);
142: }
143: }
144: }
|