1 package org.apache.turbine.services.intake.model;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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 264148 2005-08-29 14:21:04Z henning $
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 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 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 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[] 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 val = parser.getString(getKey());
113 setTestValue((StringUtils.isNotEmpty(val))
114 ? new StringKey(val) : (StringKey) getEmptyValue());
115 }
116 }
117 }