KickJava   Java API By Example, From Geeks To Geeks.

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


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.StringKey;
22
23 import org.apache.turbine.services.intake.IntakeException;
24 import org.apache.turbine.services.intake.validator.StringValidator;
25 import org.apache.turbine.services.intake.xmlmodel.XmlField;
26
27 /**
28  * @author <a HREF="mailto:jmcnally@collab.net">John McNally</a>
29  * @author <a HREF="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
30  * @author <a HREF="mailto:quintonm@bellsouth.net">Quinton McCombs</a>
31  * @version $Id: StringKeyField.java,v 1.11.2.2 2004/05/20 03:16:39 seade Exp $
32  * @deprecated Use String instead
33  */

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

45     public StringKeyField(XmlField field, Group group)
46             throws IntakeException
47     {
48         super(field, group);
49     }
50
51     /**
52      * Produces the fully qualified class name of the default validator.
53      *
54      * @return class name of the default validator
55      */

56     protected String JavaDoc getDefaultValidator()
57     {
58         return StringValidator.class.getName();
59     }
60
61     /**
62      * Sets the default value for a String field
63      *
64      * @param prop Parameter for the default values
65      */

66     public void setDefaultValue(String JavaDoc prop)
67     {
68         if (prop == null)
69         {
70             return;
71         }
72
73         defaultValue = new StringKey(prop);
74     }
75
76     /**
77      * Set the empty Value. This value is used if Intake
78      * maps a field to a parameter returned by the user and
79      * the corresponding field is either empty (empty string)
80      * or non-existant.
81      *
82      * @param prop The value to use if the field is empty.
83      */

84     public void setEmptyValue(String JavaDoc prop)
85     {
86         if (prop == null)
87         {
88             return;
89         }
90
91         emptyValue = new StringKey(prop);
92     }
93
94     /**
95      * Sets the value of the field from data in the parser.
96      */

97     protected void doSetValue()
98     {
99         if (isMultiValued)
100         {
101             String JavaDoc[] ss = parser.getStrings(getKey());
102             StringKey[] ival = new StringKey[ss.length];
103             for (int i = 0; i < ss.length; i++)
104             {
105                 ival[i] = (StringUtils.isNotEmpty(ss[i]))
106                         ? new StringKey(ss[i]) : (StringKey) getEmptyValue();
107             }
108             setTestValue(ival);
109         }
110         else
111         {
112             String JavaDoc val = parser.getString(getKey());
113             setTestValue((StringUtils.isNotEmpty(val))
114                     ? new StringKey(val) : (StringKey) getEmptyValue());
115         }
116     }
117 }
118
Popular Tags