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.DoubleValidator; 23 import org.apache.turbine.services.intake.xmlmodel.XmlField; 24 25 31 public class DoubleField 32 extends Field 33 { 34 41 public DoubleField(XmlField field, Group group) 42 throws IntakeException 43 { 44 super(field, group); 45 } 46 47 52 public void setDefaultValue(String prop) 53 { 54 defaultValue = null; 55 56 if (prop == null) 57 { 58 return; 59 } 60 61 defaultValue = new Double (prop); 62 } 63 64 72 public void setEmptyValue(String prop) 73 { 74 emptyValue = null; 75 76 if (prop == null) 77 { 78 return; 79 } 80 81 emptyValue = new Double (prop); 82 } 83 84 94 protected Object getSafeEmptyValue() 95 { 96 if (isMultiValued) 97 { 98 return new double[0]; 99 } 100 else 101 { 102 return (null == getEmptyValue()) 103 ? new Double (0.0) : getEmptyValue(); 104 } 105 } 106 107 112 protected String getDefaultValidator() 113 { 114 return DoubleValidator.class.getName(); 115 } 116 117 120 protected void doSetValue() 121 { 122 if (isMultiValued) 123 { 124 String [] inputs = parser.getStrings(getKey()); 125 double[] values = new double[inputs.length]; 126 for (int i = 0; i < inputs.length; i++) 127 { 128 values[i] = StringUtils.isNotEmpty(inputs[i]) 129 ? new Double (inputs[i]).doubleValue() 130 : ((Double ) getEmptyValue()).doubleValue(); 131 } 132 setTestValue(values); 133 } 134 else 135 { 136 String val = parser.getString(getKey()); 137 setTestValue(StringUtils.isNotEmpty(val) 138 ? new Double (val) : (Double ) getEmptyValue()); 139 } 140 } 141 142 } 143 | Popular Tags |