freemarker-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ddek...@apache.org
Subject [10/36] incubator-freemarker git commit: FREEMARKER-55: read message args from positioned vargs.
Date Wed, 13 Sep 2017 09:49:11 GMT
FREEMARKER-55: read message args from positioned vargs.


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

Branch: refs/heads/3
Commit: 8f5eaaaf2df1914fef461802f2d7b511d4a99870
Parents: 3b83475
Author: Woonsan Ko <woonsan@apache.org>
Authored: Sun Sep 3 00:08:31 2017 -0400
Committer: Woonsan Ko <woonsan@apache.org>
Committed: Sun Sep 3 00:08:31 2017 -0400

----------------------------------------------------------------------
 .../freemarker/spring/model/MessageFunction.java     | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/8f5eaaaf/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/MessageFunction.java
----------------------------------------------------------------------
diff --git a/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/MessageFunction.java
b/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/MessageFunction.java
index d440963..7bee8c1 100644
--- a/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/MessageFunction.java
+++ b/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/MessageFunction.java
@@ -19,6 +19,7 @@
 
 package org.apache.freemarker.spring.model;
 
+import java.util.ArrayList;
 import java.util.List;
 
 import javax.servlet.http.HttpServletRequest;
@@ -29,7 +30,9 @@ import org.apache.freemarker.core.Environment;
 import org.apache.freemarker.core.TemplateException;
 import org.apache.freemarker.core.model.ArgumentArrayLayout;
 import org.apache.freemarker.core.model.ObjectWrapperAndUnwrapper;
+import org.apache.freemarker.core.model.TemplateCollectionModel;
 import org.apache.freemarker.core.model.TemplateModel;
+import org.apache.freemarker.core.model.TemplateModelIterator;
 import org.apache.freemarker.core.model.impl.SimpleString;
 import org.apache.freemarker.core.util.CallableUtils;
 import org.apache.freemarker.core.util.StringToIndexMap;
@@ -41,6 +44,7 @@ public class MessageFunction extends AbstractSpringTemplateFunctionModel
{
 
     private static final int CODE_PARAM_IDX = 0;
     private static final int MESSAGE_PARAM_IDX = 1;
+    private static final int MESSAGE_ARGS_PARAM_IDX = 2;
 
     private static final String MESSAGE_PARAM_NAME = "message";
 
@@ -71,8 +75,17 @@ public class MessageFunction extends AbstractSpringTemplateFunctionModel
{
         final String code = CallableUtils.getStringArgument(args, CODE_PARAM_IDX, this);
 
         if (code != null && !code.isEmpty()) {
+            final TemplateCollectionModel messageArgsModel = (TemplateCollectionModel) args[MESSAGE_ARGS_PARAM_IDX];
             List<Object> msgArgumentList = null;
-            // TODO: How to read message arguments from the varags?
+
+            if (!messageArgsModel.isEmptyCollection()) {
+                msgArgumentList = new ArrayList<>();
+                TemplateModel msgArgModel;
+                for (TemplateModelIterator tit = messageArgsModel.iterator(); tit.hasNext();
) {
+                    msgArgModel = tit.next();
+                    msgArgumentList.add(objectWrapperAndUnwrapper.unwrap(msgArgModel));
+                }
+            }
 
             // TODO: Is it okay to set the default value to null to avoid NoSuchMessageException
from Spring MessageSource?
             message = messageSource.getMessage(code, (msgArgumentList == null) ? null : msgArgumentList.toArray(),


Mime
View raw message