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 31 public class FormattingLongConvertor extends FormattingDecimalConvertor { 32 33 public FormattingLongConvertor() { 34 super(); 35 } 36 37 public ConversionResult convertFromString(String value, Locale locale, Convertor.FormatCache formatCache) { 38 value = value.replace(' ', (char)160); 40 DecimalFormat decimalFormat = getDecimalFormat(locale, formatCache); 41 try { 42 Number decimalValue = decimalFormat.parse(value); 43 if (decimalValue instanceof Long ) 44 return new ConversionResult(decimalValue); 45 else 46 return new ConversionResult(new Long (decimalValue.longValue())); 47 } catch (ParseException e) { 48 return ConversionResult.create("long"); 49 } 50 } 51 52 protected int getDefaultVariant() { 53 return INTEGER; 54 } 55 56 public Class getTypeClass() { 57 return Long .class; 58 } 59 } 60 | Popular Tags |