Method from freemarker.core.Configurable Detail: |
protected Object clone() throws CloneNotSupportedException {
Configurable copy = (Configurable)super.clone();
copy.properties = new Properties(properties);
copy.customAttributes = (HashMap)customAttributes.clone();
return copy;
}
|
public ArithmeticEngine getArithmeticEngine() {
return arithmeticEngine != null
? arithmeticEngine : parent.getArithmeticEngine();
}
Retrieves the arithmetic engine used to perform arithmetic operations. |
public String getBooleanFormat() {
if(trueFormat == null) {
return parent.getBooleanFormat();
}
return trueFormat + COMMA + falseFormat;
}
|
String getBooleanFormat(boolean value) {
return value ? getTrueFormat() : getFalseFormat();
}
|
public Object getCustomAttribute(String name) {
Object retval;
synchronized(customAttributes) {
retval = customAttributes.get(name);
if(retval == null && customAttributes.containsKey(name)) {
return null;
}
}
if(retval == null && parent != null) {
return parent.getCustomAttribute(name);
}
return retval;
}
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. |
Object getCustomAttribute(Object key,
CustomAttribute attr) {
synchronized(customAttributes) {
Object o = customAttributes.get(key);
if(o == null && !customAttributes.containsKey(key)) {
o = attr.create();
customAttributes.put(key, o);
}
return o;
}
}
Internal entry point for getting unnamed custom attributes |
public String[] getCustomAttributeNames() {
synchronized(customAttributes) {
Collection names = new LinkedList(customAttributes.keySet());
for (Iterator iter = names.iterator(); iter.hasNext();) {
if(!(iter.next() instanceof String)) {
iter.remove();
}
}
return (String[])names.toArray(new String[names.size()]);
}
}
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. |
public String getDateFormat() {
return dateFormat != null ? dateFormat : parent.getDateFormat();
}
Returns the date format used to convert date models representing
date-only dates to strings.
Defaults to "date" |
public String getDateTimeFormat() {
return dateTimeFormat != null ? dateTimeFormat : parent.getDateTimeFormat();
}
Returns the date format used to convert date models representing datetime
dates to strings.
Defaults to "datetime" |
protected Environment getEnvironment() {
return this instanceof Environment
? (Environment) this
: Environment.getCurrentEnvironment();
}
|
public Locale getLocale() {
return locale != null ? locale : parent.getLocale();
}
Returns the assumed locale when searching for template files with no
explicit requested locale. Defaults to system locale. |
public String getNumberFormat() {
return numberFormat != null ? numberFormat : parent.getNumberFormat();
}
Returns the default number format used to convert numbers to strings.
Defaults to "number" |
public ObjectWrapper getObjectWrapper() {
return objectWrapper != null
? objectWrapper : parent.getObjectWrapper();
}
Retrieves the object wrapper used to wrap objects to template models. |
public String getOutputEncoding() {
return outputEncodingSet
? outputEncoding
: (parent != null ? parent.getOutputEncoding() : null);
}
|
public final Configurable getParent() {
return parent;
}
Returns the parent Configurable object of this object.
The parent stores the default values for this configurable. For example,
the parent of the freemarker.template.Template object is the
freemarker.template.Configuration object, so setting values not
specfied on template level are specified by the confuration object. |
public String getSetting(String key) {
return properties.getProperty(key);
} 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 that
#setSetting(String, String) will work with them correctly.)
Returns the textual representation of a setting. |
public Map getSettings() {
return Collections.unmodifiableMap(properties);
} 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 that
#setSettings(Properties) will work with them correctly.)
This meant to return the String-to-String Map of the
settings. So it actually should return a Properties object,
but it doesn't by mistake. The returned Map is read-only,
but it will reflect the further configuration changes (aliasing effect). |
public TemplateExceptionHandler getTemplateExceptionHandler() {
return templateExceptionHandler != null
? templateExceptionHandler : parent.getTemplateExceptionHandler();
}
Retrieves the exception handler used to handle template exceptions. |
public String getTimeFormat() {
return timeFormat != null ? timeFormat : parent.getTimeFormat();
}
Returns the date format used to convert date models representing
time-only dates to strings.
Defaults to "time" |
public TimeZone getTimeZone() {
return timeZone != null ? timeZone : parent.getTimeZone();
}
Returns the time zone to use when formatting time values. Defaults to
system time zone. |
public String getURLEscapingCharset() {
return urlEscapingCharsetSet
? urlEscapingCharset
: (parent != null ? parent.getURLEscapingCharset() : null);
}
|
protected TemplateException invalidSettingValueException(String name,
String value) {
return new TemplateException("Invalid value for setting " + name + ": " + value, getEnvironment());
}
|
public boolean isClassicCompatible() {
return classicCompatible != null ? classicCompatible.booleanValue() : parent.isClassicCompatible();
}
Returns whether the engine runs in the "Classic Compatibile" mode.
When this mode is active, the engine behavior is altered in following
way: (these resemble the behavior of the 1.7.x line of FreeMarker engine,
now named "FreeMarker Classic", hence the name).
- handle undefined expressions gracefully. Namely when an expression
"expr" evaluates to null:
- as argument of the <assign varname=expr> directive,
${expr} directive, otherexpr == expr or
otherexpr != expr conditional expressions, or
hash[expr] expression, then it is treated as empty string.
- as argument of <list expr as item> or
<foreach item in expr>, the loop body is not executed
(as if it were a 0-length list)
- as argument of <if> directive, or otherwise where a
boolean expression is expected, it is treated as false
- Non-boolean models are accepted in <if> directive,
or as operands of logical operators. "Empty" models (zero-length string,
empty sequence or hash) are evaluated as false, all others are evaluated as
true.
- When boolean value is treated as a string (i.e. output in
${...} directive, or concatenated with other string), true
values are converted to string "true", false values are converted to
empty string.
- Scalar models supplied to <list> and
<foreach> are treated as a one-element list consisting
of the passed model.
- Paths parameter of <include> will be interpreted as
absolute path.
In all other aspects, the engine is a 2.1 engine even in compatibility
mode - you don't lose any of the new functionality by enabling it. |
public void removeCustomAttribute(String name) {
synchronized(customAttributes) {
customAttributes.remove(name);
}
}
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). |
public void setArithmeticEngine(ArithmeticEngine arithmeticEngine) {
if (arithmeticEngine == null) throw new IllegalArgumentException("Setting \"arithmetic_engine\" can't be null");
this.arithmeticEngine = arithmeticEngine;
properties.setProperty(ARITHMETIC_ENGINE_KEY, arithmeticEngine.getClass().getName());
}
Sets the arithmetic engine used to perform arithmetic operations. |
public void setBooleanFormat(String booleanFormat) {
if (booleanFormat == null) {
throw new IllegalArgumentException("Setting \"boolean_format\" can't be null");
}
int comma = booleanFormat.indexOf(COMMA);
if(comma == -1) {
throw new IllegalArgumentException("Setting \"boolean_format\" must consist of two comma-separated values for true and false respectively");
}
trueFormat = booleanFormat.substring(0, comma);
falseFormat = booleanFormat.substring(comma + 1);
properties.setProperty(BOOLEAN_FORMAT_KEY, booleanFormat);
}
|
public void setClassicCompatible(boolean classicCompatibility) {
this.classicCompatible = classicCompatibility ? Boolean.TRUE : Boolean.FALSE;
properties.setProperty(CLASSIC_COMPATIBLE_KEY, classicCompatible.toString());
}
Toggles the "Classic Compatibile" mode. For a comprehensive description
of this mode, see #isClassicCompatible() . |
void setCustomAttribute(Object key,
Object value) {
synchronized(customAttributes) {
customAttributes.put(key, value);
}
}
Internal entry point for setting unnamed custom attributes |
public void setCustomAttribute(String name,
Object value) {
synchronized(customAttributes) {
customAttributes.put(name, value);
}
}
Sets a named custom attribute for this configurable. |
public void setDateFormat(String dateFormat) {
if (dateFormat == null) throw new IllegalArgumentException("Setting \"date_format\" can't be null");
this.dateFormat = dateFormat;
properties.setProperty(DATE_FORMAT_KEY, dateFormat);
}
Sets the date format used to convert date models representing date-only
dates to strings. |
public void setDateTimeFormat(String dateTimeFormat) {
if (dateTimeFormat == null) throw new IllegalArgumentException("Setting \"datetime_format\" can't be null");
this.dateTimeFormat = dateTimeFormat;
properties.setProperty(DATETIME_FORMAT_KEY, dateTimeFormat);
}
Sets the date format used to convert date models representing datetime
dates to strings. |
public void setLocale(Locale locale) {
if (locale == null) throw new IllegalArgumentException("Setting \"locale\" can't be null");
this.locale = locale;
properties.setProperty(LOCALE_KEY, locale.toString());
}
Sets the locale to assume when searching for template files with no
explicit requested locale. |
public void setNumberFormat(String numberFormat) {
if (numberFormat == null) throw new IllegalArgumentException("Setting \"number_format\" can't be null");
this.numberFormat = numberFormat;
properties.setProperty(NUMBER_FORMAT_KEY, numberFormat);
}
Sets the number format used to convert numbers to strings. |
public void setObjectWrapper(ObjectWrapper objectWrapper) {
if (objectWrapper == null) throw new IllegalArgumentException("Setting \"object_wrapper\" can't be null");
this.objectWrapper = objectWrapper;
properties.setProperty(OBJECT_WRAPPER_KEY, objectWrapper.getClass().getName());
}
Sets the object wrapper used to wrap objects to template models. |
public void setOutputEncoding(String outputEncoding) {
this.outputEncoding = outputEncoding;
// java.util.Properties doesn't allow null value!
if (outputEncoding != null) {
properties.setProperty(OUTPUT_ENCODING_KEY, outputEncoding);
} else {
properties.remove(OUTPUT_ENCODING_KEY);
}
outputEncodingSet = true;
}
Sets the output encoding. Allows null , which means that the
output encoding is not known. |
final void setParent(Configurable parent) {
this.parent = parent;
}
Reparenting support. This is used by Environment when it includes a
template - the included template becomes the parent configurable during
its evaluation. |
public void setSetting(String key,
String value) throws TemplateException {
try {
if (LOCALE_KEY.equals(key)) {
setLocale(StringUtil.deduceLocale(value));
} else if (NUMBER_FORMAT_KEY.equals(key)) {
setNumberFormat(value);
} else if (TIME_FORMAT_KEY.equals(key)) {
setTimeFormat(value);
} else if (DATE_FORMAT_KEY.equals(key)) {
setDateFormat(value);
} else if (DATETIME_FORMAT_KEY.equals(key)) {
setDateTimeFormat(value);
} else if (TIME_ZONE_KEY.equals(key)) {
setTimeZone(TimeZone.getTimeZone(value));
} else if (CLASSIC_COMPATIBLE_KEY.equals(key)) {
setClassicCompatible(StringUtil.getYesNo(value));
} else if (TEMPLATE_EXCEPTION_HANDLER_KEY.equals(key)) {
if (value.indexOf('.") == -1) {
if ("debug".equalsIgnoreCase(value)) {
setTemplateExceptionHandler(
TemplateExceptionHandler.DEBUG_HANDLER);
} else if ("html_debug".equalsIgnoreCase(value)) {
setTemplateExceptionHandler(
TemplateExceptionHandler.HTML_DEBUG_HANDLER);
} else if ("ignore".equalsIgnoreCase(value)) {
setTemplateExceptionHandler(
TemplateExceptionHandler.IGNORE_HANDLER);
} else if ("rethrow".equalsIgnoreCase(value)) {
setTemplateExceptionHandler(
TemplateExceptionHandler.RETHROW_HANDLER);
} else {
throw invalidSettingValueException(key, value);
}
} else {
setTemplateExceptionHandler(
(TemplateExceptionHandler) ClassUtil.forName(value)
.newInstance());
}
} else if (ARITHMETIC_ENGINE_KEY.equals(key)) {
if (value.indexOf('.") == -1) {
if ("bigdecimal".equalsIgnoreCase(value)) {
setArithmeticEngine(ArithmeticEngine.BIGDECIMAL_ENGINE);
} else if ("conservative".equalsIgnoreCase(value)) {
setArithmeticEngine(ArithmeticEngine.CONSERVATIVE_ENGINE);
} else {
throw invalidSettingValueException(key, value);
}
} else {
setArithmeticEngine(
(ArithmeticEngine) ClassUtil.forName(value)
.newInstance());
}
} else if (OBJECT_WRAPPER_KEY.equals(key)) {
if (value.indexOf('.") == -1) {
if ("default".equalsIgnoreCase(value)) {
setObjectWrapper(ObjectWrapper.DEFAULT_WRAPPER);
} else if ("simple".equalsIgnoreCase(value)) {
setObjectWrapper(ObjectWrapper.SIMPLE_WRAPPER);
} else if ("beans".equalsIgnoreCase(value)) {
setObjectWrapper(ObjectWrapper.BEANS_WRAPPER);
} else if ("jython".equalsIgnoreCase(value)) {
Class clazz = Class.forName(
"freemarker.ext.jython.JythonWrapper");
setObjectWrapper(
(ObjectWrapper) clazz.getField("INSTANCE").get(null));
} else {
throw invalidSettingValueException(key, value);
}
} else {
setObjectWrapper((ObjectWrapper) ClassUtil.forName(value)
.newInstance());
}
} else if (BOOLEAN_FORMAT_KEY.equals(key)) {
setBooleanFormat(value);
} else if (OUTPUT_ENCODING_KEY.equals(key)) {
setOutputEncoding(value);
} else if (URL_ESCAPING_CHARSET_KEY.equals(key)) {
setURLEscapingCharset(value);
} else if (STRICT_BEAN_MODELS.equals(key)) {
setStrictBeanModels(StringUtil.getYesNo(value));
}
else {
throw unknownSettingException(key);
}
} catch(TemplateException e) {
throw e;
} catch(Exception e) {
throw new TemplateException(
"Failed to set setting " + key + " to value " + value,
e, getEnvironment());
}
}
|
public void setSettings(Properties props) throws TemplateException {
Iterator it = props.keySet().iterator();
while (it.hasNext()) {
String key = (String) it.next();
setSetting(key, props.getProperty(key).trim());
}
}
Set the settings stored in a Properties object. |
public void setSettings(InputStream propsIn) throws IOException, TemplateException {
Properties p = new Properties();
p.load(propsIn);
setSettings(p);
}
Reads a setting list (key and element pairs) from the input stream.
The stream has to follow the usual .properties format. |
public void setStrictBeanModels(boolean strict) {
if (!(objectWrapper instanceof BeansWrapper)) {
throw new IllegalStateException("Not a beans wrapper");
}
((BeansWrapper) objectWrapper).setStrict(strict);
}
|
public void setTemplateExceptionHandler(TemplateExceptionHandler templateExceptionHandler) {
if (templateExceptionHandler == null) throw new IllegalArgumentException("Setting \"template_exception_handler\" can't be null");
this.templateExceptionHandler = templateExceptionHandler;
properties.setProperty(TEMPLATE_EXCEPTION_HANDLER_KEY, templateExceptionHandler.getClass().getName());
}
Sets the exception handler used to handle template exceptions. |
public void setTimeFormat(String timeFormat) {
if (timeFormat == null) throw new IllegalArgumentException("Setting \"time_format\" can't be null");
this.timeFormat = timeFormat;
properties.setProperty(TIME_FORMAT_KEY, timeFormat);
}
Sets the date format used to convert date models representing time-only
values to strings. |
public void setTimeZone(TimeZone timeZone) {
if (timeZone == null) throw new IllegalArgumentException("Setting \"time_zone\" can't be null");
this.timeZone = timeZone;
properties.setProperty(TIME_ZONE_KEY, timeZone.getID());
}
Sets the time zone to use when formatting time values. |
public void setURLEscapingCharset(String urlEscapingCharset) {
this.urlEscapingCharset = urlEscapingCharset;
// java.util.Properties doesn't allow null value!
if (urlEscapingCharset != null) {
properties.setProperty(URL_ESCAPING_CHARSET_KEY, urlEscapingCharset);
} else {
properties.remove(URL_ESCAPING_CHARSET_KEY);
}
urlEscapingCharsetSet = true;
}
Sets the URL escaping charset. Allows null , which means that the
output encoding will be used for URL escaping. |
protected TemplateException unknownSettingException(String name) {
return new UnknownSettingException(name, getEnvironment());
}
|