freemarker-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ddek...@apache.org
Subject [07/24] incubator-freemarker git commit: Added more information about configuring FreeMarker with string-string key-value pairs.
Date Tue, 06 Dec 2016 22:30:02 GMT
Added more information about configuring FreeMarker with string-string key-value pairs.


Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/58cba5b9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/58cba5b9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/58cba5b9

Branch: refs/heads/2.3
Commit: 58cba5b961154f374989c6eab49e8560623db9de
Parents: 0815e14
Author: ddekany <ddekany@apache.org>
Authored: Thu Aug 11 20:29:46 2016 +0200
Committer: ddekany <ddekany@apache.org>
Committed: Thu Aug 11 20:29:46 2016 +0200

----------------------------------------------------------------------
 src/manual/en_US/book.xml | 37 +++++++++++++++++++++++++++++++------
 1 file changed, 31 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/58cba5b9/src/manual/en_US/book.xml
----------------------------------------------------------------------
diff --git a/src/manual/en_US/book.xml b/src/manual/en_US/book.xml
index b93691a..c6b0c38 100644
--- a/src/manual/en_US/book.xml
+++ b/src/manual/en_US/book.xml
@@ -8083,7 +8083,11 @@ cfg.setSharedVariable("company", "Foo Inc.");</programlisting>
 
             <programlisting role="unspecified">Configuration myCfg = new Configuration(Configuration.VERSION_2_3_25);
 myCfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
-myCfg.setDefaultEncoding("UTF-8");</programlisting>
+myCfg.setDefaultEncoding("UTF-8");
+DefaultObjectWrapperBuilder owb = new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_25);
+owb.setForceLegacyNonListCollections(false);
+owb.setDefaultDateType(TemplateDateModel.DATETIME);
+myCfg.setObjectWrapper(owb.build());</programlisting>
 
             <para>You do this before you start to actually use the
             <literal>Configuration</literal> object (typically, when you
@@ -8109,14 +8113,35 @@ myCfg.setDefaultEncoding("UTF-8");</programlisting>
       &lt;prop key="incompatible_improvements"&gt;2.3.25&lt;/prop&gt;
       &lt;prop key="template_exception_handler"&gt;rethrow&lt;/prop&gt;
       &lt;prop key="default_encoding"&gt;UTF-8&lt;/prop&gt;
+      &lt;prop key="object_wrapper"&gt;
+        DefaultObjectWrapper(
+                2.3.25,
+                forceLegacyNonListCollections = false,
+                defaultDateType = freemarker.template.TemplateDateModel.DATETIME)
+      &lt;/prop&gt;
     &lt;/props&gt;
   &lt;/property&gt;
 &lt;/bean&gt;</programlisting>
 
-            <para>Note that this kind of configuring
-            (<literal>String</literal> key-value pairs) is somewhat limited
-            compared to directly using Java API, so in some cases you have to
-            find a way to do this in Java.</para>
+            <para>Here's the same when configuring FreeMarker for Struts,
+            which looks for a <literal>freemarker.properties</literal> in the
+            classpath:</para>
+
+            <programlisting role="unspecified">incompatible_improvements=2.3.25
+template_exception_handler=rethrow
+default_encoding=UTF-8
+object_wrapper=DefaultObjectWrapper( \
+        2.3.25, \
+        forceLegacyNonListCollections = false, \
+        defaultDateType = freemarker.template.TemplateDateModel.DATETIME)</programlisting>
+
+            <para>As demonstrated above with
+            <literal>object_wrapper</literal>, some settings can accept quite
+            complex values, which can be used to instantiate objects of
+            arbitrary classes and set their properties. Still, configuring
+            with <literal>String</literal> key-value pairs is limited compared
+            to directly using the Java API, so in some cases you have to find
+            a way to do this in Java.</para>
           </listitem>
 
           <listitem>
@@ -8153,7 +8178,7 @@ myCfg.setDefaultEncoding("UTF-8");</programlisting>
               should set <link
               linkend="pgui_config_incompatible_improvements">the
               <literal>incompatible_improvements</literal> setting</link>
to
-              2.3.22 or higher, to avoid soe confusing legacy bugs.</para>
+              2.3.22 or higher, to avoid some confusing legacy bugs.</para>
             </note>
           </listitem>
 


Mime
View raw message