You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@click.apache.org by sa...@apache.org on 2009/01/04 22:19:29 UTC

svn commit: r731361 - /incubator/click/trunk/click/framework/src/net/sf/click/util/Format.java

Author: sabob
Date: Sun Jan  4 13:19:28 2009
New Revision: 731361

URL: http://svn.apache.org/viewvc?rev=731361&view=rev
Log:
added MessageFormat support. CLK-474

Modified:
    incubator/click/trunk/click/framework/src/net/sf/click/util/Format.java

Modified: incubator/click/trunk/click/framework/src/net/sf/click/util/Format.java
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/framework/src/net/sf/click/util/Format.java?rev=731361&r1=731360&r2=731361&view=diff
==============================================================================
--- incubator/click/trunk/click/framework/src/net/sf/click/util/Format.java (original)
+++ incubator/click/trunk/click/framework/src/net/sf/click/util/Format.java Sun Jan  4 13:19:28 2009
@@ -21,9 +21,11 @@
 import java.io.Serializable;
 import java.text.DateFormat;
 import java.text.DecimalFormat;
+import java.text.MessageFormat;
 import java.text.NumberFormat;
 import java.text.SimpleDateFormat;
 import java.util.Date;
+import java.util.List;
 import java.util.Locale;
 
 import net.sf.click.Context;
@@ -682,6 +684,46 @@
     }
 
     /**
+     * Return a formatted string using the given message pattern and argument.
+     * See {@link java.text.MessageFormat} for information on the message
+     * pattern string.
+     *
+     * @param pattern the message pattern
+     * @param argument the message argument
+     * @return the formatted string
+     */
+    public String message(String pattern, Object argument) {
+        return message(pattern, new Object[] { argument });
+    }
+
+    /**
+     * Return a formatted string using the given message pattern and arguments.
+     * See {@link java.text.MessageFormat} for information on the message
+     * pattern string.
+     *
+     * @param pattern the message pattern
+     * @param arguments the message arguments
+     * @return the formatted string
+     */
+    public String message(String pattern, Object[] arguments) {
+        MessageFormat format = new MessageFormat(pattern, getLocale());
+        return format.format(arguments, new StringBuffer(), null).toString();
+    }
+
+    /**
+     * Return a formatted string using the given message pattern and arguments.
+     * See {@link java.text.MessageFormat} for information on the message
+     * pattern string.
+     *
+     * @param pattern the message pattern
+     * @param arguments list of message arguments
+     * @return the formatted string
+     */
+    public String message(String pattern, List arguments) {
+        return message(pattern, arguments.toArray());
+    }
+
+    /**
      * Return a percentage formatted number string using number.
      * <p/>
      * If the number is null this method will return the