@SuppressWarnings("unchecked") public AbstractTemplate( Engine engine, Filter filter, Formatter<?> formatter, Map<Class<?>, Object> functions, Map<String, Template> importMacros) { this.engine = engine; this.filter = filter; this.formatter = (Formatter<Object>) formatter; this.importMacros = importMacros; this.macros = initMacros(engine, filter, formatter, functions, importMacros); if (formatter instanceof MultiFormatter) { MultiFormatter multi = (MultiFormatter) formatter; this.numberFormatter = multi.get(Number.class); this.booleanFormatter = multi.get(Boolean.class); this.byteFormatter = getFormatter(multi, Byte.class, numberFormatter); this.charFormatter = multi.get(Character.class); this.shortFormatter = getFormatter(multi, Short.class, numberFormatter); this.intFormatter = getFormatter(multi, Integer.class, numberFormatter); this.longFormatter = getFormatter(multi, Long.class, numberFormatter); this.floatFormatter = getFormatter(multi, Float.class, numberFormatter); this.doubleFormatter = getFormatter(multi, Double.class, numberFormatter); this.dateFormatter = multi.get(Date.class); } else { this.numberFormatter = null; this.booleanFormatter = null; this.byteFormatter = null; this.charFormatter = null; this.shortFormatter = null; this.intFormatter = null; this.longFormatter = null; this.floatFormatter = null; this.doubleFormatter = null; this.dateFormatter = null; } this.nullValue = engine.getProperty(NULL_VALUE, ""); this.trueValue = engine.getProperty(TRUE_VALUE, "true"); this.falseValue = engine.getProperty(FALSE_VALUE, "false"); this.outputEncoding = engine.getProperty(OUTPUT_ENCODING); this.outputCharset = outputEncoding == null || outputEncoding.length() == 0 ? null : Charset.forName(outputEncoding); }
@SuppressWarnings("unchecked") private static Formatter<Number> getFormatter( MultiFormatter multi, Class<? extends Number> type, Formatter<Number> defaultFormatter) { Formatter<Number> formatter = multi.get((Class<Number>) type); if (formatter == null) { return defaultFormatter; } return formatter; }