001: /*
002: * JFolder, Copyright 2001-2006 Gary Steinmetz
003: *
004: * Distributable under LGPL license.
005: * See terms of license at gnu.org.
006: */
007:
008: package org.jfolder.common.web.template;
009:
010: //base classes
011: import java.util.ArrayList;
012:
013: //project specific classes
014: import org.jfolder.common.UnexpectedSystemException;
015: import org.jfolder.common.utils.web.ParameterSet;
016:
017: //other classes
018:
019: public class CreationResultParameterContext implements
020: ConsoleParameterContext {
021:
022: //
023: private ConsoleParameterHolder parameterCph = null;
024: private boolean valid = false;
025:
026: //
027: private CreationResultParameterContext() {
028: //
029: this .parameterCph = ConsoleParameterHolder.newInstance();
030:
031: }
032:
033: //
034: public final static CreationResultParameterContext newInstance(
035: ParameterSet inPs) {
036:
037: CreationResultParameterContext outValue = null;
038:
039: outValue = new CreationResultParameterContext();
040: outValue.initialize(inPs);
041:
042: return outValue;
043: }
044:
045: //
046: public int hashCode() {
047:
048: int outValue = 0;
049:
050: outValue += this .parameterCph.hashCode();
051:
052: return outValue;
053: }
054:
055: public boolean equals(Object inObj) {
056:
057: boolean outValue = true;
058:
059: if (inObj instanceof CreationResultParameterContext) {
060: CreationResultParameterContext nextCrpc = ((CreationResultParameterContext) inObj);
061: outValue &= (this .parameterCph
062: .equals(nextCrpc.parameterCph));
063: outValue &= (this .valid == nextCrpc.valid);
064: } else {
065: outValue &= false;
066: }
067:
068: return outValue;
069: }
070:
071: public String getParameter(Integer inIndex) {
072: return ((String) this .parameterCph.getInput(inIndex));
073: }
074:
075: //
076: public boolean isValid() {
077: return this .valid;
078: }
079:
080: //
081: private void initialize(ParameterSet inPs) {
082:
083: //
084: this .valid = true;
085:
086: //
087: int foundParameters = 0;
088: if (inPs
089: .isParameterString(CreationParameterContext.CONSOLE_CREATION_PARAMETER_COUNT)) {
090: //
091: try {
092: String s = inPs
093: .getParameter(CreationParameterContext.CONSOLE_CREATION_PARAMETER_COUNT);
094: //
095: foundParameters = Integer.parseInt(s);
096: } catch (NumberFormatException nfe) {
097: foundParameters = 0;
098: this .valid &= false;
099: }
100: } else {
101: this .valid &= false;
102: }
103:
104: //
105: ArrayList indexes = ConsoleParameterHolder.getIndexes();
106: for (int i = 0; i < indexes.size(); i++) {
107: Integer nextIndex = ((Integer) indexes.get(i));
108:
109: if (inPs
110: .isParameterString(CreationParameterContext.CONSOLE_CREATION_PARAMETER_TYPE_PREFIX
111: + nextIndex)) {
112: //
113:
114: String nextValueType = inPs
115: .getParameter(CreationParameterContext.CONSOLE_CREATION_PARAMETER_TYPE_PREFIX
116: + nextIndex);
117:
118: if (i < foundParameters) {
119: //
120: //
121: String nextValue = null;
122: Integer nextType = new Integer(nextValueType);
123: if (CreationParameterContext.TYPE_TEXT_BOX
124: .equals(nextType)) {
125: //
126: String nextValueId = CreationParameterContext
127: .getTextBoxFromTypeTextBox(i);
128: //
129: nextValue = inPs.getParameter(nextValueId);
130: } else if (CreationParameterContext.TYPE_FILE_UPLOAD
131: .equals(nextType)) {
132: //
133: String nextValueId = CreationParameterContext
134: .getFileUploadFromTypeFileUpload(i);
135: //
136: nextValue = nextValueId;//inPs.getParameter(nextValueId)
137: } else if (CreationParameterContext.TYPE_HIDDEN_BOX
138: .equals(nextType)) {
139: //
140: String nextValueId = CreationParameterContext
141: .getHiddenBoxFromTypeHiddenBox(i);
142: //
143: nextValue = inPs.getParameter(nextValueId);
144: } else if (CreationParameterContext.TYPE_BUTTON
145: .equals(nextType)) {
146: //
147: //String nextValueId =
148: //CreationParameterContext.getButtonFromTypeButton(i);
149: //
150: nextValue = "";//inPs.getParameter(nextValueId);
151: } else if (CreationParameterContext.TYPE_TEXT_AREA
152: .equals(nextType)) {
153: //
154: String nextValueId = CreationParameterContext
155: .getTextAreaFromTypeTextArea(i);
156: //
157: nextValue = inPs.getParameter(nextValueId);
158: } else if (CreationParameterContext.TYPE_INCLUSIVE_SELECT
159: .equals(nextType)) {
160: //
161: String nextValueId = CreationParameterContext
162: .getDropDownBoxFromTypeSelectInclusive(i);
163: //
164: nextValue = inPs.getParameter(nextValueId);
165: //
166: if (nextValue.length() > 0) {
167: nextValue = nextValue
168: .substring(ConsoleTemplateContext.BRANCH_SEPARATOR
169: .length());
170: } else {
171: nextValueId = CreationParameterContext
172: .getTextBoxFromTypeSelectInclusive(i);
173: //
174: nextValue = inPs.getParameter(nextValueId);
175: }
176: } else if (CreationParameterContext.TYPE_EXCLUSIVE_SELECT
177: .equals(nextType)) {
178: //
179: String nextValueId = CreationParameterContext
180: .getDropDownBoxFromTypeSelectExclusive(i);
181: //
182: nextValue = inPs.getParameter(nextValueId);
183: nextValue = nextValue
184: .substring(ConsoleTemplateContext.BRANCH_SEPARATOR
185: .length());
186: } else {
187: throw new UnexpectedSystemException(
188: "Unknown Type '" + nextType + "'");
189: }
190: //
191: //
192: this .parameterCph.addInput(nextIndex, nextValue);
193: } else {
194: this .parameterCph.addInput(nextIndex, "");
195: }
196: } else {
197: this .valid &= false;
198: this .parameterCph.addInput(nextIndex, "");
199: }
200: }
201: }
202: }
|