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
Configurable
andParserConfiguration
. This means that it can influence both the template parsing phase and the runtime settings. For both aspects (i.e.,ParserConfiguration
andConfigurable
) to take effect, you have first pass this object to theTemplate
constructor (this is where theParserConfiguration
interface is used), and then you have to callapply(Template)
on the resultingTemplate
object (this is where theConfigurable
aspect 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#ftl
header, those values should have precedence. A consequence of this is that if you want to configure the sameTemplate
with 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 TypeMethodDescriptionvoid
Sets those settings of theTemplate
which aren't yet set in theTemplate
and are set in thisTemplateConfiguration
, leaves the other settings as is.int
The getter pair ofsetAutoEscapingPolicy(int)
.ReturnsConfiguration.getIncompatibleImprovements()
from the parentConfiguration
.int
The getter pair ofsetInterpolationSyntax(int)
.int
The getter pair ofsetNamingConvention(int)
.The getter pair ofsetOutputFormat(OutputFormat)
.Returns the parentConfiguration
, ornull
if none was associated yet.boolean
Getter pair ofsetRecognizeStandardFileExtensions(boolean)
.boolean
The getter pair ofsetStrictSyntaxMode(boolean)
.int
Getter pair ofsetTabSize(int)
.int
The getter pair ofsetTagSyntax(int)
.boolean
The getter pair ofgetWhitespaceStripping()
.boolean
Tells if this setting is set directly in this object or its value is coming from theparent
.boolean
boolean
Tells if this setting is set directly in this object or its value is coming from theparent
.boolean
Tells if this setting is set directly in this object or its value is coming from theparent
.boolean
Tells if this setting is set directly in this object or its value is coming from theparent
.boolean
Tells if this setting is set directly in this object or its value is coming from theparent
.boolean
Tells if this setting is set directly in this object or its value is coming from theparent
.boolean
Tells if this setting is set directly in this object or its value is coming from theparent
.boolean
Tells if this setting is set directly in this object or its value is coming from theparent
.boolean
Tells if this setting is set directly in this object or its value is coming from theparent
.void
Set all settings in thisTemplateConfiguration
that were set in the parameterTemplateConfiguration
, possibly overwriting the earlier value in this object.void
setAutoEscapingPolicy(int autoEscapingPolicy)
Sets the output format of the template; seeConfiguration.setAutoEscapingPolicy(int)
for more.void
setEncoding(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#ftl
header.void
setInterpolationSyntax(int interpolationSyntax)
void
setNamingConvention(int namingConvention)
void
setOutputFormat(OutputFormat outputFormat)
Sets the output format of the template; seeConfiguration.setOutputFormat(OutputFormat)
for more.void
Associates this instance with aConfiguration
; usually you don't call this, as it's called internally when this instance is added to aConfiguration
.void
setRecognizeStandardFileExtensions(boolean recognizeStandardFileExtensions)
void
setStrictBeanModels(boolean strict)
void
setStrictSyntaxMode(boolean strictSyntaxMode)
void
setTabSize(int tabSize)
void
setTagSyntax(int tagSyntax)
void
setWhitespaceStripping(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, unknownSettingException
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods 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 parentConfiguration
when 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 sameConfiguration
parameter again, as that changes nothing anyway).- Throws:
IllegalArgumentException
- if the argument isnull
or not aConfiguration
IllegalStateException
- if this object is already associated to a differentConfiguration
object, or if theConfiguration
has#getIncompatibleImprovements()
less than 2.3.22 and this object tries to change any non-parser settings
-
getParentConfiguration
Returns the parentConfiguration
, ornull
if none was associated yet. -
merge
Set all settings in thisTemplateConfiguration
that were set in the parameterTemplateConfiguration
, possibly overwriting the earlier value in this object. (A setting is said to be set in aTemplateConfiguration
if it was explicitly set via a setter method, as opposed to be inherited.) -
apply
Sets those settings of theTemplate
which aren't yet set in theTemplate
and are set in thisTemplateConfiguration
, leaves the other settings as is. A setting is said to be set in aTemplateConfiguration
orTemplate
if 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
encoding
setting of theTemplate
counts as unset if it'snull
, even ifnull
was 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:
getTagSyntax
in 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:
getInterpolationSyntax
in 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:
getNamingConvention
in 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:
getWhitespaceStripping
in 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:
getAutoEscapingPolicy
in 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:
getOutputFormat
in 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:
getRecognizeStandardFileExtensions
in 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:
getStrictSyntaxMode
in 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:
setStrictBeanModels
in 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#ftl
header. This setting overrides the locale-specific encodings set viaConfiguration.setEncoding(java.util.Locale, String)
. It also overrides theencoding
parameter ofConfiguration.getTemplate(String, String)
(and of its overloads) and theencoding
parameter of the#include
directive. 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
encoding
in 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:
getTabSize
in 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 theParserConfiguration
interface.- Specified by:
getIncompatibleImprovements
in interfaceParserConfiguration
- Throws:
IllegalStateException
- If the parent configuration wasn't yet set.
-