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
20
21
22 import org.apache.commons.lang.StringUtils;
23
24 import org.apache.torque.om.StringKey;
25
26 import org.apache.turbine.services.intake.IntakeException;
27 import org.apache.turbine.services.intake.validator.StringValidator;
28 import org.apache.turbine.services.intake.xmlmodel.XmlField;
29
30 /***
31 * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
32 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
33 * @author <a href="mailto:quintonm@bellsouth.net">Quinton McCombs</a>
34 * @version $Id: StringKeyField.java 534527 2007-05-02 16:10:59Z tv $
35 * @deprecated Use String instead
36 */
37 public class StringKeyField
38 extends Field
39 {
40
41 /***
42 * Constructor.
43 *
44 * @param field xml field definition object
45 * @param group xml group definition object
46 * @throws IntakeException thrown by superclass
47 */
48 public StringKeyField(XmlField field, Group group)
49 throws IntakeException
50 {
51 super(field, group);
52 }
53
54 /***
55 * Produces the fully qualified class name of the default validator.
56 *
57 * @return class name of the default validator
58 */
59 protected String getDefaultValidator()
60 {
61 return StringValidator.class.getName();
62 }
63
64 /***
65 * Sets the default value for a String field
66 *
67 * @param prop Parameter for the default values
68 */
69 public void setDefaultValue(String prop)
70 {
71 if (prop == null)
72 {
73 return;
74 }
75
76 defaultValue = new StringKey(prop);
77 }
78
79 /***
80 * Set the empty Value. This value is used if Intake
81 * maps a field to a parameter returned by the user and
82 * the corresponding field is either empty (empty string)
83 * or non-existant.
84 *
85 * @param prop The value to use if the field is empty.
86 */
87 public void setEmptyValue(String prop)
88 {
89 if (prop == null)
90 {
91 return;
92 }
93
94 emptyValue = new StringKey(prop);
95 }
96
97 /***
98 * Sets the value of the field from data in the parser.
99 */
100 protected void doSetValue()
101 {
102 if (isMultiValued)
103 {
104 String[] ss = parser.getStrings(getKey());
105 StringKey[] ival = new StringKey[ss.length];
106 for (int i = 0; i < ss.length; i++)
107 {
108 ival[i] = (StringUtils.isNotEmpty(ss[i]))
109 ? new StringKey(ss[i]) : (StringKey) getEmptyValue();
110 }
111 setTestValue(ival);
112 }
113 else
114 {
115 String val = parser.getString(getKey());
116 setTestValue((StringUtils.isNotEmpty(val))
117 ? new StringKey(val) : (StringKey) getEmptyValue());
118 }
119 }
120 }