Some tidying up, name changes and clarifications. I went with "defaultValue"

rather than "missingVariableValue" because the value is used any time a
variable resolves to null, not necessarily just when it is missing. If you
have a context like:

new Object() {
   String foo = null;
}

and reference {{foo}} in your template, foo is not missing, per se, but the
default value will still be used for it.
This commit is contained in:
Michael Bayne
2011-04-15 12:35:33 -07:00
parent 5d59eada29
commit 15ff48eabb
3 changed files with 29 additions and 30 deletions
@@ -126,10 +126,14 @@ public class Template
return null;
}
protected Object getValueWithDefault (Context ctx, String name, int line)
/**
* Returns the value for the specified variable, or the configured default value if the
* variable resolves to null. See {@link #getValue}.
*/
protected Object getValueOrDefault (Context ctx, String name, int line)
{
Object value = getValue(ctx, name, line);
return value != null? value : _compiler.missingVariableValue;
return (value == null) ? _compiler.defaultValue : value;
}
protected Object getValueIn (Object data, String name, int line)