KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > turbine > services > intake > model > ComboKeyField


1 package org.apache.turbine.services.intake.model;
2
3 /*
4  * Copyright 2001-2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License")
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 import org.apache.commons.lang.StringUtils;
20
21 import org.apache.torque.om.ComboKey;
22
23 import org.apache.turbine.services.intake.IntakeException;
24 import org.apache.turbine.services.intake.xmlmodel.XmlField;
25
26 /**
27  * @author <a HREF="mailto:jmcnally@collab.net">John McNally</a>
28  * @author <a HREF="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
29  * @author <a HREF="mailto:quintonm@bellsouth.net">Quinton McCombs</a>
30  * @version $Id: ComboKeyField.java,v 1.11.2.2 2004/05/20 03:16:39 seade Exp $
31  */

32 public class ComboKeyField
33         extends Field
34 {
35     /**
36      * Constructor.
37      *
38      * @param field xml field definition object
39      * @param group xml group definition object
40      * @throws IntakeException thrown by superclass
41      */

42     public ComboKeyField(XmlField field, Group group)
43             throws IntakeException
44     {
45         super(field, group);
46     }
47
48     /**
49      * Sets the default value for a ComboKey field
50      *
51      * @param prop Parameter for the default values
52      */

53     public void setDefaultValue(String JavaDoc prop)
54     {
55         defaultValue = null;
56
57         if (prop == null)
58         {
59             return;
60         }
61
62         defaultValue = new ComboKey(prop);
63     }
64
65     /**
66      * Set the empty Value. This value is used if Intake
67      * maps a field to a parameter returned by the user and
68      * the corresponding field is either empty (empty string)
69      * or non-existant.
70      *
71      * @param prop The value to use if the field is empty.
72      */

73     public void setEmptyValue(String JavaDoc prop)
74     {
75         emptyValue = null;
76
77         if (prop == null)
78         {
79             return;
80         }
81
82         emptyValue = new ComboKey(prop);
83     }
84
85     /**
86      * Sets the value of the field from data in the parser.
87      */

88     protected void doSetValue()
89     {
90         if (isMultiValued)
91         {
92             String JavaDoc[] inputs = parser.getStrings(getKey());
93             ComboKey[] values = new ComboKey[inputs.length];
94             for (int i = 0; i < inputs.length; i++)
95             {
96                 values[i] = StringUtils.isNotEmpty(inputs[i])
97                         ? new ComboKey(inputs[i]) : (ComboKey) getEmptyValue();
98             }
99             setTestValue(values);
100         }
101         else
102         {
103             String JavaDoc val = parser.getString(getKey());
104             setTestValue(StringUtils.isNotEmpty(val) ? new ComboKey(val) : (ComboKey) getEmptyValue());
105         }
106     }
107 }
108
Popular Tags