Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 39242200BE4 for ; Tue, 6 Dec 2016 23:30:02 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 37FE1160B17; Tue, 6 Dec 2016 22:30:02 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 874DC160B30 for ; Tue, 6 Dec 2016 23:30:01 +0100 (CET) Received: (qmail 30009 invoked by uid 500); 6 Dec 2016 22:30:00 -0000 Mailing-List: contact notifications-help@freemarker.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@freemarker.incubator.apache.org Delivered-To: mailing list notifications@freemarker.incubator.apache.org Received: (qmail 29970 invoked by uid 99); 6 Dec 2016 22:30:00 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 06 Dec 2016 22:30:00 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id 3FE5AC896F for ; Tue, 6 Dec 2016 22:30:00 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -6.219 X-Spam-Level: X-Spam-Status: No, score=-6.219 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-2.999] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id Zaco3hAlqv4l for ; Tue, 6 Dec 2016 22:29:58 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with SMTP id B31535FD15 for ; Tue, 6 Dec 2016 22:29:57 +0000 (UTC) Received: (qmail 29230 invoked by uid 99); 6 Dec 2016 22:29:57 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 06 Dec 2016 22:29:57 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id B5091DFF56; Tue, 6 Dec 2016 22:29:56 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: ddekany@apache.org To: notifications@freemarker.incubator.apache.org Date: Tue, 06 Dec 2016 22:30:02 -0000 Message-Id: In-Reply-To: <05bcaa7349b249bca60d129188d4364f@git.apache.org> References: <05bcaa7349b249bca60d129188d4364f@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [07/24] incubator-freemarker git commit: Added more information about configuring FreeMarker with string-string key-value pairs. archived-at: Tue, 06 Dec 2016 22:30:02 -0000 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 Authored: Thu Aug 11 20:29:46 2016 +0200 Committer: ddekany 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."); Configuration myCfg = new Configuration(Configuration.VERSION_2_3_25); myCfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER); -myCfg.setDefaultEncoding("UTF-8"); +myCfg.setDefaultEncoding("UTF-8"); +DefaultObjectWrapperBuilder owb = new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_25); +owb.setForceLegacyNonListCollections(false); +owb.setDefaultDateType(TemplateDateModel.DATETIME); +myCfg.setObjectWrapper(owb.build()); You do this before you start to actually use the Configuration object (typically, when you @@ -8109,14 +8113,35 @@ myCfg.setDefaultEncoding("UTF-8"); <prop key="incompatible_improvements">2.3.25</prop> <prop key="template_exception_handler">rethrow</prop> <prop key="default_encoding">UTF-8</prop> + <prop key="object_wrapper"> + DefaultObjectWrapper( + 2.3.25, + forceLegacyNonListCollections = false, + defaultDateType = freemarker.template.TemplateDateModel.DATETIME) + </prop> </props> </property> </bean> - Note that this kind of configuring - (String 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. + Here's the same when configuring FreeMarker for Struts, + which looks for a freemarker.properties in the + classpath: + + 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) + + As demonstrated above with + object_wrapper, some settings can accept quite + complex values, which can be used to instantiate objects of + arbitrary classes and set their properties. Still, configuring + with String 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. @@ -8153,7 +8178,7 @@ myCfg.setDefaultEncoding("UTF-8"); should set the incompatible_improvements setting to - 2.3.22 or higher, to avoid soe confusing legacy bugs. + 2.3.22 or higher, to avoid some confusing legacy bugs.