1 package org.apache.turbine.services.intake.model; 2 3 18 19 import org.apache.commons.lang.StringUtils; 20 21 import org.apache.turbine.services.intake.IntakeException; 22 import org.apache.turbine.services.intake.validator.FloatValidator; 23 import org.apache.turbine.services.intake.xmlmodel.XmlField; 24 25 34 public class FloatField 35 extends Field 36 { 37 38 45 public FloatField(XmlField field, Group group) 46 throws IntakeException 47 { 48 super(field, group); 49 } 50 51 56 public void setDefaultValue(String prop) 57 { 58 defaultValue = null; 59 60 if (prop == null) 61 { 62 return; 63 } 64 65 defaultValue = new Float (prop); 66 } 67 68 76 public void setEmptyValue(String prop) 77 { 78 emptyValue = null; 79 80 if (prop == null) 81 { 82 return; 83 } 84 85 emptyValue = new Double (prop); 86 } 87 88 98 protected Object getSafeEmptyValue() 99 { 100 if (isMultiValued) 101 { 102 return new float[0]; 103 } 104 else 105 { 106 return (null == getEmptyValue()) 107 ? new Float (0.0) : getEmptyValue(); 108 } 109 } 110 111 116 protected String getDefaultValidator() 117 { 118 return FloatValidator.class.getName(); 119 } 120 121 124 protected void doSetValue() 125 { 126 if (isMultiValued) 127 { 128 String [] inputs = parser.getStrings(getKey()); 129 float[] values = new float[inputs.length]; 130 for (int i = 0; i < inputs.length; i++) 131 { 132 values[i] = StringUtils.isNotEmpty(inputs[i]) 133 ? new Float (inputs[i]).floatValue() 134 : ((Float ) getEmptyValue()).floatValue(); 135 } 136 setTestValue(values); 137 } 138 else 139 { 140 String val = parser.getString(getKey()); 141 setTestValue(StringUtils.isNotEmpty(val) 142 ? new Float (val) : getEmptyValue()); 143 } 144 } 145 146 } 147 | Popular Tags |