View Javadoc
1   /*
2    * $Id$
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  package org.apache.struts.webapp.el.exercise;
23  
24  
25  import org.apache.struts.action.ActionForm;
26  import org.apache.struts.action.ActionMapping;
27  import org.apache.struts.util.LabelValueBean;
28  
29  import jakarta.servlet.http.HttpServletRequest;
30  import java.util.ArrayList;
31  import java.util.Collection;
32  
33  
34  /**
35   * General purpose test bean for Struts custom tag tests.
36   *
37   * @author Craig R. McClanahan
38   * @author Martin F N Cooper
39   * @version $Rev$ $Date: 2004-10-16 13:04:52 -0400 (Sat, 16 Oct 2004)
40   *          $
41   */
42  
43  public class TestBean extends ActionForm {
44      private static final long serialVersionUID = 8323139488730091727L;
45  
46      // ------------------------------------------------------------- Properties
47  
48  
49      /**
50       * A collection property where the elements of the collection are of type
51       * <code>LabelValueBean</code>.
52       */
53      private Collection<LabelValueBean> beanCollection = null;
54  
55      public Collection<LabelValueBean> getBeanCollection() {
56          if (beanCollection == null) {
57              ArrayList<LabelValueBean> entries = new ArrayList<>(10);
58  
59              entries.add(new LabelValueBean("Label 0", "Value 0"));
60              entries.add(new LabelValueBean("Label 1", "Value 1"));
61              entries.add(new LabelValueBean("Label 2", "Value 2"));
62              entries.add(new LabelValueBean("Label 3", "Value 3"));
63              entries.add(new LabelValueBean("Label 4", "Value 4"));
64              entries.add(new LabelValueBean("Label 5", "Value 5"));
65              entries.add(new LabelValueBean("Label 6", "Value 6"));
66              entries.add(new LabelValueBean("Label 7", "Value 7"));
67              entries.add(new LabelValueBean("Label 8", "Value 8"));
68              entries.add(new LabelValueBean("Label 9", "Value 9"));
69  
70              beanCollection = entries;
71          }
72  
73          return (beanCollection);
74      }
75  
76      public void setBeanCollection(Collection<LabelValueBean> beanCollection) {
77          this.beanCollection = beanCollection;
78      }
79  
80  
81      /**
82       * A multiple-String SELECT element using a bean collection.
83       */
84      private String[] beanCollectionSelect = { "Value 1", "Value 3",
85              "Value 5" };
86  
87      public String[] getBeanCollectionSelect() {
88          return (this.beanCollectionSelect);
89      }
90  
91      public void setBeanCollectionSelect(String beanCollectionSelect[]) {
92          this.beanCollectionSelect = beanCollectionSelect;
93      }
94  
95  
96      /**
97       * A boolean property whose initial value is true.
98       */
99      private boolean booleanProperty = true;
100 
101     public boolean getBooleanProperty() {
102         return (booleanProperty);
103     }
104 
105     public void setBooleanProperty(boolean booleanProperty) {
106         this.booleanProperty = booleanProperty;
107     }
108 
109 
110     /**
111      * A multiple-String SELECT element using a collection.
112      */
113     private String[] collectionSelect = { "Value 2", "Value 4",
114             "Value 6" };
115 
116     public String[] getCollectionSelect() {
117         return (this.collectionSelect);
118     }
119 
120     public void setCollectionSelect(String collectionSelect[]) {
121         this.collectionSelect = collectionSelect;
122     }
123 
124 
125     /**
126      * A double property.
127      */
128     private double doubleProperty = 321.0;
129 
130     public double getDoubleProperty() {
131         return (this.doubleProperty);
132     }
133 
134     public void setDoubleProperty(double doubleProperty) {
135         this.doubleProperty = doubleProperty;
136     }
137 
138 
139     /**
140      * A boolean property whose initial value is false
141      */
142     private boolean falseProperty = false;
143 
144     public boolean getFalseProperty() {
145         return (falseProperty);
146     }
147 
148     public void setFalseProperty(boolean falseProperty) {
149         this.falseProperty = falseProperty;
150     }
151 
152 
153     /**
154      * A float property.
155      */
156     private float floatProperty = (float) 123.0;
157 
158     public float getFloatProperty() {
159         return (this.floatProperty);
160     }
161 
162     public void setFloatProperty(float floatProperty) {
163         this.floatProperty = floatProperty;
164     }
165 
166 
167     /**
168      * Integer arrays that are accessed as an array as well as indexed.
169      */
170     private int intArray[] = { 0, 10, 20, 30, 40 };
171 
172     public int[] getIntArray() {
173         return (this.intArray);
174     }
175 
176     public void setIntArray(int intArray[]) {
177         this.intArray = intArray;
178     }
179 
180     private int intIndexed[] = { 0, 10, 20, 30, 40 };
181 
182     public int getIntIndexed(int index) {
183         return (intIndexed[index]);
184     }
185 
186     public void setIntIndexed(int index, int value) {
187         intIndexed[index] = value;
188     }
189 
190 
191     private int intMultibox[] = new int[0];
192 
193     public int[] getIntMultibox() {
194         return (this.intMultibox);
195     }
196 
197     public void setIntMultibox(int intMultibox[]) {
198         this.intMultibox = intMultibox;
199     }
200 
201     /**
202      * An integer property.
203      */
204     private int intProperty = 123;
205 
206     public int getIntProperty() {
207         return (this.intProperty);
208     }
209 
210     public void setIntProperty(int intProperty) {
211         this.intProperty = intProperty;
212     }
213 
214 
215     /**
216      * A long property.
217      */
218     private long longProperty = 321;
219 
220     public long getLongProperty() {
221         return (this.longProperty);
222     }
223 
224     public void setLongProperty(long longProperty) {
225         this.longProperty = longProperty;
226     }
227 
228 
229     /**
230      * A multiple-String SELECT element.
231      */
232     private String[] multipleSelect = { "Multiple 3", "Multiple 5",
233             "Multiple 7" };
234 
235     public String[] getMultipleSelect() {
236         return (this.multipleSelect);
237     }
238 
239     public void setMultipleSelect(String multipleSelect[]) {
240         this.multipleSelect = multipleSelect;
241     }
242 
243 
244     /**
245      * A nested reference to another test bean (populated as needed).
246      */
247     private TestBean nested = null;
248 
249     public TestBean getNested() {
250         if (nested == null) {
251             nested = new TestBean();
252         }
253         return (nested);
254     }
255 
256 
257     /**
258      * A String property with an initial value of null.
259      */
260     private String nullProperty = null;
261 
262     public String getNullProperty() {
263         return (this.nullProperty);
264     }
265 
266     public void setNullProperty(String nullProperty) {
267         this.nullProperty = nullProperty;
268     }
269 
270 
271     /**
272      * A short property.
273      */
274     private short shortProperty = (short) 987;
275 
276     public short getShortProperty() {
277         return (this.shortProperty);
278     }
279 
280     public void setShortProperty(short shortProperty) {
281         this.shortProperty = shortProperty;
282     }
283 
284 
285     /**
286      * A single-String value for a SELECT element.
287      */
288     private String singleSelect = "Single 5";
289 
290     public String getSingleSelect() {
291         return (this.singleSelect);
292     }
293 
294     public void setSingleSelect(String singleSelect) {
295         this.singleSelect = singleSelect;
296     }
297 
298 
299     /**
300      * String arrays that are accessed as an array as well as indexed.
301      */
302     private String stringArray[] =
303             { "String 0", "String 1", "String 2", "String 3", "String 4" };
304 
305     public String[] getStringArray() {
306         return (this.stringArray);
307     }
308 
309     public void setStringArray(String stringArray[]) {
310         this.stringArray = stringArray;
311     }
312 
313     private String stringIndexed[] =
314             { "String 0", "String 1", "String 2", "String 3", "String 4" };
315 
316     public String getStringIndexed(int index) {
317         return (stringIndexed[index]);
318     }
319 
320     public void setStringIndexed(int index, String value) {
321         stringIndexed[index] = value;
322     }
323 
324     private String indexedStrings[] =
325             { "alpha", "beta", "gamma", "delta", "epsilon" };
326 
327     public String[] getIndexedStrings() {
328         return (indexedStrings);
329     }
330 
331     private String stringMultibox[] = new String[0];
332 
333     public String[] getStringMultibox() {
334         return (this.stringMultibox);
335     }
336 
337     public void setStringMultibox(String stringMultibox[]) {
338         this.stringMultibox = stringMultibox;
339     }
340 
341     /**
342      * A String property.
343      */
344     private String stringProperty = "This is a string";
345 
346     public String getStringProperty() {
347         return (this.stringProperty);
348     }
349 
350     public void setStringProperty(String stringProperty) {
351         this.stringProperty = stringProperty;
352     }
353 
354     /**
355      * An empty String property.
356      */
357     private String emptyStringProperty = "";
358 
359     public String getEmptyStringProperty() {
360         return (this.emptyStringProperty);
361     }
362 
363     public void setEmptyStringProperty(String emptyStringProperty) {
364         this.emptyStringProperty = emptyStringProperty;
365     }
366 
367     /**
368      * A list of coordinate objects.
369      */
370     private Coord[] coords =
371             { new Coord(0, 0), new Coord(0, 1), new Coord(1, 1),
372                     new Coord(2, 0),
373                     new Coord(2, 1)
374             };
375 
376     public Coord[]  getCoords() {
377         return (coords);
378     }
379 
380     public Coord getCoord(int index) {
381         return (coords[index]);
382     }
383 
384     public void setCoord(int index, Coord coord) {
385         coords[index] = coord;
386     }
387 
388     /**
389      * A list of images.
390      */
391     public String images[] = { "T1.gif", "T2.gif" };
392 
393     public String[] getImages() {
394         return (images);
395     }
396 
397     private Coord[] imageCoords = { new Coord(0, 0), new Coord(0, 0) };
398 
399     public Coord[]  getImageCoords() {
400         return (imageCoords);
401     }
402 
403     public Coord getImageCoord(int index) {
404         return (imageCoords[index]);
405     }
406 
407     public void setImageCoord(int index, Coord coord) {
408         imageCoords[index] = coord;
409     }
410 
411     /**
412      * A property that allows a null value but is still used in a SELECT.
413      */
414     private String withNulls = null;
415 
416     public String getWithNulls() {
417         return (this.withNulls);
418     }
419 
420     public void setWithNulls(String withNulls) {
421         this.withNulls = withNulls;
422     }
423 
424     // --------------------------------------------------------- Public Methods
425 
426 
427     /**
428      * Reset the properties that will be received as input.
429      */
430     public void reset(ActionMapping mapping, HttpServletRequest request) {
431 
432         booleanProperty = false;
433         collectionSelect = new String[0];
434         intMultibox = new int[0];
435         multipleSelect = new String[0];
436         stringMultibox = new String[0];
437         if (nested != null) {
438             nested.reset(mapping, request);
439         }
440 
441     }
442 
443 
444 }