1 16 17 package org.apache.commons.beanutils.locale.converters; 18 19 import org.apache.commons.beanutils.locale.BaseLocaleConverter; 20 import org.apache.commons.logging.Log; 21 import org.apache.commons.logging.LogFactory; 22 23 import java.text.DecimalFormat ; 24 import java.text.ParseException ; 25 import java.util.Locale ; 26 27 28 40 41 public class DecimalLocaleConverter extends BaseLocaleConverter { 42 43 44 46 47 private static Log log = LogFactory.getLog(DecimalLocaleConverter.class); 48 49 51 59 public DecimalLocaleConverter() { 60 61 this(false); 62 } 63 64 72 public DecimalLocaleConverter(boolean locPattern) { 73 74 this(Locale.getDefault(), locPattern); 75 } 76 77 84 public DecimalLocaleConverter(Locale locale) { 85 86 this(locale, false); 87 } 88 89 97 public DecimalLocaleConverter(Locale locale, boolean locPattern) { 98 99 this(locale, (String ) null, locPattern); 100 } 101 102 110 public DecimalLocaleConverter(Locale locale, String pattern) { 111 112 this(locale, pattern, false); 113 } 114 115 124 public DecimalLocaleConverter(Locale locale, String pattern, boolean locPattern) { 125 126 this(null, locale, pattern, locPattern); 127 } 128 129 138 public DecimalLocaleConverter(Object defaultValue) { 139 140 this(defaultValue, false); 141 } 142 143 152 public DecimalLocaleConverter(Object defaultValue, boolean locPattern) { 153 154 this(defaultValue, Locale.getDefault(), locPattern); 155 } 156 157 165 public DecimalLocaleConverter(Object defaultValue, Locale locale) { 166 167 this(defaultValue, locale, false); 168 } 169 170 179 public DecimalLocaleConverter(Object defaultValue, Locale locale, boolean locPattern) { 180 181 this(defaultValue, locale, null, locPattern); 182 } 183 184 193 public DecimalLocaleConverter(Object defaultValue, Locale locale, String pattern) { 194 195 this(defaultValue, locale, pattern, false); 196 } 197 198 208 public DecimalLocaleConverter(Object defaultValue, Locale locale, String pattern, boolean locPattern) { 209 210 super(defaultValue, locale, pattern, locPattern); 211 212 } 213 214 216 226 protected Object parse(Object value, String pattern) throws ParseException { 227 DecimalFormat formatter = (DecimalFormat ) DecimalFormat.getInstance(locale); 229 if (pattern != null) { 231 if (locPattern) { 232 formatter.applyLocalizedPattern(pattern); 233 } else { 234 formatter.applyPattern(pattern); 235 } 236 } else { 237 log.warn("No pattern provided, using default."); 238 } 239 240 return formatter.parse((String ) value); 241 } 242 } 243 | Popular Tags |