Class FreemarkerConfigurationImpl
- java.lang.Object
-
- freemarker.core.Configurable
-
- freemarker.template.Configuration
-
- edu.cornell.mannlib.vitro.webapp.freemarker.config.FreemarkerConfigurationImpl
-
- All Implemented Interfaces:
Cloneable
public class FreemarkerConfigurationImpl extends freemarker.template.ConfigurationExtend 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?
-
-
Field Summary
-
Fields inherited from class freemarker.template.Configuration
ANGLE_BRACKET_TAG_SYNTAX, AUTO_DETECT_NAMING_CONVENTION, AUTO_DETECT_TAG_SYNTAX, 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, INCOMPATIBLE_ENHANCEMENTS, INCOMPATIBLE_IMPROVEMENTS, INCOMPATIBLE_IMPROVEMENTS_KEY, INCOMPATIBLE_IMPROVEMENTS_KEY_CAMEL_CASE, INCOMPATIBLE_IMPROVEMENTS_KEY_SNAKE_CASE, 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, PARSED_DEFAULT_INCOMPATIBLE_ENHANCEMENTS, SQUARE_BRACKET_TAG_SYNTAX, STRICT_SYNTAX_KEY, STRICT_SYNTAX_KEY_CAMEL_CASE, STRICT_SYNTAX_KEY_SNAKE_CASE, TAG_SYNTAX_KEY, TAG_SYNTAX_KEY_CAMEL_CASE, TAG_SYNTAX_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, 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, 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, CLASSIC_COMPATIBLE_KEY, CLASSIC_COMPATIBLE_KEY_CAMEL_CASE, CLASSIC_COMPATIBLE_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, 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, URL_ESCAPING_CHARSET_KEY, URL_ESCAPING_CHARSET_KEY_CAMEL_CASE, URL_ESCAPING_CHARSET_KEY_SNAKE_CASE
-
-
Constructor Summary
Constructors Constructor Description FreemarkerConfigurationImpl()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ObjectgetCustomAttribute(String name)String[]getCustomAttributeNames()LocalegetLocale()freemarker.template.TemplateModelgetSharedVariable(String name)Set<String>getSharedVariableNames()freemarker.template.TemplategetTemplate(String name, Locale locale, Object customLookupCondition, String encoding, boolean parseAsFTL, boolean ignoreMissing)Override getTemplate(), so we can apply DataGetters to all included templates.static voidretrieveAndRunDataGetters(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
addAutoImport, addAutoInclude, clearEncodingMap, clearSharedVariables, clearTemplateCache, clone, doAutoImportsAndIncludes, getCacheStorage, getCorrectedNameForUnknownSetting, getDefaultConfiguration, getDefaultEncoding, getDefaultObjectWrapper, getEncoding, getIncompatibleEnhancements, getIncompatibleImprovements, getLocalizedLookup, getNamingConvention, getParsedIncompatibleEnhancements, getStrictSyntaxMode, getSupportedBuiltInDirectiveNames, getSupportedBuiltInNames, getTagSyntax, getTemplate, getTemplate, getTemplate, getTemplate, getTemplate, getTemplate, getTemplateLoader, getTemplateLookupStrategy, getTemplateNameFormat, getTemplateUpdateDelayMilliseconds, getVersion, getVersionNumber, getWhitespaceStripping, isCacheStorageExplicitlySet, isLogTemplateExceptionsExplicitlySet, isObjectWrapperExplicitlySet, isTemplateExceptionHandlerExplicitlySet, isTemplateLoaderExplicitlySet, isTemplateLookupStrategyExplicitlySet, isTemplateNameFormatExplicitlySet, loadBuiltInEncodingMap, removeAutoImport, removeAutoInclude, removeTemplateFromCache, removeTemplateFromCache, removeTemplateFromCache, removeTemplateFromCache, removeTemplateFromCache, setAllSharedVariables, setAutoImports, setAutoIncludes, setCacheStorage, setClassForTemplateLoading, setClassLoaderForTemplateLoading, setDefaultConfiguration, setDefaultEncoding, setDirectoryForTemplateLoading, setEncoding, setIncompatibleEnhancements, setIncompatibleImprovements, setLocalizedLookup, setLogTemplateExceptions, setNamingConvention, setObjectWrapper, setServletContextForTemplateLoading, setSetting, setSharedVariable, setSharedVariable, setSharedVaribles, setStrictSyntaxMode, setTagSyntax, setTemplateExceptionHandler, setTemplateLoader, setTemplateLookupStrategy, setTemplateNameFormat, setTemplateUpdateDelay, setTemplateUpdateDelayMilliseconds, setWhitespaceStripping, unsetCacheStorage, unsetLogTemplateExceptions, unsetObjectWrapper, unsetTemplateExceptionHandler, unsetTemplateLoader, unsetTemplateLookupStrategy, unsetTemplateNameFormat
-
Methods inherited from class freemarker.core.Configurable
getArithmeticEngine, getAutoFlush, getBooleanFormat, getClassicCompatibleAsInt, getDateFormat, getDateTimeFormat, getEnvironment, getLogTemplateExceptions, getNewBuiltinClassResolver, getNumberFormat, getObjectWrapper, getOutputEncoding, getParent, getSetting, getSettings, getShowErrorTips, getSQLDateAndTimeTimeZone, getTemplateExceptionHandler, getTimeFormat, getTimeZone, getURLEscapingCharset, invalidSettingValueException, isAPIBuiltinEnabled, isClassicCompatible, parseAsImportList, parseAsList, parseAsSegmentedList, removeCustomAttribute, setAPIBuiltinEnabled, setArithmeticEngine, setAutoFlush, setBooleanFormat, setClassicCompatible, setClassicCompatibleAsInt, setCustomAttribute, setDateFormat, setDateTimeFormat, setLocale, setNewBuiltinClassResolver, setNumberFormat, setOutputEncoding, setSettings, setSettings, setShowErrorTips, setSQLDateAndTimeTimeZone, setStrictBeanModels, setTimeFormat, setTimeZone, settingValueAssignmentException, setURLEscapingCharset, unknownSettingException
-
-
-
-
Method Detail
-
getCustomAttribute
public Object getCustomAttribute(String name)
- Overrides:
getCustomAttributein classfreemarker.core.Configurable
-
getCustomAttributeNames
public String[] getCustomAttributeNames()
- Overrides:
getCustomAttributeNamesin classfreemarker.core.Configurable
-
getSharedVariable
public freemarker.template.TemplateModel getSharedVariable(String name)
- Overrides:
getSharedVariablein classfreemarker.template.Configuration
-
getSharedVariableNames
public Set<String> getSharedVariableNames()
- Overrides:
getSharedVariableNamesin classfreemarker.template.Configuration
-
getLocale
public Locale getLocale()
- Overrides:
getLocalein classfreemarker.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:
getTemplatein classfreemarker.template.Configuration- Throws:
freemarker.template.TemplateNotFoundExceptionfreemarker.template.MalformedTemplateNameExceptionfreemarker.core.ParseExceptionIOException
-
retrieveAndRunDataGetters
public static void retrieveAndRunDataGetters(freemarker.core.Environment env, String templateName)Find the DataGetters for this template, and apply them to the Freemarker environment.
-
-