You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@freemarker.apache.org by dd...@apache.org on 2019/09/22 21:48:53 UTC
[freemarker] 04/05: Added Environment.getDataModelOrSharedVariable
This is an automated email from the ASF dual-hosted git repository.
ddekany pushed a commit to branch 2.3-gae
in repository https://gitbox.apache.org/repos/asf/freemarker.git
commit 2453c91097023438a176bc5814da0c956d2f8b95
Author: ddekany <dd...@apache.org>
AuthorDate: Sat Sep 21 13:50:02 2019 +0200
Added Environment.getDataModelOrSharedVariable
---
src/main/java/freemarker/core/Environment.java | 26 +++++++++++++++++++-------
src/manual/en_US/book.xml | 11 ++++++-----
2 files changed, 25 insertions(+), 12 deletions(-)
diff --git a/src/main/java/freemarker/core/Environment.java b/src/main/java/freemarker/core/Environment.java
index 6136583..9d7a2f6 100644
--- a/src/main/java/freemarker/core/Environment.java
+++ b/src/main/java/freemarker/core/Environment.java
@@ -2099,13 +2099,26 @@ public final class Environment extends Configurable {
*/
public TemplateModel getGlobalVariable(String name) throws TemplateModelException {
TemplateModel result = globalNamespace.get(name);
- if (result == null) {
- result = rootDataModel.get(name);
+ if (result != null) {
+ return result;
}
- if (result == null) {
- result = configuration.getSharedVariable(name);
+
+ return getDataModelOrSharedVariable(name);
+ }
+
+ /**
+ * Returns the variable from the data-model, or if it's not there, then from the
+ * {@linkplain Configuration#setSharedVariables(Map)} shared variables}
+ *
+ * @since 2.3.30
+ */
+ public TemplateModel getDataModelOrSharedVariable(String name) throws TemplateModelException {
+ TemplateModel dataModelVal = rootDataModel.get(name);
+ if (dataModelVal != null) {
+ return dataModelVal;
}
- return result;
+
+ return configuration.getSharedVariable(name);
}
/**
@@ -2406,8 +2419,7 @@ public final class Environment extends Configurable {
}
public TemplateModel get(String key) throws TemplateModelException {
- TemplateModel value = rootDataModel.get(key);
- return value != null ? value : configuration.getSharedVariable(key);
+ return getDataModelOrSharedVariable(key);
}
// NB: The methods below do not take into account
diff --git a/src/manual/en_US/book.xml b/src/manual/en_US/book.xml
index 4b4ac2b..502debc 100644
--- a/src/manual/en_US/book.xml
+++ b/src/manual/en_US/book.xml
@@ -20,11 +20,7 @@
<book conformance="docgen" version="5.0" xml:lang="en"
xmlns="http://docbook.org/ns/docbook"
xmlns:xlink="http://www.w3.org/1999/xlink"
- xmlns:xi="http://www.w3.org/2001/XInclude"
- xmlns:ns5="http://www.w3.org/1999/xhtml"
- xmlns:ns4="http://www.w3.org/2000/svg"
- xmlns:ns3="http://www.w3.org/1998/Math/MathML"
- xmlns:ns="http://docbook.org/ns/docbook">
+>
<info>
<title>Apache FreeMarker Manual</title>
@@ -28689,6 +28685,11 @@ TemplateModel x = env.getVariable("x"); // get variable x</programlisting>
<itemizedlist>
<listitem>
+ <para>Added
+ <literal>Environment.getDataModelOrSharedVariable(String)</literal>.</para>
+ </listitem>
+
+ <listitem>
<para>Bug fixed: In <literal><#escape
<replaceable>placeholder</replaceable> as
<replaceable>escExpression</replaceable>></literal>, the