Package freemarker.core
Class Configurable
java.lang.Object
freemarker.core.Configurable
- Direct Known Subclasses:
Configuration,Environment,TemplateCore
This is a common superclass of
Configuration,
Template, and Environment classes.
It provides settings that are common to each of them. FreeMarker
uses a three-level setting hierarchy - the return value of every setting
getter method on Configurable objects inherits its value from its parent
Configurable object, unless explicitly overridden by a call to a
corresponding setter method on the object itself. The parent of an
Environment object is a Template object, the
parent of a Template object is a Configuration
object.-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected Objectclone()protected voidfreemarker.core.ast.ArithmeticEngineRetrieves the arithmetic engine used to perform arithmetic operations.getBooleanFormat(boolean value) getCustomAttribute(String name) Retrieves a named custom attribute for this configurable.String[]Returns an array with names of all custom attributes defined directly on this configurable.Returns the date format used to convert date models representing date-only dates to strings.Returns the date format used to convert date models representing datetime dates to strings.Returns the assumed locale when searching for template files with no explicit requested locale.Returns the default number format used to convert numbers to strings.Retrieves the object wrapper used to wrap objects to template models.final ConfigurableReturns the parent Configurable object of this object.getSetting(String key) Deprecated.This method was always defective, and certainly it always will be.Deprecated.This method was always defective, and certainly it always will be.Retrieves the exception handler used to handle template exceptions.Returns the date format used to convert date models representing time-only dates to strings.Returns the time zone to use when formatting time values.protected TemplateExceptioninvalidSettingValueException(String name, String value) voidremoveCustomAttribute(String name) Removes a named custom attribute for this configurable.voidsetArithmeticEngine(freemarker.core.ast.ArithmeticEngine arithmeticEngine) Sets the arithmetic engine used to perform arithmetic operations.voidsetBooleanFormat(String booleanFormat) voidsetCustomAttribute(String name, Object value) Sets a named custom attribute for this configurable.voidsetDateFormat(String dateFormat) Sets the date format used to convert date models representing date-only dates to strings.voidsetDateTimeFormat(String dateTimeFormat) Sets the date format used to convert date models representing datetime dates to strings.voidSets the locale to assume when searching for template files with no explicit requested locale.voidsetNumberFormat(String numberFormat) Sets the number format used to convert numbers to strings.voidsetNumbersForComputers(boolean b) voidsetObjectWrapper(ObjectWrapper objectWrapper) Sets the object wrapper used to wrap objects to template models.voidsetOutputEncoding(String outputEncoding) Sets the output encoding.voidsetParent(Configurable parent) Reparenting support.voidsetSetting(String key, String value) Sets a setting by a name and string value.voidsetSettings(InputStream propsIn) Reads a setting list (key and element pairs) from the input stream.voidsetSettings(Properties props) Set the settings stored in aPropertiesobject.voidsetStrictBeanModels(boolean strict) voidsetTemplateExceptionHandler(TemplateExceptionHandler templateExceptionHandler) Sets the exception handler used to handle template exceptions.voidsetTimeFormat(String timeFormat) Sets the date format used to convert date models representing time-only values to strings.voidsetTimeZone(TimeZone timeZone) Sets the time zone to use when formatting time values.voidsetURLEscapingCharset(String urlEscapingCharset) Sets the URL escaping charset.protected TemplateException
-
Field Details
-
LOCALE_KEY
- See Also:
-
NUMBER_FORMAT_KEY
- See Also:
-
TIME_FORMAT_KEY
- See Also:
-
DATE_FORMAT_KEY
- See Also:
-
DATETIME_FORMAT_KEY
- See Also:
-
TIME_ZONE_KEY
- See Also:
-
TEMPLATE_EXCEPTION_HANDLER_KEY
- See Also:
-
ARITHMETIC_ENGINE_KEY
- See Also:
-
OBJECT_WRAPPER_KEY
- See Also:
-
BOOLEAN_FORMAT_KEY
- See Also:
-
OUTPUT_ENCODING_KEY
- See Also:
-
URL_ESCAPING_CHARSET_KEY
- See Also:
-
STRICT_BEAN_MODELS
- See Also:
-
-
Constructor Details
-
Configurable
public Configurable() -
Configurable
Creates a new instance. Normally you do not need to use this constructor, as you don't useConfigurabledirectly, but its subclasses.
-
-
Method Details
-
clone
- Overrides:
clonein classObject- Throws:
CloneNotSupportedException
-
getParent
Returns the parent Configurable object of this object. The parent stores the default values for this configurable. For example, the parent of theTemplateobject is theConfigurationobject, so setting values not specfied on template level are specified by the confuration object.- Returns:
- the parent Configurable object, or null, if this is the root Configurable object.
-
setParent
Reparenting support. This is used by Environment when it includes a template - the included template becomes the parent configurable during its evaluation. -
setLocale
Sets the locale to assume when searching for template files with no explicit requested locale. -
getTimeZone
Returns the time zone to use when formatting time values. Defaults to system time zone. -
setTimeZone
Sets the time zone to use when formatting time values. -
getLocale
Returns the assumed locale when searching for template files with no explicit requested locale. Defaults to system locale. -
setNumberFormat
Sets the number format used to convert numbers to strings. -
getNumberFormat
Returns the default number format used to convert numbers to strings. Defaults to "number" -
setBooleanFormat
-
getBooleanFormat
-
getBooleanFormat
-
setTimeFormat
Sets the date format used to convert date models representing time-only values to strings. -
getTimeFormat
Returns the date format used to convert date models representing time-only dates to strings. Defaults to "time" -
setDateFormat
Sets the date format used to convert date models representing date-only dates to strings. -
getDateFormat
Returns the date format used to convert date models representing date-only dates to strings. Defaults to "date" -
setDateTimeFormat
Sets the date format used to convert date models representing datetime dates to strings. -
getDateTimeFormat
Returns the date format used to convert date models representing datetime dates to strings. Defaults to "datetime" -
setTemplateExceptionHandler
Sets the exception handler used to handle template exceptions.- Parameters:
templateExceptionHandler- the template exception handler to use for handlingTemplateExceptions. By default,TemplateExceptionHandler.HTML_DEBUG_HANDLERis used.
-
getTemplateExceptionHandler
Retrieves the exception handler used to handle template exceptions. -
setArithmeticEngine
public void setArithmeticEngine(freemarker.core.ast.ArithmeticEngine arithmeticEngine) Sets the arithmetic engine used to perform arithmetic operations.- Parameters:
arithmeticEngine- the arithmetic engine used to perform arithmetic operations.By default,ArithmeticEngine.BIGDECIMAL_ENGINEis used.
-
getArithmeticEngine
public freemarker.core.ast.ArithmeticEngine getArithmeticEngine()Retrieves the arithmetic engine used to perform arithmetic operations. -
setObjectWrapper
Sets the object wrapper used to wrap objects to template models.- Parameters:
objectWrapper- the object wrapper used to wrap objects to template models.
-
getObjectWrapper
Retrieves the object wrapper used to wrap objects to template models. -
setOutputEncoding
Sets the output encoding. Allowsnull, which means that the output encoding is not known. -
setNumbersForComputers
public void setNumbersForComputers(boolean b) -
getOutputEncoding
-
setURLEscapingCharset
Sets the URL escaping charset. Allowsnull, which means that the output encoding will be used for URL escaping. -
getURLEscapingCharset
-
setSetting
Sets a setting by a name and string value.List of supported names and their valid values:
"locale": local codes with the usual format, such as"en_US"."template_exception_handler": If the value contains dot, then it is interpreted as class name, and the object will be created with its parameterless constructor. If the value does not contain dot, then it must be one of these special values:"rethrow","debug","html_debug","ignore"(case insensitive)."arithmetic_engine": If the value contains dot, then it is interpreted as class name, and the object will be created with its parameterless constructor. If the value does not contain dot, then it must be one of these special values:"bigdecimal","conservative"(case insensitive)."object_wrapper": If the value contains dot, then it is interpreted as class name, and the object will be created with its parameterless constructor. If the value does not contain dot, then it must be one of these special values:"simple","beans","jython"(case insensitive)."number_format": pattern asjava.text.DecimalFormatdefines."boolean_format": the textual value for boolean true and false, separated with comma. For example"yes,no"."date_format", "time_format", "datetime_format": patterns asjava.text.SimpleDateFormatdefines."time_zone": time zone, with the format asjava.util.TimeZone.getTimeZonedefines. For example"GMT-8:00"or"America/Los_Angeles""output_encoding": Informs FreeMarker about the charset used for the output. As FreeMarker outputs character stream (not byte stream), it is not aware of the output charset unless the software that encloses it tells it explicitly with this setting. Some templates may use FreeMarker features that require this."url_escaping_charset": If this setting is set, then it overrides the value of the"output_encoding"setting when FreeMarker does URL encoding.
- Parameters:
key- the name of the setting.value- the string that describes the new value of the setting.- Throws:
Configurable.UnknownSettingException- if the key is wrong.TemplateException- if the new value of the setting can't be set for any other reasons.
-
setStrictBeanModels
public void setStrictBeanModels(boolean strict) -
getSetting
Deprecated.This method was always defective, and certainly it always will be. Don't use it. (Simply, it's hardly possible in general to convert setting values to text in a way that ensures thatsetSetting(String, String)will work with them correctly.)Returns the textual representation of a setting.- Parameters:
key- the setting key. Can be any of standard XXX_KEY constants, or a custom key.
-
getSettings
Deprecated.This method was always defective, and certainly it always will be. Don't use it. (Simply, it's hardly possible in general to convert setting values to text in a way that ensures thatsetSettings(Properties)will work with them correctly.)This meant to return the String-to-StringMapof the settings. So it actually should return aPropertiesobject, but it doesn't by mistake. The returnedMapis read-only, but it will reflect the further configuration changes (aliasing effect). -
getEnvironment
-
unknownSettingException
-
invalidSettingValueException
-
setSettings
Set the settings stored in aPropertiesobject.- Throws:
TemplateException- if thePropertiesobject contains invalid keys, or invalid setting values, or any other error occurs while changing the settings.
-
setSettings
Reads a setting list (key and element pairs) from the input stream. The stream has to follow the usual.propertiesformat.- Throws:
TemplateException- if the stream contains invalid keys, or invalid setting values, or any other error occurs while changing the settings.IOException- if an error occurred when reading from the input stream.
-
setCustomAttribute
Sets a named custom attribute for this configurable.- Parameters:
name- the name of the custom attributevalue- the value of the custom attribute. You can set the value to null, however note that there is a semantic difference between an attribute set to null and an attribute that is not present, seeremoveCustomAttribute(String).
-
getCustomAttributeNames
Returns an array with names of all custom attributes defined directly on this configurable. (That is, it doesn't contain the names of custom attributes defined indirectly on its parent configurables.) The returned array is never null, but can be zero-length. The order of elements in the returned array is not defined and can change between invocations. -
removeCustomAttribute
Removes a named custom attribute for this configurable. Note that this is different than setting the custom attribute value to null. If you set the value to null,getCustomAttribute(String)will return null, while if you remove the attribute, it will return the value of the attribute in the parent configurable (if there is a parent configurable, that is).- Parameters:
name- the name of the custom attribute
-
getCustomAttribute
Retrieves a named custom attribute for this configurable. If the attribute is not present in the configurable, and the configurable has a parent, then the parent is looked up as well.- Parameters:
name- the name of the custom attribute- Returns:
- the value of the custom attribute. Note that if the custom attribute
was created with <#ftl attributes={...}>, then this value is already
unwrapped (i.e. it's a
String, or aList, or aMap, ...etc., not a FreeMarker specific class).
-
doAutoImportsAndIncludes
- Throws:
TemplateExceptionIOException
-