Repository: incubator-freemarker Updated Branches: refs/heads/2.3-gae cb5f3276c -> e3ed32a1f
When specifying the output_format configuration settings with String-String key-value pairs (like with Configuration.setSetting(String, String) or in a .properties file), it's now possible to specify the standard output formats by name rather than by class name (like output_format=HTML). (Custom formats still has to be referred by class name, as FreeMarker can't discover what their names are, since it's not aware of the custom classes.) Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/e3ed32a1 Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/e3ed32a1 Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/e3ed32a1 Branch: refs/heads/2.3-gae Commit: e3ed32a1f184bfb6f7f28a75e4f24a07a64cac21 Parents: cb5f327 Author: ddekany <ddek...@apache.org> Authored: Tue Mar 20 19:53:03 2018 +0100 Committer: ddekany <ddek...@apache.org> Committed: Tue Mar 20 19:53:03 2018 +0100 ---------------------------------------------------------------------- src/main/java/freemarker/template/Configuration.java | 7 +++++-- src/manual/en_US/book.xml | 14 ++++++++++++++ .../java/freemarker/template/ConfigurationTest.java | 5 +++++ 3 files changed, 24 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/e3ed32a1/src/main/java/freemarker/template/Configuration.java ---------------------------------------------------------------------- diff --git a/src/main/java/freemarker/template/Configuration.java b/src/main/java/freemarker/template/Configuration.java index 5376dda..8db9155 100644 --- a/src/main/java/freemarker/template/Configuration.java +++ b/src/main/java/freemarker/template/Configuration.java @@ -3178,8 +3178,11 @@ public class Configuration extends Configurable implements Cloneable, ParserConf if (value.equalsIgnoreCase(DEFAULT)) { unsetOutputFormat(); } else { - setOutputFormat((OutputFormat) _ObjectBuilderSettingEvaluator.eval( - value, OutputFormat.class, true, _SettingEvaluationEnvironment.getCurrent())); + OutputFormat stdOF = STANDARD_OUTPUT_FORMATS.get(value); + setOutputFormat( + stdOF != null ? stdOF + : (OutputFormat) _ObjectBuilderSettingEvaluator.eval( + value, OutputFormat.class, true, _SettingEvaluationEnvironment.getCurrent())); } } else if (REGISTERED_CUSTOM_OUTPUT_FORMATS_KEY_SNAKE_CASE.equals(name) || REGISTERED_CUSTOM_OUTPUT_FORMATS_KEY_CAMEL_CASE.equals(name)) { http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/e3ed32a1/src/manual/en_US/book.xml ---------------------------------------------------------------------- diff --git a/src/manual/en_US/book.xml b/src/manual/en_US/book.xml index eb4470f..0f49b3f 100644 --- a/src/manual/en_US/book.xml +++ b/src/manual/en_US/book.xml @@ -27696,6 +27696,20 @@ TemplateModel x = env.getVariable("x"); // get variable x</programlisting> </listitem> <listitem> + <para>When specifying the <literal>output_format</literal> + configuration settings with + <literal>String</literal>-<literal>String</literal> key-value + pairs (like with <literal>Configuration.setSetting(String, + String)</literal> or in a <literal>.properties</literal> file), + it's now possible to specify the standard output formats by name + rather than by class name (like + <literal>output_format=HTML</literal>). (Custom formats still + has to be referred by class name, as FreeMarker can't discover + what their names are, since it's not aware of the custom + classes.)</para> + </listitem> + + <listitem> <para>Added new property to <literal>BeansWrapper.MethodAppearanceDecision</literal>: <literal>replaceExistingProperty</literal>. This is useful when http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/e3ed32a1/src/test/java/freemarker/template/ConfigurationTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/freemarker/template/ConfigurationTest.java b/src/test/java/freemarker/template/ConfigurationTest.java index 72c1291..f3e8be9 100644 --- a/src/test/java/freemarker/template/ConfigurationTest.java +++ b/src/test/java/freemarker/template/ConfigurationTest.java @@ -75,6 +75,7 @@ import freemarker.core.TemplateDateFormatFactory; import freemarker.core.TemplateNumberFormatFactory; import freemarker.core.UndefinedOutputFormat; import freemarker.core.UnregisteredOutputFormatException; +import freemarker.core.XHTMLOutputFormat; import freemarker.core.XMLOutputFormat; import freemarker.core._CoreStringUtils; import freemarker.ext.beans.BeansWrapperBuilder; @@ -942,6 +943,10 @@ public class ConfigurationTest extends TestCase { cfg.setSetting(Configuration.OUTPUT_FORMAT_KEY_SNAKE_CASE, HTMLOutputFormat.class.getSimpleName()); assertEquals(HTMLOutputFormat.INSTANCE, cfg.getOutputFormat()); + + // Set standard format by name instead of class name: + cfg.setSetting(Configuration.OUTPUT_FORMAT_KEY_CAMEL_CASE, XHTMLOutputFormat.INSTANCE.getName()); + assertEquals(XHTMLOutputFormat.INSTANCE, cfg.getOutputFormat()); cfg.unsetOutputFormat(); assertEquals(UndefinedOutputFormat.INSTANCE, cfg.getOutputFormat());