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: BeanPrefix.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 BeanPrefix 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=\"prefix_enum\">");
033: print("<input type=\"text\" name=\"prefix_string\">");
034: print("<input type=\"text\" name=\"prefix_boolean\">");
035: print("<input type=\"text\" name=\"prefix_string\">");
036: print("<input type=\"text\" name=\"prefix_stringbuffer\">");
037: print("<input type=\"text\" name=\"prefix_int\">");
038: print("<input type=\"text\" name=\"prefix_integer\">");
039: print("<input type=\"text\" name=\"prefix_char\">");
040: print("<input type=\"text\" name=\"prefix_character\">");
041: print("<input type=\"text\" name=\"prefix_boolean\">");
042: print("<input type=\"text\" name=\"prefix_booleanObject\">");
043: print("<input type=\"text\" name=\"prefix_byte\">");
044: print("<input type=\"text\" name=\"prefix_byteObject\">");
045: print("<input type=\"text\" name=\"prefix_double\">");
046: print("<input type=\"text\" name=\"prefix_doubleObject\">");
047: print("<input type=\"text\" name=\"prefix_float\">");
048: print("<input type=\"text\" name=\"prefix_floatObject\">");
049: print("<input type=\"text\" name=\"prefix_long\">");
050: print("<input type=\"text\" name=\"prefix_longObject\">");
051: print("<input type=\"text\" name=\"prefix_short\">");
052: print("<input type=\"text\" name=\"prefix_shortObject\">");
053: print("<input type=\"file\" name=\"prefix_stringFile\"/>");
054: print("<input type=\"file\" name=\"prefix_bytesFile\"/>");
055: print("<input type=\"file\" name=\"prefix_streamFile\"/>");
056: print("<input type=\"text\" name=\"prefix_date\">");
057: print("<input type=\"text\" name=\"prefix_dateFormatted\">");
058: print("<input type=\"text\" name=\"prefix_datesFormatted\">");
059: print("<input type=\"text\" name=\"prefix_datesFormatted\">");
060: print("<input type=\"text\" name=\"prefix_serializableParam\">");
061: print("<input type=\"text\" name=\"prefix_serializableParams\">");
062: print("<input type=\"text\" name=\"prefix_serializableParams\">");
063: print("</form");
064: }
065:
066: public void doBean() {
067: BeanImpl bean = getSubmissionBean("bean", BeanImpl.class,
068: "prefix_");
069:
070: Set<ValidationError> errors = bean.getValidationErrors();
071: for (ValidationError error : errors) {
072: print(error.getIdentifier() + " : " + error.getSubject()
073: + "\n");
074: }
075: print(bean.getEnum() + "," + bean.getString() + ","
076: + bean.getStringbuffer() + "," + bean.getInt() + ","
077: + bean.getInteger() + "," + bean.getChar() + ","
078: + bean.getCharacter() + "," + bean.isBoolean() + ","
079: + bean.getBooleanObject() + "," + bean.getByte() + ","
080: + bean.getByteObject() + "," + bean.getDouble() + ","
081: + bean.getDoubleObject() + "," + bean.getFloat() + ","
082: + bean.getFloatObject() + "," + bean.getLong() + ","
083: + bean.getLongObject() + "," + bean.getShort() + ","
084: + bean.getShortObject());
085: print("," + bean.getStringFile());
086:
087: try {
088: byte[] image_bytes = ResourceFinderClasspath.getInstance()
089: .useStream("uwyn.png", new InputStreamUser() {
090: public Object useInputStream(InputStream stream)
091: throws InnerClassException {
092: try {
093: return FileUtils.readBytes(stream);
094: } catch (FileUtilsErrorException e) {
095: throwException(e);
096: }
097:
098: return null;
099: }
100: });
101:
102: if (null == bean.getBytesFile()) {
103: print(",null");
104: } else {
105: print(","
106: + Arrays.equals(image_bytes, bean
107: .getBytesFile()));
108: }
109: print(","
110: + bean.getConstrainedProperty("bytesFile")
111: .getName());
112:
113: if (null == bean.getStreamFile()) {
114: print(",null");
115: } else {
116: print(","
117: + Arrays.equals(image_bytes, FileUtils
118: .readBytes(bean.getStreamFile())));
119: }
120: SimpleDateFormat sf = new SimpleDateFormat(
121: "EEE d MMM yyyy HH:mm:ss");
122: sf.setTimeZone(RifeConfig.Tools.getDefaultTimeZone());
123: print(","
124: + (null == bean.getDate() ? null : sf.format(bean
125: .getDate())));
126: if (null == bean.getDatesFormatted()) {
127: print(",null");
128: } else {
129: for (Date date : bean.getDatesFormatted()) {
130: print(",");
131: if (null == date) {
132: print("null");
133: } else {
134: print(sf.format(date));
135: }
136: }
137: }
138: print("," + bean.getSerializableParam());
139: if (null == bean.getSerializableParams()) {
140: print(",null");
141: } else {
142: for (Object param : bean.getSerializableParams()) {
143: print("," + param);
144: }
145: }
146: } catch (ResourceFinderErrorException e) {
147: throw new EngineException(e);
148: } catch (FileUtilsErrorException e) {
149: throw new EngineException(e);
150: }
151: }
152: }
|