private void initDefaultFormats() { FormatStrings formatStrings = getFormatStrings(); setDateFormat(formatStrings.getDateFormat()); setBooleanTrueValue(formatStrings.getTrueString()); setBooleanFalseValue(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); DecimalFormatSymbols formatSymbols = formatStrings.getFormatSymbols(); NumberFormat format = new DecimalFormat(formatStrings.getIntegerFormat(), formatSymbols); return format.format(value); }
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); } DecimalFormatSymbols formatSymbols = formatStrings.getFormatSymbols(); NumberFormat format = new DecimalFormat(formatStrings.getDoubleFormat(), formatSymbols); return format.format(value); }
@Override protected DateTimeFormatter getDateTimeFormatter(FormatStrings formatStrings, Locale locale) { return DateTimeFormatter.ofPattern(formatStrings.getDateFormat(), locale); }
private Object tryNumber(String value) { UserSessionSource userSession = AppBeans.get(UserSessionSource.NAME); FormatStrings formatStrings = Datatypes.getFormatStrings(userSession.getLocale()); char decimalSeparator = formatStrings.getFormatSymbols().getDecimalSeparator(); char groupingSeparator = formatStrings.getFormatSymbols().getGroupingSeparator(); if (decimalSeparator != '.') value = value.replace(decimalSeparator, '.'); if (groupingSeparator != ',') value = value.replace(groupingSeparator, ','); if (!Character.isDigit(value.charAt(0)) || value.startsWith("0")) return null; try { Number number = new BigDecimal(value); return number; } catch (NumberFormatException e) { return null; } } }
@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 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 protected DateTimeFormatter getDateTimeFormatter(FormatStrings formatStrings, Locale locale) { return DateTimeFormatter.ofPattern(formatStrings.getDateTimeFormat(), locale); }
@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(); }
@Override protected DateTimeFormatter getDateTimeFormatter(FormatStrings formatStrings, Locale locale) { return DateTimeFormatter.ofPattern(formatStrings.getTimeFormat(), locale); }
@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); }
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; }
@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(); }
@Override public BigDecimal 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(); DecimalFormat format = new DecimalFormat(formatStrings.getDecimalFormat(), formatSymbols); format.setParseBigDecimal(true); return (BigDecimal) parse(value, format); }
@Override protected DateTimeFormatter getDateTimeFormatter(FormatStrings formatStrings, Locale locale) { return DateTimeFormatter.ofPattern(formatStrings.getDateTimeFormat(), locale).withZone(ZoneId.systemDefault()); }
@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 protected DateTimeFormatter getDateTimeFormatter(FormatStrings formatStrings, Locale locale) { return DateTimeFormatter.ofPattern(formatStrings.getTimeFormat(), locale); }
switch (type) { case "DATE": format = formatStrings.getDateFormat(); break; case "DATETIME": format = formatStrings.getDateTimeFormat(); break; default:
@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())); }