if (LOCALE_KEY.equals(name)) { if (JVM_DEFAULT.equalsIgnoreCase(value)) { setLocale(Locale.getDefault()); } else { setLocale(StringUtil.deduceLocale(value)); setNumberFormat(value); } else if (CUSTOM_NUMBER_FORMATS_KEY_SNAKE_CASE.equals(name) || CUSTOM_NUMBER_FORMATS_KEY_CAMEL_CASE.equals(name)) { _CoreAPI.checkSettingValueItemsType("Map keys", String.class, map.keySet()); _CoreAPI.checkSettingValueItemsType("Map values", TemplateNumberFormatFactory.class, map.values()); setCustomNumberFormats(map); } else if (TIME_FORMAT_KEY_SNAKE_CASE.equals(name) || TIME_FORMAT_KEY_CAMEL_CASE.equals(name)) { setTimeFormat(value); } else if (DATE_FORMAT_KEY_SNAKE_CASE.equals(name) || DATE_FORMAT_KEY_CAMEL_CASE.equals(name)) { setDateFormat(value); } else if (DATETIME_FORMAT_KEY_SNAKE_CASE.equals(name) || DATETIME_FORMAT_KEY_CAMEL_CASE.equals(name)) { setDateTimeFormat(value); } else if (CUSTOM_DATE_FORMATS_KEY_SNAKE_CASE.equals(name) || CUSTOM_DATE_FORMATS_KEY_CAMEL_CASE.equals(name)) { _CoreAPI.checkSettingValueItemsType("Map keys", String.class, map.keySet()); _CoreAPI.checkSettingValueItemsType("Map values", TemplateDateFormatFactory.class, map.values()); setCustomDateFormats(map); } else if (TIME_ZONE_KEY_SNAKE_CASE.equals(name) || TIME_ZONE_KEY_CAMEL_CASE.equals(name)) { setTimeZone(parseTimeZoneSettingValue(value)); } else if (SQL_DATE_AND_TIME_TIME_ZONE_KEY_SNAKE_CASE.equals(name) || SQL_DATE_AND_TIME_TIME_ZONE_KEY_CAMEL_CASE.equals(name)) {
@Override public Object clone() { try { Configuration copy = (Configuration) super.clone(); copy.sharedVariables = new HashMap(sharedVariables); copy.localeToCharsetMap = new ConcurrentHashMap(localeToCharsetMap); copy.recreateTemplateCacheWith( cache.getTemplateLoader(), cache.getCacheStorage(), cache.getTemplateLookupStrategy(), cache.getTemplateNameFormat(), cache.getTemplateConfigurations()); return copy; } catch (CloneNotSupportedException e) { throw new BugException("Cloning failed", e); } }
/** * Executes the auto-imports and auto-includes for the main template of this environment. * This is not meant to be called or overridden by code outside of FreeMarker. */ protected void doAutoImportsAndIncludes(Environment env) throws TemplateException, IOException { if (parent != null) parent.doAutoImportsAndIncludes(env); }
/** * Creates the exception that should be thrown when a setting name isn't recognized. */ protected TemplateException unknownSettingException(String name) { return new UnknownSettingException( getEnvironment(), name, getCorrectedNameForUnknownSetting(name)); }
try { if (LOCALE_KEY.equals(key)) { setLocale(StringUtil.deduceLocale(value)); } else if (NUMBER_FORMAT_KEY.equals(key)) { setNumberFormat(value); } else if (TIME_FORMAT_KEY.equals(key)) { setTimeFormat(value); } else if (DATE_FORMAT_KEY.equals(key)) { setDateFormat(value); } else if (DATETIME_FORMAT_KEY.equals(key)) { setDateTimeFormat(value); } else if (TIME_ZONE_KEY.equals(key)) { setTimeZone(TimeZone.getTimeZone(value)); } else if (CLASSIC_COMPATIBLE_KEY.equals(key)) { setClassicCompatible(StringUtil.getYesNo(value)); } else if (TEMPLATE_EXCEPTION_HANDLER_KEY.equals(key)) { if (value.indexOf('.') == -1) { if ("debug".equalsIgnoreCase(value)) { setTemplateExceptionHandler( TemplateExceptionHandler.DEBUG_HANDLER); } else if ("html_debug".equalsIgnoreCase(value)) { setTemplateExceptionHandler( TemplateExceptionHandler.HTML_DEBUG_HANDLER); } else if ("ignore".equalsIgnoreCase(value)) { setTemplateExceptionHandler( TemplateExceptionHandler.IGNORE_HANDLER); } else if ("rethrow".equalsIgnoreCase(value)) { setTemplateExceptionHandler( TemplateExceptionHandler.RETHROW_HANDLER);
/** * Gets the value of a {@link Template}-scope attribute from the given {@link Template}. * * @throws UnsupportedOperationException * If this custom attribute has different scope than {@link #SCOPE_TEMPLATE}. * @throws NullPointerException * If {@code template} is null */ public final Object get(Template template) { if (scope != SCOPE_TEMPLATE) { throw new UnsupportedOperationException("This is not a template-scope attribute"); } return ((Configurable) template).getCustomAttribute(key, this); }
@Override public void setOutputEncoding(String outputEncoding) { cachedURLEscapingCharsetSet = false; super.setOutputEncoding(outputEncoding); }
/** * @since 2.3.21 */ protected TemplateException settingValueAssignmentException(String name, String value, Throwable cause) { return new SettingValueAssignmentException(getEnvironment(), name, value, cause); }
/** * The getter pair of {@link #setBooleanFormat(String)}. */ public String getBooleanFormat() { return booleanFormat != null ? booleanFormat : parent.getBooleanFormat(); }
/** * The getter pair of {@link #setArithmeticEngine(ArithmeticEngine)}. */ public ArithmeticEngine getArithmeticEngine() { return arithmeticEngine != null ? arithmeticEngine : parent.getArithmeticEngine(); }
/** * The getter pair of {@link #setDateTimeFormat(String)}. */ public String getDateTimeFormat() { return dateTimeFormat != null ? dateTimeFormat : parent.getDateTimeFormat(); }
/** * The getter pair of {@link #setDateFormat(String)}. */ public String getDateFormat() { return dateFormat != null ? dateFormat : parent.getDateFormat(); }
/** * See {@link #setAutoFlush(boolean)} * * @since 2.3.17 */ public boolean getAutoFlush() { return autoFlush != null ? autoFlush.booleanValue() : (parent != null ? parent.getAutoFlush() : true); }
/** * Gets the value of a {@link Configuration}-scope attribute from the given {@link Configuration}. * * @throws UnsupportedOperationException * If this custom attribute has different scope than {@link #SCOPE_CONFIGURATION}. * @throws NullPointerException * If {@code cfg} is null * * @since 2.3.22 */ public final Object get(Configuration cfg) { if (scope != SCOPE_CONFIGURATION) { throw new UnsupportedOperationException("This is not a template-scope attribute"); } return ((Configurable) cfg).getCustomAttribute(key, this); }
@Override public void setOutputEncoding(String outputEncoding) { cachedURLEscapingCharsetSet = false; super.setOutputEncoding(outputEncoding); }
/** * Creates the exception that should be thrown when a setting name isn't recognized. */ protected TemplateException unknownSettingException(String name) { return new UnknownSettingException( getEnvironment(), name, getCorrectedNameForUnknownSetting(name)); }
protected TemplateException invalidSettingValueException(String name, String value) { return new _MiscTemplateException(getEnvironment(), "Invalid value for setting ", new _DelayedJQuote(name), ": ", new _DelayedJQuote(value)); }
private _ErrorDescriptionBuilder getNullBooleanFormatErrorDescription() { return new _ErrorDescriptionBuilder( "Can't convert boolean to string automatically, because the \"", BOOLEAN_FORMAT_KEY ,"\" setting was ", new _DelayedJQuote(getBooleanFormat()), (getBooleanFormat().equals(C_TRUE_FALSE) ? ", which is the legacy default computer-language format, and hence isn't accepted." : ".") ).tips( "If you just want \"true\"/\"false\" result as you are generting computer-language output, " + "use \"?c\", like ${myBool?c}.", "You can write myBool?string('yes', 'no') and like to specify boolean formatting in place.", new Object[] { "If you need the same two values on most places, the programmers should set the \"", BOOLEAN_FORMAT_KEY ,"\" setting to something like \"yes,no\"." } ); }
/** * The getter pair of {@link #setArithmeticEngine(ArithmeticEngine)}. */ public ArithmeticEngine getArithmeticEngine() { return arithmeticEngine != null ? arithmeticEngine : parent.getArithmeticEngine(); }
/** * The getter pair of {@link #setDateTimeFormat(String)}. */ public String getDateTimeFormat() { return dateTimeFormat != null ? dateTimeFormat : parent.getDateTimeFormat(); }