1 16 package org.apache.cocoon.forms.datatype.convertor; 17 18 import java.util.Locale ; 19 import java.text.DecimalFormat ; 20 import java.text.ParseException ; 21 22 32 public class FormattingIntegerConvertor extends FormattingDecimalConvertor { 33 34 public FormattingIntegerConvertor() { 35 super(); 36 } 37 38 public ConversionResult convertFromString(String value, Locale locale, Convertor.FormatCache formatCache) { 39 value = value.replace(' ', (char)160); 41 DecimalFormat decimalFormat = getDecimalFormat(locale, formatCache); 42 try { 43 Number decimalValue = decimalFormat.parse(value); 44 if (decimalValue instanceof Integer ) 45 return new ConversionResult(decimalValue); 46 else 47 return new ConversionResult(new Integer (decimalValue.intValue())); 48 } catch (ParseException e) { 49 return ConversionResult.create("integer"); 50 } 51 } 52 53 protected int getDefaultVariant() { 54 return INTEGER; 55 } 56 57 public Class getTypeClass() { 58 return Integer .class; 59 } 60 } 61 | Popular Tags |