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