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: BeanNormal.java 3714 2007-04-08 02:57:38Z gbevin $
007: */
008: package com.uwyn.rife.engine.testelements.submission;
009:
010: import com.uwyn.rife.config.RifeConfig;
011: import com.uwyn.rife.engine.Element;
012: import com.uwyn.rife.engine.exceptions.EngineException;
013: import com.uwyn.rife.resources.ResourceFinderClasspath;
014: import com.uwyn.rife.resources.exceptions.ResourceFinderErrorException;
015: import com.uwyn.rife.site.ValidationError;
016: import com.uwyn.rife.tools.FileUtils;
017: import com.uwyn.rife.tools.InnerClassException;
018: import com.uwyn.rife.tools.InputStreamUser;
019: import com.uwyn.rife.tools.exceptions.FileUtilsErrorException;
020: import java.io.InputStream;
021: import java.text.SimpleDateFormat;
022: import java.util.Arrays;
023: import java.util.Date;
024: import java.util.Set;
025:
026: public class BeanNormal extends Element {
027: public void processElement() {
028: print("<form name=\"submissionform\" action=\""
029: + getSubmissionFormUrl()
030: + "\" method=\"post\" enctype=\"multipart/form-data\">");
031: print(getSubmissionFormParameters("bean"));
032: print("<input type=\"text\" name=\"enum\">");
033: print("<input type=\"text\" name=\"string\">");
034: print("<input type=\"text\" name=\"boolean\">");
035: print("<input type=\"text\" name=\"string\">");
036: print("<input type=\"text\" name=\"stringbuffer\">");
037: print("<input type=\"text\" name=\"int\">");
038: print("<input type=\"text\" name=\"integer\">");
039: print("<input type=\"text\" name=\"char\">");
040: print("<input type=\"text\" name=\"character\">");
041: print("<input type=\"text\" name=\"boolean\">");
042: print("<input type=\"text\" name=\"booleanObject\">");
043: print("<input type=\"text\" name=\"byte\">");
044: print("<input type=\"text\" name=\"byteObject\">");
045: print("<input type=\"text\" name=\"double\">");
046: print("<input type=\"text\" name=\"doubleObject\">");
047: print("<input type=\"text\" name=\"float\">");
048: print("<input type=\"text\" name=\"floatObject\">");
049: print("<input type=\"text\" name=\"long\">");
050: print("<input type=\"text\" name=\"longObject\">");
051: print("<input type=\"text\" name=\"short\">");
052: print("<input type=\"text\" name=\"shortObject\">");
053: print("<input type=\"file\" name=\"stringFile\"/>");
054: print("<input type=\"file\" name=\"bytesFile\"/>");
055: print("<input type=\"file\" name=\"streamFile\"/>");
056: print("<input type=\"text\" name=\"date\">");
057: print("<input type=\"text\" name=\"dateFormatted\">");
058: print("<input type=\"text\" name=\"datesFormatted\">");
059: print("<input type=\"text\" name=\"datesFormatted\">");
060: print("<input type=\"text\" name=\"serializableParam\">");
061: print("<input type=\"text\" name=\"serializableParams\">");
062: print("<input type=\"text\" name=\"serializableParams\">");
063: print("</form");
064: }
065:
066: public void doBean() {
067: BeanImpl bean = getSubmissionBean("bean", BeanImpl.class);
068:
069: Set<ValidationError> errors = bean.getValidationErrors();
070: for (ValidationError error : errors) {
071: print(error.getIdentifier() + " : " + error.getSubject()
072: + "\n");
073: }
074: print(bean.getEnum() + "," + bean.getString() + ","
075: + bean.getStringbuffer() + "," + bean.getInt() + ","
076: + bean.getInteger() + "," + bean.getChar() + ","
077: + bean.getCharacter() + "," + bean.isBoolean() + ","
078: + bean.getBooleanObject() + "," + bean.getByte() + ","
079: + bean.getByteObject() + "," + bean.getDouble() + ","
080: + bean.getDoubleObject() + "," + bean.getFloat() + ","
081: + bean.getFloatObject() + "," + bean.getLong() + ","
082: + bean.getLongObject() + "," + bean.getShort() + ","
083: + bean.getShortObject());
084: print("," + bean.getStringFile());
085:
086: try {
087: byte[] image_bytes = ResourceFinderClasspath.getInstance()
088: .useStream("uwyn.png", new InputStreamUser() {
089: public Object useInputStream(InputStream stream)
090: throws InnerClassException {
091: try {
092: return FileUtils.readBytes(stream);
093: } catch (FileUtilsErrorException e) {
094: throwException(e);
095: }
096:
097: return null;
098: }
099: });
100:
101: if (null == bean.getBytesFile()) {
102: print(",null");
103: } else {
104: print(","
105: + Arrays.equals(image_bytes, bean
106: .getBytesFile()));
107: }
108: print(","
109: + bean.getConstrainedProperty("bytesFile")
110: .getName());
111:
112: if (null == bean.getStreamFile()) {
113: print(",null");
114: } else {
115: print(","
116: + Arrays.equals(image_bytes, FileUtils
117: .readBytes(bean.getStreamFile())));
118: }
119: SimpleDateFormat sf = new SimpleDateFormat(
120: "EEE d MMM yyyy HH:mm:ss");
121: sf.setTimeZone(RifeConfig.Tools.getDefaultTimeZone());
122: print(","
123: + (null == bean.getDate() ? null : sf.format(bean
124: .getDate())));
125: if (null == bean.getDatesFormatted()) {
126: print(",null");
127: } else {
128: for (Date date : bean.getDatesFormatted()) {
129: print(",");
130: if (null == date) {
131: print("null");
132: } else {
133: print(sf.format(date));
134: }
135: }
136: }
137: print("," + bean.getSerializableParam());
138: if (null == bean.getSerializableParams()) {
139: print(",null");
140: } else {
141: for (Object param : bean.getSerializableParams()) {
142: print("," + param);
143: }
144: }
145: } catch (ResourceFinderErrorException e) {
146: throw new EngineException(e);
147: } catch (FileUtilsErrorException e) {
148: throw new EngineException(e);
149: }
150: }
151: }
|