/** * Returns localized format strings. * @param locale selected locale * @return {@link FormatStrings} object, or null if no formats are registered for the locale */ @Nullable public static FormatStrings getFormatStrings(Locale locale) { return getFormatStringsRegistry().getFormatStrings(locale); }
@Override public LocalDate parse(String value, Locale locale) throws ParseException { if (StringUtils.isBlank(value)) { return null; } FormatStrings formatStrings = AppBeans.get(FormatStringsRegistry.class).getFormatStrings(locale); if (formatStrings == null) { return parse(value); } DateTimeFormatter formatter = DateTimeFormatter.ofPattern(formatPattern); return LocalDate.parse(value.trim(), formatter); }
@Nullable public Date parse(@Nullable String value, Locale locale, TimeZone timeZone) throws ParseException { if (StringUtils.isBlank(value)) { return null; } FormatStrings formatStrings = AppBeans.get(FormatStringsRegistry.class).getFormatStrings(locale); if (formatStrings == null) { return parse(value); } DateFormat format = new SimpleDateFormat(formatStrings.getDateTimeFormat()); if (timeZone != null) { format.setTimeZone(timeZone); } return format.parse(value.trim()); }
@Override public Date parse(String value, Locale locale) throws ParseException { if (StringUtils.isBlank(value)) { return null; } FormatStrings formatStrings = AppBeans.get(FormatStringsRegistry.class).getFormatStrings(locale); if (formatStrings == null) { return parse(value); } DateFormat format = new SimpleDateFormat(formatStrings.getTimeFormat()); return format.parse(value.trim()); }
@Override public String format(@Nullable Object value, Locale locale, TimeZone timeZone) { if (value == null) { return ""; } FormatStrings formatStrings = AppBeans.get(FormatStringsRegistry.class).getFormatStrings(locale); if (formatStrings == null) { return format(value); } DateFormat format = new SimpleDateFormat(formatStrings.getDateTimeFormat()); if (timeZone != null) { format.setTimeZone(timeZone); } return format.format(value); }
@Override public String format(Object value, Locale locale) { if (value == null) { return ""; } FormatStrings formatStrings = AppBeans.get(FormatStringsRegistry.class).getFormatStrings(locale); if (formatStrings == null) { return format(value); } DateFormat format = new SimpleDateFormat(formatStrings.getDateFormat()); return format.format(value); }
@Override public String format(Object value, Locale locale) { if (value == null) { return ""; } FormatStrings formatStrings = AppBeans.get(FormatStringsRegistry.class).getFormatStrings(locale); if (formatStrings == null) { return format(value); } DateFormat format = new SimpleDateFormat(formatStrings.getTimeFormat()); format.setLenient(false); return format.format(value); }
@Override public Date parse(String value, Locale locale) throws ParseException { if (StringUtils.isBlank(value)) { return null; } FormatStrings formatStrings = AppBeans.get(FormatStringsRegistry.class).getFormatStrings(locale); if (formatStrings == null) { return parse(value); } DateFormat format = new SimpleDateFormat(formatStrings.getDateFormat()); format.setLenient(false); return normalize(format.parse(value.trim())); }
@Nullable @Override public T parse(@Nullable String value, Locale locale) throws ParseException { if (StringUtils.isBlank(value)) { return null; } FormatStrings formatStrings = AppBeans.get(FormatStringsRegistry.class).getFormatStrings(locale); if (formatStrings == null) { return parse(value); } DateTimeFormatter formatter = getDateTimeFormatter(formatStrings, locale); return formatter.parse(value.trim(), newInstance()); }
@Override public String format(@Nullable Object value, Locale locale) { if (value == null) { return ""; } FormatStrings formatStrings = AppBeans.get(FormatStringsRegistry.class).getFormatStrings(locale); if (formatStrings == null) { return format(value); } DateTimeFormatter formatter = getDateTimeFormatter(formatStrings, locale); //noinspection unchecked return formatter.format((TemporalAccessor) value); }
@Override public String format(Object value, Locale locale) { if (value == null) return ""; FormatStrings formatStrings = AppBeans.get(FormatStringsRegistry.class).getFormatStrings(locale); if (formatStrings == null) return format(value); DecimalFormatSymbols formatSymbols = formatStrings.getFormatSymbols(); NumberFormat format = new DecimalFormat(formatStrings.getIntegerFormat(), formatSymbols); return format.format(value); }
@Override public Integer parse(String value, Locale locale) throws ParseException { if (StringUtils.isBlank(value)) return null; FormatStrings formatStrings = AppBeans.get(FormatStringsRegistry.class).getFormatStrings(locale); if (formatStrings == null) return parse(value); DecimalFormatSymbols formatSymbols = formatStrings.getFormatSymbols(); NumberFormat format = new DecimalFormat(formatStrings.getIntegerFormat(), formatSymbols); return parse(value, format).intValue(); }
@Override public String format(Object value, Locale locale) { if (value == null) { return ""; } FormatStrings formatStrings = AppBeans.get(FormatStringsRegistry.class).getFormatStrings(locale); if (formatStrings == null) { return format(value); } DecimalFormatSymbols formatSymbols = formatStrings.getFormatSymbols(); NumberFormat format = new DecimalFormat(formatStrings.getDoubleFormat(), formatSymbols); return format.format(value); }
@Override public String format(Object value, Locale locale) { if (value == null) { return ""; } FormatStrings formatStrings = AppBeans.get(FormatStringsRegistry.class).getFormatStrings(locale); if (formatStrings == null) { return format(value); } DecimalFormatSymbols formatSymbols = formatStrings.getFormatSymbols(); NumberFormat format = new DecimalFormat(formatStrings.getIntegerFormat(), formatSymbols); return format.format(value); }
@Override public String format(Object value, Locale locale) { if (value == null) { return ""; } FormatStrings formatStrings = AppBeans.get(FormatStringsRegistry.class).getFormatStrings(locale); if (formatStrings == null) { return format(value); } DecimalFormatSymbols formatSymbols = formatStrings.getFormatSymbols(); NumberFormat format = new DecimalFormat(formatStrings.getDecimalFormat(), formatSymbols); return format.format(value); }
@Override public Long parse(String value, Locale locale) throws ParseException { if (StringUtils.isBlank(value)) { return null; } FormatStrings formatStrings = AppBeans.get(FormatStringsRegistry.class).getFormatStrings(locale); if (formatStrings == null) { return parse(value); } DecimalFormatSymbols formatSymbols = formatStrings.getFormatSymbols(); NumberFormat format = new DecimalFormat(formatStrings.getIntegerFormat(), formatSymbols); return parse(value, format).longValue(); }
@Override public Double parse(String value, Locale locale) throws ParseException { if (StringUtils.isBlank(value)) { return null; } FormatStrings formatStrings = AppBeans.get(FormatStringsRegistry.class).getFormatStrings(locale); if (formatStrings == null) { return parse(value); } DecimalFormatSymbols formatSymbols = formatStrings.getFormatSymbols(); NumberFormat format = new DecimalFormat(formatStrings.getDoubleFormat(), formatSymbols); return parse(value, format).doubleValue(); }
private FormatStrings getFormatStrings() { UserSessionSource userSessionSource = AppBeans.get(UserSessionSource.NAME); FormatStringsRegistry formatStringsRegistry = AppBeans.get(FormatStringsRegistry.NAME); return formatStringsRegistry.getFormatStrings(userSessionSource.getLocale()); }
@Override public Boolean parse(String value, Locale locale) throws ParseException { if (StringUtils.isBlank(value)) { return null; } FormatStrings formatStrings = AppBeans.get(FormatStringsRegistry.class).getFormatStrings(locale); if (formatStrings == null) { return parse(value); } return parse(value, formatStrings.getTrueString(), formatStrings.getFalseString()); }
@Override public String format(Object value, Locale locale) { if (value == null) { return ""; } FormatStrings formatStrings = AppBeans.get(FormatStringsRegistry.class).getFormatStrings(locale); if (formatStrings == null) { return format(value); } return (boolean) value ? formatStrings.getTrueString() : formatStrings.getFalseString(); }