List of usage examples for org.apache.commons.beanutils.locale.converters DateLocaleConverter DateLocaleConverter
public DateLocaleConverter(Object defaultValue, Locale locale)
From source file:com.opencsv.bean.ColumnPositionMappingStrategyTest.java
@Before public void setUp() throws Exception { strat = new ColumnPositionMappingStrategy<>(); strat.setType(WXTradeItem.class); // java.utils.Date? ConvertUtils.register(new DateLocaleConverter(Locale.getDefault(), "yyyy-MM-dd HH:mm:ss"), Date.class); }
From source file:com.feilong.commons.core.bean.BeanUtilTest.java
/** * Copy property./*ww w .ja v a 2 s . c om*/ */ @Test public void copyProperty() { User a = new User(); a.setId(5L); a.setMoney(new BigDecimal(500000)); a.setDate(new Date()); User b = new User(); // DateConverter converter = new DateConverter(DatePattern.forToString, Locale.US); ConvertUtils.register(new DateLocaleConverter(Locale.US, DatePattern.forToString), Date.class); String[] strs = { "date", "money" }; BeanUtil.copyProperties(b, a, strs); log.info(b.getDate() + ""); log.info(b.getMoney() + ""); }
From source file:com.feilong.core.bean.BeanUtilTest.java
/** * Copy property.// ww w. j a v a2 s . co m */ @Test public void testCopyProperties1() { User user = new User(); user.setId(5L); user.setMoney(new BigDecimal(500000)); user.setDate(new Date()); user.setNickNames(toArray("feilong", "", "venusdrogon")); // ConvertUtils.register(new DateLocaleConverter(Locale.US, TO_STRING_STYLE), Date.class); BeanUtil.register(new DateLocaleConverter(Locale.US, TO_STRING_STYLE), Date.class); Converter converter = ConvertUtils.lookup(Date.class); LOGGER.debug("{},{}", converter.getClass().getSimpleName(), converter.convert(Date.class, new Date().toString())); User user2 = new User(); BeanUtil.copyProperties(user2, user, "date", "money", "nickNames"); LOGGER.debug(JsonUtil.format(user2)); converter = ConvertUtils.lookup(Date.class); LOGGER.debug("{},{}", converter.getClass().getSimpleName(), converter.convert(Date.class, new Date().toString())); }
From source file:com.feilong.commons.core.bean.BeanUtilTest.java
/** * Copy properties.//from ww w. j av a2s. c o m */ @Test public void copyProperties() { User a = new User(); a.setId(5L); a.setDate(new Date()); String[] nickName = { "feilong", "", "venusdrogon" }; a.setNickName(nickName); User b = new User(); String[] aStrings = { "date", "id", "nickName" }; ConvertUtils.register(new DateLocaleConverter(Locale.US, DatePattern.forToString), Date.class); BeanUtil.copyProperties(b, a, aStrings); if (log.isDebugEnabled()) { log.debug(JsonUtil.format(b)); } }
From source file:org.modelibra.util.Transformer.java
/** * Transforms a date text with a pattern into a Date object, if the text is * date./*from w w w .ja va 2 s . c o m*/ * * @param date * date text * @param datePattern * date pattern * @return Date object if date is valid, TypeRuntimeException otherwise */ public static Date date(String date, String datePattern) { try { Locale locale = Locale.getDefault(); DateLocaleConverter converter = new DateLocaleConverter(locale, datePattern); // It does not accept dates with months greater than 12 and days // greater than 31. // It accepts years greater than the current year. converter.convert(date, datePattern); SimpleDateFormat formatter = new SimpleDateFormat(datePattern, locale); return formatter.parse(date); } catch (ParseException e) { throw new TypeRuntimeException(e); } catch (ConversionException e) { throw new TypeRuntimeException(e); } }
From source file:org.modelibra.util.Validator.java
/** * Validates a date./* w w w .java2 s. c om*/ * * @param date * date * @param datePattern * date pattern * @return <code>true</code> if date is valid. */ public static boolean date(String date, String datePattern) { boolean result = false; try { // String datePattern = "yyyy-MM-dd"; Locale locale = Locale.getDefault(); DateLocaleConverter converter = new DateLocaleConverter(locale, datePattern); // It does not accept dates with months greater than 12 and days // greater // than 31. // It accepts years greater than the current year. converter.convert(date, datePattern); result = true; } catch (RuntimeException e) { return false; } return result; }
From source file:org.waterforpeople.mapping.app.util.DtoMarshaller.java
/** * sets up the converters that this marshaller should use *///from www. java 2s . c o m private static void configureConverters() { String pattern = "MM/dd/yy"; Locale locale = Locale.getDefault(); DateLocaleConverter converter = new DateLocaleConverter(locale, pattern); converter.setLenient(true); ConvertUtils.register(converter, java.util.Date.class); TypeEnumConverter enumConverter = new TypeEnumConverter(); ConvertUtils.register(enumConverter, Question.Type.class); ConvertUtils.register(enumConverter, QuestionDto.QuestionType.class); ConvertUtils.register(enumConverter, AccessPoint.Status.class); ConvertUtils.register(enumConverter, AccessPoint.AccessPointType.class); ConvertUtils.register(enumConverter, UnitOfMeasure.UnitOfMeasureSystem.class); ConvertUtils.register(enumConverter, UnitOfMeasure.UnitOfMeasureType.class); ConvertUtils.register(enumConverter, QuestionHelpMedia.Type.class); ConvertUtils.register(enumConverter, QuestionHelpDto.Type.class); ConvertUtils.register(enumConverter, OGRFeatureDto.FeatureType.class); ConvertUtils.register(enumConverter, Survey.Status.class); ConvertUtils.register(enumConverter, Survey.Sector.class); // Resetting default values from zero to null ConvertUtils.register(new DoubleConverter(null), Double.class); ConvertUtils.register(new LongConverter(null), Long.class); ConvertUtils.register(new IntegerConverter(null), Integer.class); DatastoreTextConverter textConverter = new DatastoreTextConverter(); ConvertUtils.register(textConverter, Text.class); ConvertUtils.register(textConverter, String.class); }