private Object tryDate(String value) { UserSessionSource userSession = AppBeans.get(UserSessionSource.NAME); FormatStrings formatStrings = Datatypes.getFormatStrings(userSession.getLocale()); SimpleDateFormat sdf = new SimpleDateFormat(formatStrings.getDateFormat()); try { Date date = sdf.parse(value); return date; } catch (ParseException e) { return null; } }
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 String apply(Number value) { if (value == null) { return null; } String pattern = element != null ? element.attributeValue("format") : null; if (pattern == null) { Datatype datatype = Datatypes.getNN(value.getClass()); return datatype.format(value, userSessionSource.getLocale()); } else { if (pattern.startsWith("msg://")) { pattern = messages.getMainMessage(pattern.substring(6, pattern.length())); } FormatStrings formatStrings = Datatypes.getFormatStrings(userSessionSource.getLocale()); if (formatStrings == null) throw new IllegalStateException("FormatStrings are not defined for " + userSessionSource.getLocale()); DecimalFormat format = new DecimalFormat(pattern, formatStrings.getFormatSymbols()); return format.format(value); } } }
String type = element.attributeValue("type"); if (type != null) { FormatStrings formatStrings = Datatypes.getFormatStrings(userSessionSource.getLocale()); if (formatStrings == null) throw new IllegalStateException("FormatStrings are not defined for " + userSessionSource.getLocale());
FormatStrings formatStrings = Datatypes.getFormatStrings(locale);
protected void setupFormatStrings(List<StockPanel> panels) { FormatStrings formatStrings = Datatypes.getFormatStrings(userSessionSource.getLocale()); if (formatStrings != null) { for (StockPanel panel : panels) { DecimalFormatSymbols formatSymbols = formatStrings.getFormatSymbols(); if (panel.getPrecision() == null) { panel.setPrecision(-1); } if (panel.getPercentPrecision() == null) { panel.setPercentPrecision(2); } if (panel.getDecimalSeparator() == null) { panel.setDecimalSeparator(Character.toString(formatSymbols.getDecimalSeparator())); } if (panel.getThousandsSeparator() == null) { panel.setThousandsSeparator(Character.toString(formatSymbols.getGroupingSeparator())); } } } }
protected void setupChartLocale(AbstractChart chart) { chart.setLanguage(messages.getTools().localeToString(userSessionSource.getLocale())); // number formatting FormatStrings formatStrings = Datatypes.getFormatStrings(userSessionSource.getLocale()); if (formatStrings != null) { DecimalFormatSymbols formatSymbols = formatStrings.getFormatSymbols(); chart.setPrecision(-1); chart.setPercentPrecision(2); chart.setDecimalSeparator(Character.toString(formatSymbols.getDecimalSeparator())); chart.setThousandsSeparator(Character.toString(formatSymbols.getGroupingSeparator())); } // number prefixes List<BigNumberPrefix> bigPrefixes = new ArrayList<>(); for (BigNumberPower power : BigNumberPower.values()) { bigPrefixes.add(new BigNumberPrefix(power, messages.getMainMessage("amcharts.bigNumberPower." + power.name()))); } chart.setPrefixesOfBigNumbers(bigPrefixes); List<SmallNumberPrefix> smallPrefixes = new ArrayList<>(); for (SmallNumberPower power : SmallNumberPower.values()) { smallPrefixes.add(new SmallNumberPrefix(power, messages.getMainMessage("amcharts.smallNumberPower." + power.name()))); } chart.setPrefixesOfSmallNumbers(smallPrefixes); }
FormatStrings formatStrings = Datatypes.getFormatStrings(userSessionSource.getLocale()); if (formatStrings != null) { DecimalFormatSymbols formatSymbols = formatStrings.getFormatSymbols();