/** * 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); }
/** * Returns localized format strings. * @param locale selected locale * @return {@link FormatStrings} object. Throws exception if not found. */ @Nonnull public static FormatStrings getFormatStringsNN(Locale locale) { return getFormatStringsRegistry().getFormatStringsNN(locale); }
"Check cuba.mainMessagePack application property, it must point to a valid set of main message packs."); formatStringsRegistry.setFormatStrings( messageTools.trimLocale(locale), new FormatStrings(
@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); }
@Override public void afterPropertiesSet() { UserSessionSource userSessionSource = beanLocator.get(UserSessionSource.NAME); FormatStringsRegistry formatStringsRegistry = beanLocator.get(FormatStringsRegistry.NAME); String timeFormat = formatStringsRegistry.getFormatStringsNN(userSessionSource.getLocale()).getTimeFormat(); setFormat(timeFormat); }
@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 void afterPropertiesSet() { UserSessionSource userSessionSource = beanLocator.get(UserSessionSource.class); Locale locale = userSessionSource.getLocale(); FormatStringsRegistry formatStringsRegistry = beanLocator.get(FormatStringsRegistry.NAME); dateField.setDateFormat(formatStringsRegistry.getFormatStringsNN(locale).getDateFormat()); dateField.setResolution(DateResolution.DAY); timeField.setTimeFormat(formatStringsRegistry.getFormatStringsNN(locale).getTimeFormat()); setResolution(Resolution.MIN); AppUI ui = AppUI.getCurrent(); if (ui != null && ui.isTestMode()) { timeField.setCubaId("timepart"); dateField.setCubaId("datepart"); } }
@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()); }
public Properties getFreeMarkerSettings() { GlobalConfig globalConfig = configuration.getConfig(GlobalConfig.class); Map<String, Locale> availableLocales = globalConfig.getAvailableLocales(); if (availableLocales.isEmpty()) { throw new IllegalStateException("Property cuba.availableLocales is not configured"); } Locale locale = availableLocales.values().iterator().next(); FormatStrings formatStrings = formatStringsRegistry.getFormatStrings(locale); final Properties freemarkerSettings = new Properties(); freemarkerSettings.setProperty("number_format", "#"); freemarkerSettings.setProperty("datetime_format", formatStrings.getDateTimeFormat()); freemarkerSettings.setProperty("date_format", formatStrings.getDateFormat()); freemarkerSettings.setProperty("template_exception_handler", "rethrow"); return freemarkerSettings; } }
@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(@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.getTimeFormat()); format.setLenient(false); return format.format(value); }
@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 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())); }
@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.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); }
protected java.text.NumberFormat createLocalizedFormat(Locale locale) { FormatStrings formatStrings = AppBeans.get(FormatStringsRegistry.class).getFormatStrings(locale); if (formatStrings == null) { return createFormat(); } DecimalFormatSymbols formatSymbols = formatStrings.getFormatSymbols(); if (!decimalSeparator.equals("")) { formatSymbols.setDecimalSeparator(decimalSeparator.charAt(0)); } if (!groupingSeparator.equals("")) { formatSymbols.setGroupingSeparator(groupingSeparator.charAt(0)); } DecimalFormat format = new DecimalFormat(formatPattern, formatSymbols); setupFormat(format); return format; }