When configuring FreeMarker with string values (like with a .properties file), in the settings that support the object builder syntax, now you can create a TemplateMarkupOutputModel value with the new markup function, like markup(HTMLOutputFormat(), "<p>Example</p>").
Project: http://git-wip-us.apache.org/repos/asf/freemarker/repo Commit: http://git-wip-us.apache.org/repos/asf/freemarker/commit/9fedabc9 Tree: http://git-wip-us.apache.org/repos/asf/freemarker/tree/9fedabc9 Diff: http://git-wip-us.apache.org/repos/asf/freemarker/diff/9fedabc9 Branch: refs/heads/2.3-gae Commit: 9fedabc92f0bbaea75d0715c3d56b9bf94fd2bb8 Parents: 62f9f43 Author: ddekany <[email protected]> Authored: Wed Dec 19 10:54:05 2018 +0100 Committer: ddekany <[email protected]> Committed: Wed Dec 19 11:09:48 2018 +0100 ---------------------------------------------------------------------- src/main/java/freemarker/core/Configurable.java | 5 +++ .../java/freemarker/core/_MarkupBuilder.java | 44 ++++++++++++++++++++ .../core/_ObjectBuilderSettingEvaluator.java | 1 + src/manual/en_US/book.xml | 10 +++++ 4 files changed, 60 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/freemarker/blob/9fedabc9/src/main/java/freemarker/core/Configurable.java ---------------------------------------------------------------------- diff --git a/src/main/java/freemarker/core/Configurable.java b/src/main/java/freemarker/core/Configurable.java index 3c83e94..28803f1 100644 --- a/src/main/java/freemarker/core/Configurable.java +++ b/src/main/java/freemarker/core/Configurable.java @@ -2505,6 +2505,11 @@ public class Configurable { * constructor (since 2.3.24). * </li> * <li> + * <p>{@link TemplateMarkupOutputModel} objects can be created like + * {@code markup(HTMLOutputFormat(), "<h1>Example</h1>")} (since 2.3.29). Of course the 1st argument can be + * any other {@link MarkupOutputFormat} too. + * </li> + * <li> * <p>The classes and methods that the expression meant to access must be all public. * </li> * </ul> http://git-wip-us.apache.org/repos/asf/freemarker/blob/9fedabc9/src/main/java/freemarker/core/_MarkupBuilder.java ---------------------------------------------------------------------- diff --git a/src/main/java/freemarker/core/_MarkupBuilder.java b/src/main/java/freemarker/core/_MarkupBuilder.java new file mode 100644 index 0000000..3a7decd --- /dev/null +++ b/src/main/java/freemarker/core/_MarkupBuilder.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package freemarker.core; + +import freemarker.template.TemplateModelException; + +/** + * For internal use only; don't depend on this, there's no backward compatibility guarantee at all! + * Used by {@link _ObjectBuilderSettingEvaluator}. + * + * @since 2.3.29 + */ +public class _MarkupBuilder<MO extends TemplateMarkupOutputModel> { + + private final String markupSource; + private final MarkupOutputFormat<MO> markupOutputFormat; + + public _MarkupBuilder(MarkupOutputFormat<MO> markupOutputFormat, String markupSource) { + this.markupOutputFormat = markupOutputFormat; + this.markupSource = markupSource; + } + + public MO build() throws TemplateModelException { + return markupOutputFormat.fromMarkup(markupSource); + } + +} http://git-wip-us.apache.org/repos/asf/freemarker/blob/9fedabc9/src/main/java/freemarker/core/_ObjectBuilderSettingEvaluator.java ---------------------------------------------------------------------- diff --git a/src/main/java/freemarker/core/_ObjectBuilderSettingEvaluator.java b/src/main/java/freemarker/core/_ObjectBuilderSettingEvaluator.java index ae99899..6475444 100644 --- a/src/main/java/freemarker/core/_ObjectBuilderSettingEvaluator.java +++ b/src/main/java/freemarker/core/_ObjectBuilderSettingEvaluator.java @@ -691,6 +691,7 @@ public class _ObjectBuilderSettingEvaluator { addWithSimpleName(SHORTHANDS, Locale.class); SHORTHANDS.put("TimeZone", "freemarker.core._TimeZone"); + SHORTHANDS.put("markup", "freemarker.core._Markup"); // For accessing static fields: addWithSimpleName(SHORTHANDS, Configuration.class); http://git-wip-us.apache.org/repos/asf/freemarker/blob/9fedabc9/src/manual/en_US/book.xml ---------------------------------------------------------------------- diff --git a/src/manual/en_US/book.xml b/src/manual/en_US/book.xml index 2a68d54..5b8a1ff 100644 --- a/src/manual/en_US/book.xml +++ b/src/manual/en_US/book.xml @@ -27663,6 +27663,16 @@ TemplateModel x = env.getVariable("x"); // get variable x</programlisting> (<literal>Map</literal> key-value pairs, bean properties, etc.) appear together on the top level of the data-model.</para> </listitem> + + <listitem> + <para>When configuring FreeMarker with string values (like with + a <literal>.properties</literal> file), in the settings that + support the <quote>object builder</quote> syntax, now you can + create a <literal>TemplateMarkupOutputModel</literal> value with + the new <literal>markup</literal> function, like + <literal>markup(HTMLOutputFormat(), + "<p>Example</p>")</literal>.</para> + </listitem> </itemizedlist> </section> </section>
