List of usage examples for org.apache.commons.beanutils.locale LocaleConvertUtilsBean LocaleConvertUtilsBean
public LocaleConvertUtilsBean()
From source file:com.opencsv.bean.BeanFieldPrimitiveTypes.java
@Override protected Object convert(String value) throws CsvDataTypeMismatchException, CsvRequiredFieldEmptyException { if (required && StringUtils.isBlank(value)) { throw new CsvRequiredFieldEmptyException( String.format("Field '%s' is mandatory but no value was provided.", field.getName())); }/*from w w w .j a v a2 s. co m*/ Object o = null; if (StringUtils.isNotBlank(value)) { try { if (StringUtils.isEmpty(locale)) { ConvertUtilsBean converter = new ConvertUtilsBean(); converter.register(true, false, 0); o = converter.convert(value, field.getType()); } else { LocaleConvertUtilsBean lcub = new LocaleConvertUtilsBean(); lcub.setDefaultLocale(new Locale(locale)); o = lcub.convert(value, field.getType()); } } catch (ConversionException e) { CsvDataTypeMismatchException csve = new CsvDataTypeMismatchException(value, field.getType(), "Conversion of " + value + " to " + field.getType().getCanonicalName() + " failed."); csve.initCause(e); throw csve; } } return o; }
From source file:com.opencsv.bean.BeanFieldPrimitiveTypes.java
/** * This method takes the current value of the field in question in the bean * passed in and converts it to a string. * It works for all of the primitives, wrapped primitives, * {@link java.lang.String}, {@link java.math.BigDecimal}, and * {@link java.math.BigInteger}./*from w w w.jav a 2 s. c o m*/ * * @throws CsvDataTypeMismatchException If there is an error converting * value to a string */ // The rest of the JavaDoc is automatically inherited from the base class. @Override protected String convertToWrite(Object value) throws CsvDataTypeMismatchException, CsvRequiredFieldEmptyException { // Validation if (value == null) { if (required) { throw new CsvRequiredFieldEmptyException(); } else { return null; } } // Conversion String result; try { if (StringUtils.isEmpty(locale)) { ConvertUtilsBean converter = new ConvertUtilsBean(); result = converter.convert(value); } else { LocaleConvertUtilsBean converter = new LocaleConvertUtilsBean(); converter.setDefaultLocale(new Locale(locale)); result = converter.convert(value); } } catch (ConversionException e) { CsvDataTypeMismatchException csve = new CsvDataTypeMismatchException( "The field must be primitive, boxed primitive, BigDecimal, BigInteger or String types only."); csve.initCause(e); throw csve; } return result; }
From source file:net.sf.jasperreports.engine.data.JRAbstractTextDataSource.java
protected LocaleConvertUtilsBean getConvertBean() { if (convertBean == null) { convertBean = new LocaleConvertUtilsBean(); Locale locale = textAttributes.getLocale(); if (locale != null) { convertBean.setDefaultLocale(locale); convertBean.deregister();// ww w. j av a 2 s . com //convertBean.lookup(); } convertBean.register(new JRDateLocaleConverter(textAttributes.getTimeZone()), java.util.Date.class, locale); } return convertBean; }
From source file:com.itelis.worker.dev.template.service.JRXmlDataSource.java
protected LocaleConvertUtilsBean getConvertBean() { if (convertBean == null) { convertBean = new LocaleConvertUtilsBean(); if (locale != null) { convertBean.setDefaultLocale(locale); convertBean.deregister();/* www .j a v a 2 s . c o m*/ // convertBean.lookup(); } convertBean.register(new JRDateLocaleConverter(timeZone), java.util.Date.class, locale); } return convertBean; }
From source file:org.jasper.collectionspace.smk.datasource.JsonCSDataSource.java
protected LocaleConvertUtilsBean getConvertBean() { if (convertBean == null) { convertBean = new LocaleConvertUtilsBean(); if (locale != null) { convertBean.setDefaultLocale(locale); convertBean.deregister();/*from w ww. jav a 2 s . c om*/ //convertBean.lookup(); } convertBean.register(new JRDateLocaleConverter(timeZone), java.util.Date.class, locale); // fix for https://issues.apache.org/jira/browse/BEANUTILS-351 // remove on upgrade to BeanUtils 1.8.1 JRFloatLocaleConverter floatConverter = new JRFloatLocaleConverter( locale == null ? Locale.getDefault() : locale); convertBean.register(floatConverter, Float.class, locale); convertBean.register(floatConverter, Float.TYPE, locale); } return convertBean; }