%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.turbine.services.intake.model.StringKeyField |
|
|
1 | package org.apache.turbine.services.intake.model; |
|
2 | ||
3 | /* |
|
4 | * Copyright 2001-2005 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 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 | 0 | super(field, group); |
49 | 0 | } |
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 | 0 | 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 | 0 | if (prop == null) |
69 | { |
|
70 | 0 | return; |
71 | } |
|
72 | ||
73 | 0 | defaultValue = new StringKey(prop); |
74 | 0 | } |
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 | 0 | if (prop == null) |
87 | { |
|
88 | 0 | return; |
89 | } |
|
90 | ||
91 | 0 | emptyValue = new StringKey(prop); |
92 | 0 | } |
93 | ||
94 | /** |
|
95 | * Sets the value of the field from data in the parser. |
|
96 | */ |
|
97 | protected void doSetValue() |
|
98 | { |
|
99 | 0 | if (isMultiValued) |
100 | { |
|
101 | 0 | String[] ss = parser.getStrings(getKey()); |
102 | 0 | StringKey[] ival = new StringKey[ss.length]; |
103 | 0 | for (int i = 0; i < ss.length; i++) |
104 | { |
|
105 | 0 | ival[i] = (StringUtils.isNotEmpty(ss[i])) |
106 | ? new StringKey(ss[i]) : (StringKey) getEmptyValue(); |
|
107 | } |
|
108 | 0 | setTestValue(ival); |
109 | } |
|
110 | else |
|
111 | { |
|
112 | 0 | String val = parser.getString(getKey()); |
113 | 0 | setTestValue((StringUtils.isNotEmpty(val)) |
114 | ? new StringKey(val) : (StringKey) getEmptyValue()); |
|
115 | } |
|
116 | 0 | } |
117 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |