myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject svn commit: r936061 - in /myfaces/extensions/cdi/trunk/jse-modules/message-module: api/src/main/java/org/apache/myfaces/extensions/cdi/message/api/ impl/src/test/java/org/apache/myfaces/extensions/cdi/message/test/
Date Tue, 20 Apr 2010 21:10:13 GMT
Author: gpetracek
Date: Tue Apr 20 21:10:13 2010
New Revision: 936061

URL: http://svn.apache.org/viewvc?rev=936061&view=rev
Log:
EXTCDI-21 minor improvements

Modified:
    myfaces/extensions/cdi/trunk/jse-modules/message-module/api/src/main/java/org/apache/myfaces/extensions/cdi/message/api/AbstractMessage.java
    myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/message/test/SimpleMessageTest.java

Modified: myfaces/extensions/cdi/trunk/jse-modules/message-module/api/src/main/java/org/apache/myfaces/extensions/cdi/message/api/AbstractMessage.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jse-modules/message-module/api/src/main/java/org/apache/myfaces/extensions/cdi/message/api/AbstractMessage.java?rev=936061&r1=936060&r2=936061&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jse-modules/message-module/api/src/main/java/org/apache/myfaces/extensions/cdi/message/api/AbstractMessage.java
(original)
+++ myfaces/extensions/cdi/trunk/jse-modules/message-module/api/src/main/java/org/apache/myfaces/extensions/cdi/message/api/AbstractMessage.java
Tue Apr 20 21:10:13 2010
@@ -87,23 +87,60 @@ public abstract class AbstractMessage im
             {
                 argument = "null";
             }
-            else if(argument instanceof Localizable && this.getMessageContextConfig()
!= null)
-            {
-                argument = ((Localizable)argument).toString(this.getMessageContextConfig().use().create());
-            }
-            
-            checkArgument(argument);
-            if (argument instanceof NamedArgument)
+
+            if(isHiddenArgument(argument))
             {
-                addNamedArgument((NamedArgument) argument);
+                addHiddenArgument(argument);
             }
             else
             {
-                addNumberedArgument(argument);
+                addArgumentToMessage(argument);
             }
         }
     }
 
+    private void addArgumentToMessage(Object argument)
+    {
+        //TODO
+        if(argument instanceof Localizable && this.getMessageContextConfig() != null)
+        {
+            argument = ((Localizable)argument).toString(this.getMessageContextConfig().use().create());
+        }
+
+        Serializable result;
+
+        if(argument instanceof Serializable)
+        {
+            result = (Serializable)argument;
+        }
+        else
+        {
+            result = argument != null ? argument.toString() : "null";
+        }
+        checkArgument(result);
+        if (argument instanceof NamedArgument)
+        {
+            addNamedArgument((NamedArgument) argument);
+        }
+        else
+        {
+            addNumberedArgument(result);
+        }
+    }
+
+    private boolean isHiddenArgument(Serializable argument)
+    {
+        return argument != null && argument.getClass().isArray();
+    }
+
+    private void addHiddenArgument(Serializable argument)
+    {
+        for(Object current : ((Object[])argument))
+        {
+            addArgumentToMessage(current);
+        }
+    }
+
     private void checkArgument(Serializable argument)
     {
         if (argument instanceof NamedArgument)

Modified: myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/message/test/SimpleMessageTest.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/message/test/SimpleMessageTest.java?rev=936061&r1=936060&r2=936061&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/message/test/SimpleMessageTest.java
(original)
+++ myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/message/test/SimpleMessageTest.java
Tue Apr 20 21:10:13 2010
@@ -112,6 +112,14 @@ public class SimpleMessageTest extends A
    }
     
     @Test
+   public void createMessageWithHiddenArgumentsTest()
+   {
+       String messageText = this.messageContext.message().text("{xyz123}").argument(new String[]{"123",
"456", "789"}).toText();
+
+       assertEquals("???xyz123??? (123,456,789)", messageText);
+   }
+
+    @Test
     public void resolveTextTest()
     {
         String messageText = this.messageContext.message().text("{hello}").toText();



Mime
View raw message