Class TemplateConfiguration
- All Implemented Interfaces:
ParserConfiguration
Template-s (or rather groups of templates),
relatively to the common setting values coming from the Configuration. This was designed with the standard
template loading mechanism of FreeMarker in mind (Configuration.getTemplate(String)
and TemplateCache), though can also be reused for custom template loading and caching solutions.
Note on the locale setting: When used with the standard template loading/caching mechanism (
Configuration.getTemplate(String) and its overloads), localized lookup happens before the locale
specified here could have effect. The locale will be only set in the template that the localized lookup has
already found.
Note on the encoding setting encoding: See setEncoding(String).
Note that the result value of the reader methods (getter and "is" methods) is usually not useful unless the value of
that setting was already set on this object. Otherwise you will get the value from the parent Configuration,
or an IllegalStateException before this object is associated to a Configuration.
If you are using this class for your own template loading and caching solution, rather than with the standard one, you should be aware of a few more details:
- This class implements both
ConfigurableandParserConfiguration. This means that it can influence both the template parsing phase and the runtime settings. For both aspects (i.e.,ParserConfigurationandConfigurable) to take effect, you have first pass this object to theTemplateconstructor (this is where theParserConfigurationinterface is used), and then you have to callapply(Template)on the resultingTemplateobject (this is where theConfigurableaspect is used). apply(Template)only change the settings that weren't yet set on theTemplate(but are inherited from theConfiguration). This is primarily because if the template configures itself via the#ftlheader, those values should have precedence. A consequence of this is that if you want to configure the sameTemplatewith multipleTemplateConfiguration-s, you either should merge them to a single one before that (withmerge(TemplateConfiguration)), or you have to apply them in reverse order of their intended precedence.
- Since:
- 2.3.24
- See Also:
Template(String, String, Reader, Configuration, ParserConfiguration, String)
-
Nested Class Summary
Nested classes/interfaces inherited from class freemarker.core.Configurable
Configurable.SettingValueAssignmentException, Configurable.UnknownSettingException -
Field Summary
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, 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, 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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidSets those settings of theTemplatewhich aren't yet set in theTemplateand are set in thisTemplateConfiguration, leaves the other settings as is.intThe getter pair ofsetAutoEscapingPolicy(int).ReturnsConfiguration.getIncompatibleImprovements()from the parentConfiguration.intThe getter pair ofsetInterpolationSyntax(int).intThe getter pair ofsetNamingConvention(int).The getter pair ofsetOutputFormat(OutputFormat).Returns the parentConfiguration, ornullif none was associated yet.booleanGetter pair ofsetRecognizeStandardFileExtensions(boolean).booleanThe getter pair ofsetStrictSyntaxMode(boolean).intGetter pair ofsetTabSize(int).intThe getter pair ofsetTagSyntax(int).booleanThe getter pair ofgetWhitespaceStripping().booleanTells if this setting is set directly in this object or its value is coming from theparent.booleanbooleanTells if this setting is set directly in this object or its value is coming from theparent.booleanTells if this setting is set directly in this object or its value is coming from theparent.booleanTells if this setting is set directly in this object or its value is coming from theparent.booleanTells if this setting is set directly in this object or its value is coming from theparent.booleanTells if this setting is set directly in this object or its value is coming from theparent.booleanTells if this setting is set directly in this object or its value is coming from theparent.booleanTells if this setting is set directly in this object or its value is coming from theparent.booleanTells if this setting is set directly in this object or its value is coming from theparent.voidSet all settings in thisTemplateConfigurationthat were set in the parameterTemplateConfiguration, possibly overwriting the earlier value in this object.voidsetAutoEscapingPolicy(int autoEscapingPolicy)Sets the output format of the template; seeConfiguration.setAutoEscapingPolicy(int)for more.voidsetEncoding(String encoding)When the standard template loading/caching mechanism is used, this forces the charset used for reading the template "file", overriding everything but the encoding coming from the#ftlheader.voidsetInterpolationSyntax(int interpolationSyntax)voidsetNamingConvention(int namingConvention)voidsetOutputFormat(OutputFormat outputFormat)Sets the output format of the template; seeConfiguration.setOutputFormat(OutputFormat)for more.voidAssociates this instance with aConfiguration; usually you don't call this, as it's called internally when this instance is added to aConfiguration.voidsetRecognizeStandardFileExtensions(boolean recognizeStandardFileExtensions)voidsetStrictBeanModels(boolean strict)voidsetStrictSyntaxMode(boolean strictSyntaxMode)voidsetTabSize(int tabSize)voidsetTagSyntax(int tagSyntax)voidsetWhitespaceStripping(boolean whitespaceStripping)Methods inherited from class freemarker.core.Configurable
addAutoImport, addAutoInclude, clone, doAutoImportsAndIncludes, getArithmeticEngine, getAttemptExceptionReporter, getAutoFlush, getAutoImports, getAutoImportsWithoutFallback, getAutoIncludes, getAutoIncludesWithoutFallback, getBooleanFormat, getCFormat, getClassicCompatibleAsInt, getCorrectedNameForUnknownSetting, getCustomAttribute, getCustomAttributeNames, getCustomDateFormat, getCustomDateFormats, getCustomDateFormatsWithoutFallback, getCustomNumberFormat, getCustomNumberFormats, getCustomNumberFormatsWithoutFallback, getDateFormat, getDateTimeFormat, getEnvironment, getLazyAutoImports, getLazyImports, getLocale, getLogTemplateExceptions, getNewBuiltinClassResolver, getNumberFormat, getObjectWrapper, getOutputEncoding, getParent, getSetting, getSettingNames, 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, setAttemptExceptionReporter, setAutoFlush, setAutoImports, setAutoIncludes, setBooleanFormat, setCFormat, setClassicCompatible, setClassicCompatibleAsInt, setCustomAttribute, setCustomDateFormats, setCustomNumberFormats, setDateFormat, setDateTimeFormat, setLazyAutoImports, setLazyImports, setLocale, setLogTemplateExceptions, setNewBuiltinClassResolver, setNumberFormat, setObjectWrapper, setOutputEncoding, setSetting, setSettings, setSettings, setShowErrorTips, setSQLDateAndTimeTimeZone, setTemplateExceptionHandler, setTimeFormat, setTimeZone, settingValueAssignmentException, setTruncateBuiltinAlgorithm, setURLEscapingCharset, setWrapUncheckedExceptions, unknownSettingExceptionMethods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface freemarker.core.ParserConfiguration
getArithmeticEngine
-
Constructor Details
-
TemplateConfiguration
public TemplateConfiguration()Creates a new instance. The parent will beConfiguration.getDefaultConfiguration()initially, but it will be changed to the real parentConfigurationwhen this object is added to theConfiguration. (It's not allowed to add the same instance to multipleConfiguration-s).
-
-
Method Details
-
setParentConfiguration
Associates this instance with aConfiguration; usually you don't call this, as it's called internally when this instance is added to aConfiguration. This method can be called only once (except with the sameConfigurationparameter again, as that changes nothing anyway).- Throws:
IllegalArgumentException- if the argument isnullor not aConfigurationIllegalStateException- if this object is already associated to a differentConfigurationobject, or if theConfigurationhas#getIncompatibleImprovements()less than 2.3.22 and this object tries to change any non-parser settings
-
getParentConfiguration
Returns the parentConfiguration, ornullif none was associated yet. -
merge
Set all settings in thisTemplateConfigurationthat were set in the parameterTemplateConfiguration, possibly overwriting the earlier value in this object. (A setting is said to be set in aTemplateConfigurationif it was explicitly set via a setter method, as opposed to be inherited.) -
apply
Sets those settings of theTemplatewhich aren't yet set in theTemplateand are set in thisTemplateConfiguration, leaves the other settings as is. A setting is said to be set in aTemplateConfigurationorTemplateif it was explicitly set via a setter method on that object, as opposed to be inherited from theConfiguration.Note that this method doesn't deal with settings that influence the parser, as those are already baked in at this point via the
ParserConfiguration.Note that the
encodingsetting of theTemplatecounts as unset if it'snull, even ifnullwas set viaTemplate.setEncoding(String).- Throws:
IllegalStateException- If the parent configuration wasn't yet set.
-
setTagSyntax
public void setTagSyntax(int tagSyntax) -
getTagSyntax
public int getTagSyntax()The getter pair ofsetTagSyntax(int).- Specified by:
getTagSyntaxin interfaceParserConfiguration
-
isTagSyntaxSet
public boolean isTagSyntaxSet()Tells if this setting is set directly in this object or its value is coming from theparent. -
setInterpolationSyntax
public void setInterpolationSyntax(int interpolationSyntax) -
getInterpolationSyntax
public int getInterpolationSyntax()The getter pair ofsetInterpolationSyntax(int).- Specified by:
getInterpolationSyntaxin interfaceParserConfiguration
-
isInterpolationSyntaxSet
public boolean isInterpolationSyntaxSet()Tells if this setting is set directly in this object or its value is coming from theparent. -
setNamingConvention
public void setNamingConvention(int namingConvention) -
getNamingConvention
public int getNamingConvention()The getter pair ofsetNamingConvention(int).- Specified by:
getNamingConventionin interfaceParserConfiguration
-
isNamingConventionSet
public boolean isNamingConventionSet()Tells if this setting is set directly in this object or its value is coming from theparent. -
setWhitespaceStripping
public void setWhitespaceStripping(boolean whitespaceStripping) -
getWhitespaceStripping
public boolean getWhitespaceStripping()The getter pair ofgetWhitespaceStripping().- Specified by:
getWhitespaceStrippingin interfaceParserConfiguration
-
isWhitespaceStrippingSet
public boolean isWhitespaceStrippingSet()Tells if this setting is set directly in this object or its value is coming from theparent. -
setAutoEscapingPolicy
public void setAutoEscapingPolicy(int autoEscapingPolicy)Sets the output format of the template; seeConfiguration.setAutoEscapingPolicy(int)for more. -
getAutoEscapingPolicy
public int getAutoEscapingPolicy()The getter pair ofsetAutoEscapingPolicy(int).- Specified by:
getAutoEscapingPolicyin interfaceParserConfiguration
-
isAutoEscapingPolicySet
public boolean isAutoEscapingPolicySet()Tells if this setting is set directly in this object or its value is coming from theparent. -
setOutputFormat
Sets the output format of the template; seeConfiguration.setOutputFormat(OutputFormat)for more. -
getOutputFormat
The getter pair ofsetOutputFormat(OutputFormat).- Specified by:
getOutputFormatin interfaceParserConfiguration
-
isOutputFormatSet
public boolean isOutputFormatSet()Tells if this setting is set directly in this object or its value is coming from theparent. -
setRecognizeStandardFileExtensions
public void setRecognizeStandardFileExtensions(boolean recognizeStandardFileExtensions) -
getRecognizeStandardFileExtensions
public boolean getRecognizeStandardFileExtensions()Getter pair ofsetRecognizeStandardFileExtensions(boolean).- Specified by:
getRecognizeStandardFileExtensionsin interfaceParserConfiguration
-
isRecognizeStandardFileExtensionsSet
public boolean isRecognizeStandardFileExtensionsSet()Tells if this setting is set directly in this object or its value is coming from theparent. -
setStrictSyntaxMode
public void setStrictSyntaxMode(boolean strictSyntaxMode) -
getStrictSyntaxMode
public boolean getStrictSyntaxMode()The getter pair ofsetStrictSyntaxMode(boolean).- Specified by:
getStrictSyntaxModein interfaceParserConfiguration
-
isStrictSyntaxModeSet
public boolean isStrictSyntaxModeSet()Tells if this setting is set directly in this object or its value is coming from theparent. -
setStrictBeanModels
public void setStrictBeanModels(boolean strict)- Overrides:
setStrictBeanModelsin classConfigurable
-
getEncoding
-
setEncoding
When the standard template loading/caching mechanism is used, this forces the charset used for reading the template "file", overriding everything but the encoding coming from the#ftlheader. This setting overrides the locale-specific encodings set viaConfiguration.setEncoding(java.util.Locale, String). It also overrides theencodingparameter ofConfiguration.getTemplate(String, String)(and of its overloads) and theencodingparameter of the#includedirective. This works like that because specifying the encoding where you are requesting the template is error prone and deprecated.If you are developing your own template loading/caching mechanism instead of the standard one, note that the above behavior is not guaranteed by this class alone; you have to ensure it. Also, read the note on
encodingin the documentation ofapply(Template). -
isEncodingSet
public boolean isEncodingSet() -
setTabSize
public void setTabSize(int tabSize)- Since:
- 2.3.25
-
getTabSize
public int getTabSize()Getter pair ofsetTabSize(int).- Specified by:
getTabSizein interfaceParserConfiguration- Since:
- 2.3.25
-
isTabSizeSet
public boolean isTabSizeSet()Tells if this setting is set directly in this object or its value is coming from theparent.- Since:
- 2.3.25
-
getIncompatibleImprovements
ReturnsConfiguration.getIncompatibleImprovements()from the parentConfiguration. This mostly just exist to satisfy theParserConfigurationinterface.- Specified by:
getIncompatibleImprovementsin interfaceParserConfiguration- Throws:
IllegalStateException- If the parent configuration wasn't yet set.
-