001: /*
002: * Copyright 2004, 2005, 2006 Odysseus Software GmbH
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package de.odysseus.calyxo.forms.impl;
017:
018: import java.util.Iterator;
019:
020: import javax.servlet.http.HttpServletRequest;
021:
022: import de.odysseus.calyxo.base.Message;
023: import de.odysseus.calyxo.forms.FormData;
024: import de.odysseus.calyxo.forms.FormInput;
025: import de.odysseus.calyxo.forms.FormInputResult;
026: import de.odysseus.calyxo.forms.FormInputValues;
027:
028: /**
029: * Form input result for ignored inputs.
030: *
031: * @author Christoph Beck
032: */
033: public class IgnoredFormInputResult implements FormInputResult {
034: private final FormInput input;
035: private final String value;
036: private final String[] values;
037:
038: /**
039: * Constructor.
040: */
041: public IgnoredFormInputResult(FormInput input,
042: FormInputValues params) {
043: super ();
044:
045: this .input = input;
046: if (input.isArray()) {
047: this .value = null;
048: this .values = params._getInputs(input.getName());
049: } else {
050: this .value = params._getInput(input.getName());
051: this .values = null;
052: }
053: }
054:
055: /* (non-Javadoc)
056: * @see de.odysseus.calyxo.forms.FormInputResult#getLength()
057: */
058: public int getSize() {
059: return value != null ? 1 : values != null ? values.length : 0;
060: }
061:
062: /* (non-Javadoc)
063: * @see de.odysseus.calyxo.forms.FormInputResult#getFormInput()
064: */
065: public FormInput getFormInput() {
066: return input;
067: }
068:
069: /* (non-Javadoc)
070: * @see de.odysseus.calyxo.forms.FormInputResult#getProperty()
071: */
072: public String getProperty() {
073: return null;
074: }
075:
076: /* (non-Javadoc)
077: * @see de.odysseus.calyxo.forms.FormInputResult#getValue()
078: */
079: public Object getValue() {
080: return null;
081: }
082:
083: /* (non-Javadoc)
084: * @see de.odysseus.calyxo.forms.FormInputResult#getValue(int)
085: */
086: public Object getValue(int index) {
087: return null;
088: }
089:
090: /* (non-Javadoc)
091: * @see de.odysseus.calyxo.forms.FormInputResult#isValid()
092: */
093: public boolean isValid() {
094: return false;
095: }
096:
097: /* (non-Javadoc)
098: * @see de.odysseus.calyxo.forms.FormInputResult#isValid(int)
099: */
100: public boolean isValid(int index) {
101: return false;
102: }
103:
104: /* (non-Javadoc)
105: * @see de.odysseus.calyxo.forms.FormInputResult#getMessage(int)
106: */
107: public Message getMessage(int index) {
108: return null;
109: }
110:
111: /* (non-Javadoc)
112: * @see de.odysseus.calyxo.forms.FormInputResult#getFirstMessage()
113: */
114: public Message getFirstMessage() {
115: return null;
116: }
117:
118: /* (non-Javadoc)
119: * @see de.odysseus.calyxo.forms.FormInputResult#getLastMessages()
120: */
121: public Iterator getLastMessages() {
122: return null;
123: }
124:
125: /* (non-Javadoc)
126: * @see de.odysseus.calyxo.forms.FormInputResult#format(javax.servlet.http.HttpServletRequest)
127: */
128: public Object format(HttpServletRequest request) {
129: return value;
130: }
131:
132: /* (non-Javadoc)
133: * @see de.odysseus.calyxo.forms.FormInputResult#format(javax.servlet.http.HttpServletRequest, int)
134: */
135: public String format(HttpServletRequest request, int index) {
136: return values[index];
137: }
138:
139: /* (non-Javadoc)
140: * @see de.odysseus.calyxo.forms.FormInputResult#populate(de.odysseus.calyxo.forms.FormData)
141: */
142: public void populate(FormData bean) throws Exception {
143: }
144:
145: /* (non-Javadoc)
146: * @see de.odysseus.calyxo.forms.FormInputResult#isIgnored()
147: */
148: public boolean isIgnored() {
149: return true;
150: }
151:
152: /* (non-Javadoc)
153: * @see de.odysseus.calyxo.forms.FormInputResult#isRelaxed()
154: */
155: public boolean isRelaxed() {
156: return true;
157: }
158:
159: /* (non-Javadoc)
160: * @see de.odysseus.calyxo.forms.FormInputResult#getInputValue()
161: */
162: public Object getInputValue() {
163: return input.isArray() ? (Object) values : (Object) value;
164: }
165:
166: /* (non-Javadoc)
167: * @see de.odysseus.calyxo.forms.FormInputResult#getInputValue(int)
168: */
169: public String getInputValue(int index) {
170: if (input.isArray()) {
171: return values == null || index >= values.length ? null
172: : values[index];
173: } else {
174: return index == 0 ? value : null;
175: }
176: }
177: }
|