Class FreemarkerConfigurationImpl

  • All Implemented Interfaces:
    freemarker.core.ParserConfiguration, Cloneable

    public class FreemarkerConfigurationImpl
    extends freemarker.template.Configuration
    Extend the Freemarker Configuration class to include some information that is particular to the current request. A reference to the current request is not always available to the Freemarker Configuration, so we take advantage of the fact that each request runs in a separate thread, and store a reference to that request in a ThreadLocal object. Then, we override any methods that should return that request-based information instead of (or in addition to) the common info. Only the getters are overridden, not the setters. So if you call setAllSharedVariables(), for example, it will have no effect on the request-based information. Notice that the reference to the current request is actually stored through a WeakReference. This is because the ThreadLocal will not be cleared when the webapp is stopped, so none of the references from that ThreadLocal are eligible for garbage collection. If any of those references is an instance of a class that is loaded by the webapp, then the webapp ClassLoader is not eligible for garbage collection. This would be a huge memory leak. Thanks to the WeakReference, the request is eligible for garbage collection if nothing else refers to it. In theory, this means that the WeakReference could return a null, but if the garbage collector has taken the request, then who is invoking this object?
    • Nested Class Summary

      • Nested classes/interfaces inherited from class freemarker.core.Configurable

        freemarker.core.Configurable.SettingValueAssignmentException, freemarker.core.Configurable.UnknownSettingException
    • Field Summary

      • Fields inherited from class freemarker.template.Configuration

        ANGLE_BRACKET_TAG_SYNTAX, AUTO_DETECT_NAMING_CONVENTION, AUTO_DETECT_TAG_SYNTAX, AUTO_ESCAPING_POLICY_KEY, AUTO_ESCAPING_POLICY_KEY_CAMEL_CASE, AUTO_ESCAPING_POLICY_KEY_SNAKE_CASE, AUTO_IMPORT_KEY, AUTO_IMPORT_KEY_CAMEL_CASE, AUTO_IMPORT_KEY_SNAKE_CASE, AUTO_INCLUDE_KEY, AUTO_INCLUDE_KEY_CAMEL_CASE, AUTO_INCLUDE_KEY_SNAKE_CASE, CACHE_STORAGE_KEY, CACHE_STORAGE_KEY_CAMEL_CASE, CACHE_STORAGE_KEY_SNAKE_CASE, CAMEL_CASE_NAMING_CONVENTION, DEFAULT_ENCODING_KEY, DEFAULT_ENCODING_KEY_CAMEL_CASE, DEFAULT_ENCODING_KEY_SNAKE_CASE, DEFAULT_INCOMPATIBLE_ENHANCEMENTS, DEFAULT_INCOMPATIBLE_IMPROVEMENTS, DISABLE_AUTO_ESCAPING_POLICY, DOLLAR_INTERPOLATION_SYNTAX, ENABLE_IF_DEFAULT_AUTO_ESCAPING_POLICY, ENABLE_IF_SUPPORTED_AUTO_ESCAPING_POLICY, FALLBACK_ON_NULL_LOOP_VARIABLE_KEY, FALLBACK_ON_NULL_LOOP_VARIABLE_KEY_CAMEL_CASE, FALLBACK_ON_NULL_LOOP_VARIABLE_KEY_SNAKE_CASE, INCOMPATIBLE_ENHANCEMENTS, INCOMPATIBLE_IMPROVEMENTS, INCOMPATIBLE_IMPROVEMENTS_KEY, INCOMPATIBLE_IMPROVEMENTS_KEY_CAMEL_CASE, INCOMPATIBLE_IMPROVEMENTS_KEY_SNAKE_CASE, INTERPOLATION_SYNTAX_KEY, INTERPOLATION_SYNTAX_KEY_CAMEL_CASE, INTERPOLATION_SYNTAX_KEY_SNAKE_CASE, LEGACY_INTERPOLATION_SYNTAX, LEGACY_NAMING_CONVENTION, LOCALIZED_LOOKUP_KEY, LOCALIZED_LOOKUP_KEY_CAMEL_CASE, LOCALIZED_LOOKUP_KEY_SNAKE_CASE, NAMING_CONVENTION_KEY, NAMING_CONVENTION_KEY_CAMEL_CASE, NAMING_CONVENTION_KEY_SNAKE_CASE, OUTPUT_FORMAT_KEY, OUTPUT_FORMAT_KEY_CAMEL_CASE, OUTPUT_FORMAT_KEY_SNAKE_CASE, PARSED_DEFAULT_INCOMPATIBLE_ENHANCEMENTS, RECOGNIZE_STANDARD_FILE_EXTENSIONS_KEY, RECOGNIZE_STANDARD_FILE_EXTENSIONS_KEY_CAMEL_CASE, RECOGNIZE_STANDARD_FILE_EXTENSIONS_KEY_SNAKE_CASE, REGISTERED_CUSTOM_OUTPUT_FORMATS_KEY, REGISTERED_CUSTOM_OUTPUT_FORMATS_KEY_CAMEL_CASE, REGISTERED_CUSTOM_OUTPUT_FORMATS_KEY_SNAKE_CASE, SQUARE_BRACKET_INTERPOLATION_SYNTAX, SQUARE_BRACKET_TAG_SYNTAX, STRICT_SYNTAX_KEY, STRICT_SYNTAX_KEY_CAMEL_CASE, STRICT_SYNTAX_KEY_SNAKE_CASE, TAB_SIZE_KEY, TAB_SIZE_KEY_CAMEL_CASE, TAB_SIZE_KEY_SNAKE_CASE, TAG_SYNTAX_KEY, TAG_SYNTAX_KEY_CAMEL_CASE, TAG_SYNTAX_KEY_SNAKE_CASE, TEMPLATE_CONFIGURATIONS_KEY, TEMPLATE_CONFIGURATIONS_KEY_CAMEL_CASE, TEMPLATE_CONFIGURATIONS_KEY_SNAKE_CASE, TEMPLATE_LOADER_KEY, TEMPLATE_LOADER_KEY_CAMEL_CASE, TEMPLATE_LOADER_KEY_SNAKE_CASE, TEMPLATE_LOOKUP_STRATEGY_KEY, TEMPLATE_LOOKUP_STRATEGY_KEY_CAMEL_CASE, TEMPLATE_LOOKUP_STRATEGY_KEY_SNAKE_CASE, TEMPLATE_NAME_FORMAT_KEY, TEMPLATE_NAME_FORMAT_KEY_CAMEL_CASE, TEMPLATE_NAME_FORMAT_KEY_SNAKE_CASE, TEMPLATE_UPDATE_DELAY_KEY, TEMPLATE_UPDATE_DELAY_KEY_CAMEL_CASE, TEMPLATE_UPDATE_DELAY_KEY_SNAKE_CASE, VERSION_2_3_0, VERSION_2_3_19, VERSION_2_3_20, VERSION_2_3_21, VERSION_2_3_22, VERSION_2_3_23, VERSION_2_3_24, VERSION_2_3_25, VERSION_2_3_26, VERSION_2_3_27, VERSION_2_3_28, VERSION_2_3_29, VERSION_2_3_30, VERSION_2_3_31, VERSION_2_3_32, WHITESPACE_STRIPPING_KEY, WHITESPACE_STRIPPING_KEY_CAMEL_CASE, WHITESPACE_STRIPPING_KEY_SNAKE_CASE
      • Fields inherited from class freemarker.core.Configurable

        API_BUILTIN_ENABLED_KEY, API_BUILTIN_ENABLED_KEY_CAMEL_CASE, API_BUILTIN_ENABLED_KEY_SNAKE_CASE, ARITHMETIC_ENGINE_KEY, ARITHMETIC_ENGINE_KEY_CAMEL_CASE, ARITHMETIC_ENGINE_KEY_SNAKE_CASE, ATTEMPT_EXCEPTION_REPORTER_KEY, ATTEMPT_EXCEPTION_REPORTER_KEY_CAMEL_CASE, ATTEMPT_EXCEPTION_REPORTER_KEY_SNAKE_CASE, AUTO_FLUSH_KEY, AUTO_FLUSH_KEY_CAMEL_CASE, AUTO_FLUSH_KEY_SNAKE_CASE, BOOLEAN_FORMAT_KEY, BOOLEAN_FORMAT_KEY_CAMEL_CASE, BOOLEAN_FORMAT_KEY_SNAKE_CASE, C_FORMAT_KEY, C_FORMAT_KEY_CAMEL_CASE, C_FORMAT_KEY_SNAKE_CASE, CLASSIC_COMPATIBLE_KEY, CLASSIC_COMPATIBLE_KEY_CAMEL_CASE, CLASSIC_COMPATIBLE_KEY_SNAKE_CASE, CUSTOM_DATE_FORMATS_KEY, CUSTOM_DATE_FORMATS_KEY_CAMEL_CASE, CUSTOM_DATE_FORMATS_KEY_SNAKE_CASE, CUSTOM_NUMBER_FORMATS_KEY, CUSTOM_NUMBER_FORMATS_KEY_CAMEL_CASE, CUSTOM_NUMBER_FORMATS_KEY_SNAKE_CASE, DATE_FORMAT_KEY, DATE_FORMAT_KEY_CAMEL_CASE, DATE_FORMAT_KEY_SNAKE_CASE, DATETIME_FORMAT_KEY, DATETIME_FORMAT_KEY_CAMEL_CASE, DATETIME_FORMAT_KEY_SNAKE_CASE, LAZY_AUTO_IMPORTS_KEY, LAZY_AUTO_IMPORTS_KEY_CAMEL_CASE, LAZY_AUTO_IMPORTS_KEY_SNAKE_CASE, LAZY_IMPORTS_KEY, LAZY_IMPORTS_KEY_CAMEL_CASE, LAZY_IMPORTS_KEY_SNAKE_CASE, LOCALE_KEY, LOCALE_KEY_CAMEL_CASE, LOCALE_KEY_SNAKE_CASE, LOG_TEMPLATE_EXCEPTIONS_KEY, LOG_TEMPLATE_EXCEPTIONS_KEY_CAMEL_CASE, LOG_TEMPLATE_EXCEPTIONS_KEY_SNAKE_CASE, NEW_BUILTIN_CLASS_RESOLVER_KEY, NEW_BUILTIN_CLASS_RESOLVER_KEY_CAMEL_CASE, NEW_BUILTIN_CLASS_RESOLVER_KEY_SNAKE_CASE, NUMBER_FORMAT_KEY, NUMBER_FORMAT_KEY_CAMEL_CASE, NUMBER_FORMAT_KEY_SNAKE_CASE, OBJECT_WRAPPER_KEY, OBJECT_WRAPPER_KEY_CAMEL_CASE, OBJECT_WRAPPER_KEY_SNAKE_CASE, OUTPUT_ENCODING_KEY, OUTPUT_ENCODING_KEY_CAMEL_CASE, OUTPUT_ENCODING_KEY_SNAKE_CASE, SHOW_ERROR_TIPS_KEY, SHOW_ERROR_TIPS_KEY_CAMEL_CASE, SHOW_ERROR_TIPS_KEY_SNAKE_CASE, SQL_DATE_AND_TIME_TIME_ZONE_KEY, SQL_DATE_AND_TIME_TIME_ZONE_KEY_CAMEL_CASE, SQL_DATE_AND_TIME_TIME_ZONE_KEY_SNAKE_CASE, STRICT_BEAN_MODELS, STRICT_BEAN_MODELS_KEY, STRICT_BEAN_MODELS_KEY_CAMEL_CASE, STRICT_BEAN_MODELS_KEY_SNAKE_CASE, TEMPLATE_EXCEPTION_HANDLER_KEY, TEMPLATE_EXCEPTION_HANDLER_KEY_CAMEL_CASE, TEMPLATE_EXCEPTION_HANDLER_KEY_SNAKE_CASE, TIME_FORMAT_KEY, TIME_FORMAT_KEY_CAMEL_CASE, TIME_FORMAT_KEY_SNAKE_CASE, TIME_ZONE_KEY, TIME_ZONE_KEY_CAMEL_CASE, TIME_ZONE_KEY_SNAKE_CASE, TRUNCATE_BUILTIN_ALGORITHM_KEY, TRUNCATE_BUILTIN_ALGORITHM_KEY_CAMEL_CASE, TRUNCATE_BUILTIN_ALGORITHM_KEY_SNAKE_CASE, URL_ESCAPING_CHARSET_KEY, URL_ESCAPING_CHARSET_KEY_CAMEL_CASE, URL_ESCAPING_CHARSET_KEY_SNAKE_CASE, WRAP_UNCHECKED_EXCEPTIONS_KEY, WRAP_UNCHECKED_EXCEPTIONS_KEY_CAMEL_CASE, WRAP_UNCHECKED_EXCEPTIONS_KEY_SNAKE_CASE
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Object getCustomAttribute​(String name)  
      String[] getCustomAttributeNames()  
      Locale getLocale()  
      freemarker.template.TemplateModel getSharedVariable​(String name)  
      Set<String> getSharedVariableNames()  
      freemarker.template.Template getTemplate​(String name, Locale locale, Object customLookupCondition, String encoding, boolean parseAsFTL, boolean ignoreMissing)
      Override getTemplate(), so we can apply DataGetters to all included templates.
      static void retrieveAndRunDataGetters​(freemarker.core.Environment env, String templateName)
      Find the DataGetters for this template, and apply them to the Freemarker environment.
      • Methods inherited from class freemarker.template.Configuration

        clearEncodingMap, clearSharedVariables, clearTemplateCache, clone, doAutoImportsAndIncludes, getAutoEscapingPolicy, getCacheStorage, getCorrectedNameForUnknownSetting, getDefaultConfiguration, getDefaultEncoding, getDefaultObjectWrapper, getEncoding, getFallbackOnNullLoopVariable, getIncompatibleEnhancements, getIncompatibleImprovements, getInterpolationSyntax, getLocalizedLookup, getNamingConvention, getOutputFormat, getOutputFormat, getParsedIncompatibleEnhancements, getRecognizeStandardFileExtensions, getRegisteredCustomOutputFormats, getSettingNames, getStrictSyntaxMode, getSupportedBuiltInDirectiveNames, getSupportedBuiltInDirectiveNames, getSupportedBuiltInNames, getSupportedBuiltInNames, getTabSize, getTagSyntax, getTemplate, getTemplate, getTemplate, getTemplate, getTemplate, getTemplate, getTemplateConfigurations, getTemplateLoader, getTemplateLookupStrategy, getTemplateNameFormat, getTemplateUpdateDelayMilliseconds, getVersion, getVersionNumber, getWhitespaceStripping, isAttemptExceptionReporterExplicitlySet, isCacheStorageExplicitlySet, isCFormatExplicitlySet, isDefaultEncodingExplicitlySet, isLocaleExplicitlySet, isLogTemplateExceptionsExplicitlySet, isObjectWrapperExplicitlySet, isOutputFormatExplicitlySet, isRecognizeStandardFileExtensionsExplicitlySet, isTemplateExceptionHandlerExplicitlySet, isTemplateLoaderExplicitlySet, isTemplateLookupStrategyExplicitlySet, isTemplateNameFormatExplicitlySet, isTimeZoneExplicitlySet, isWrapUncheckedExceptionsExplicitlySet, loadBuiltInEncodingMap, removeTemplateFromCache, removeTemplateFromCache, removeTemplateFromCache, removeTemplateFromCache, removeTemplateFromCache, removeTemplateFromCache, setAllSharedVariables, setAttemptExceptionReporter, setAutoEscapingPolicy, setCacheStorage, setCFormat, setClassForTemplateLoading, setClassLoaderForTemplateLoading, setDefaultConfiguration, setDefaultEncoding, setDirectoryForTemplateLoading, setEncoding, setFallbackOnNullLoopVariable, setIncompatibleEnhancements, setIncompatibleImprovements, setInterpolationSyntax, setLocale, setLocalizedLookup, setLogTemplateExceptions, setNamingConvention, setObjectWrapper, setOutputFormat, setRecognizeStandardFileExtensions, setRegisteredCustomOutputFormats, setServletContextForTemplateLoading, setSetting, setSharedVariable, setSharedVariable, setSharedVariables, setSharedVaribles, setStrictSyntaxMode, setTabSize, setTagSyntax, setTemplateConfigurations, setTemplateExceptionHandler, setTemplateLoader, setTemplateLookupStrategy, setTemplateNameFormat, setTemplateUpdateDelay, setTemplateUpdateDelayMilliseconds, setTimeZone, setWhitespaceStripping, setWrapUncheckedExceptions, unsetAttemptExceptionReporter, unsetCacheStorage, unsetCFormat, unsetDefaultEncoding, unsetLocale, unsetLogTemplateExceptions, unsetObjectWrapper, unsetOutputFormat, unsetRecognizeStandardFileExtensions, unsetTemplateExceptionHandler, unsetTemplateLoader, unsetTemplateLookupStrategy, unsetTemplateNameFormat, unsetTimeZone, unsetWrapUncheckedExceptions
      • Methods inherited from class freemarker.core.Configurable

        addAutoImport, addAutoInclude, getArithmeticEngine, getAttemptExceptionReporter, getAutoFlush, getAutoImports, getAutoImportsWithoutFallback, getAutoIncludes, getAutoIncludesWithoutFallback, getBooleanFormat, getCFormat, getClassicCompatibleAsInt, getCustomDateFormat, getCustomDateFormats, getCustomDateFormatsWithoutFallback, getCustomNumberFormat, getCustomNumberFormats, getCustomNumberFormatsWithoutFallback, getDateFormat, getDateTimeFormat, getEnvironment, getLazyAutoImports, getLazyImports, getLogTemplateExceptions, getNewBuiltinClassResolver, getNumberFormat, getObjectWrapper, getOutputEncoding, getParent, getSetting, getSettings, getShowErrorTips, getSQLDateAndTimeTimeZone, getTemplateExceptionHandler, getTimeFormat, getTimeZone, getTruncateBuiltinAlgorithm, getURLEscapingCharset, getWrapUncheckedExceptions, hasCustomFormats, invalidSettingValueException, isAPIBuiltinEnabled, isAPIBuiltinEnabledSet, isArithmeticEngineSet, isAttemptExceptionReporterSet, isAutoFlushSet, isAutoImportsSet, isAutoIncludesSet, isBooleanFormatSet, isCFormatSet, isClassicCompatible, isClassicCompatibleSet, isCustomDateFormatsSet, isCustomNumberFormatsSet, isDateFormatSet, isDateTimeFormatSet, isLazyAutoImportsSet, isLazyImportsSet, isLocaleSet, isLogTemplateExceptionsSet, isNewBuiltinClassResolverSet, isNumberFormatSet, isObjectWrapperSet, isOutputEncodingSet, isShowErrorTipsSet, isSQLDateAndTimeTimeZoneSet, isTemplateExceptionHandlerSet, isTimeFormatSet, isTimeZoneSet, isTruncateBuiltinAlgorithmSet, isURLEscapingCharsetSet, isWrapUncheckedExceptionsSet, parseAsImportList, parseAsList, parseAsSegmentedList, removeAutoImport, removeAutoInclude, removeCustomAttribute, setAPIBuiltinEnabled, setArithmeticEngine, setAutoFlush, setAutoImports, setAutoIncludes, setBooleanFormat, setClassicCompatible, setClassicCompatibleAsInt, setCustomAttribute, setCustomDateFormats, setCustomNumberFormats, setDateFormat, setDateTimeFormat, setLazyAutoImports, setLazyImports, setNewBuiltinClassResolver, setNumberFormat, setOutputEncoding, setSettings, setSettings, setShowErrorTips, setSQLDateAndTimeTimeZone, setStrictBeanModels, setTimeFormat, settingValueAssignmentException, setTruncateBuiltinAlgorithm, setURLEscapingCharset, unknownSettingException
      • Methods inherited from interface freemarker.core.ParserConfiguration

        getArithmeticEngine
    • Constructor Detail

      • FreemarkerConfigurationImpl

        public FreemarkerConfigurationImpl()
    • Method Detail

      • getCustomAttribute

        public Object getCustomAttribute​(String name)
        Overrides:
        getCustomAttribute in class freemarker.core.Configurable
      • getCustomAttributeNames

        public String[] getCustomAttributeNames()
        Overrides:
        getCustomAttributeNames in class freemarker.core.Configurable
      • getSharedVariable

        public freemarker.template.TemplateModel getSharedVariable​(String name)
        Overrides:
        getSharedVariable in class freemarker.template.Configuration
      • getSharedVariableNames

        public Set<String> getSharedVariableNames()
        Overrides:
        getSharedVariableNames in class freemarker.template.Configuration
      • getLocale

        public Locale getLocale()
        Overrides:
        getLocale in class freemarker.core.Configurable
      • getTemplate

        public freemarker.template.Template getTemplate​(String name,
                                                        Locale locale,
                                                        Object customLookupCondition,
                                                        String encoding,
                                                        boolean parseAsFTL,
                                                        boolean ignoreMissing)
                                                 throws freemarker.template.TemplateNotFoundException,
                                                        freemarker.template.MalformedTemplateNameException,
                                                        freemarker.core.ParseException,
                                                        IOException
        Override getTemplate(), so we can apply DataGetters to all included templates. This won't work for top-level Templates, since the Environment hasn't been created yet. When TemplateProcessingHelper creates the Environment, it must call retrieveAndRunDataGetters() for the top-level Template.
        Overrides:
        getTemplate in class freemarker.template.Configuration
        Throws:
        freemarker.template.TemplateNotFoundException
        freemarker.template.MalformedTemplateNameException
        freemarker.core.ParseException
        IOException
      • retrieveAndRunDataGetters

        public static void retrieveAndRunDataGetters​(freemarker.core.Environment env,
                                                     String templateName)
        Find the DataGetters for this template, and apply them to the Freemarker environment.