1 package org.apache.fulcrum.intake.model; 2 3 56 57 import java.math.BigDecimal ; 58 import java.text.DecimalFormatSymbols ; 59 60 import org.apache.fulcrum.intake.xmlmodel.XmlField; 61 62 import org.apache.log4j.Category; 63 64 70 public class BigDecimalField 71 extends Field 72 { 73 74 Category category = Category.getInstance(getClass().getName()); 75 76 public BigDecimalField(XmlField field, Group group) 77 throws Exception 78 { 79 super(field, group); 80 } 81 82 87 protected void setDefaultValue(String prop) 88 { 89 defaultValue = null; 90 91 if (prop == null) 92 { 93 return; 94 } 95 96 try 97 { 98 defaultValue = new BigDecimal (prop); 99 } 100 catch (RuntimeException e) 101 { 102 category.error("Could not convert " + prop 103 + " into a BigDecimal. (" 104 + name + ")"); 105 } 106 } 107 108 113 protected String getDefaultValidator() 114 { 115 return "org.apache.fulcrum.intake.validator.NumberValidator"; 116 } 117 118 121 protected void doSetValue() 122 { 123 if ( isMultiValued ) 124 { 125 String [] inputs = pp.getStrings(getKey()); 126 BigDecimal [] values = new BigDecimal [inputs.length]; 127 for (int i = 0; i < inputs.length; i++) 128 { 129 if (inputs[i] != null && inputs[i].length() > 0) 130 { 131 values[i] = canonicalizeDecimalInput(inputs[i]); 132 } 133 } 134 setTestValue(values); 135 } 136 else 137 { 138 String s = pp.getString(getKey()); 139 if (s != null && s.length() > 0) 140 { 141 setTestValue(canonicalizeDecimalInput(s)); 142 } 143 else 144 { 145 set_flag = false; 146 } 147 } 148 } 149 150 158 protected final BigDecimal canonicalizeDecimalInput(String bigDecimal) 159 { 160 if (getLocale() != null) 161 { 162 DecimalFormatSymbols internal = new DecimalFormatSymbols (); 163 DecimalFormatSymbols user = new DecimalFormatSymbols (getLocale()); 164 165 if (!internal.equals(user)) 166 { 167 bigDecimal = bigDecimal.replace(user.getDecimalSeparator(), 168 internal.getDecimalSeparator()); 169 } 170 } 171 return new BigDecimal (bigDecimal); 172 } 173 } 174 | Popular Tags |