Author: jboynes
Date: Fri Oct  8 01:20:19 2010
New Revision: 1005692

URL: http://svn.apache.org/viewvc?rev=1005692&view=rev
Log:
refactor Resources to use varargs

Added:
    
tomcat/taglibs/standard/trunk/impl/src/test/java/org/apache/taglibs/standard/resources/
    
tomcat/taglibs/standard/trunk/impl/src/test/java/org/apache/taglibs/standard/resources/TestResources.java
Modified:
    tomcat/taglibs/standard/trunk/impl/pom.xml
    
tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/resources/Resources.java
    
tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/resources/Resources.properties

Modified: tomcat/taglibs/standard/trunk/impl/pom.xml
URL: 
http://svn.apache.org/viewvc/tomcat/taglibs/standard/trunk/impl/pom.xml?rev=1005692&r1=1005691&r2=1005692&view=diff
==============================================================================
--- tomcat/taglibs/standard/trunk/impl/pom.xml (original)
+++ tomcat/taglibs/standard/trunk/impl/pom.xml Fri Oct  8 01:20:19 2010
@@ -156,6 +156,7 @@
           <includes>
             
<include>org/apache/taglibs/standard/lang/jstl/test/StaticFunctionTests.java</include>
             <include>org/apache/taglibs/standard/TestVersion.java</include>
+            
<include>org/apache/taglibs/standard/resources/TestResources.java</include>
             
<include>org/apache/taglibs/standard/tag/common/core/TestSetSupport.java</include>
             
<include>org/apache/taglibs/standard/tag/common/xml/TestTransformSupport.java</include>
           </includes>

Modified: 
tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/resources/Resources.java
URL: 
http://svn.apache.org/viewvc/tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/resources/Resources.java?rev=1005692&r1=1005691&r2=1005692&view=diff
==============================================================================
--- 
tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/resources/Resources.java
 (original)
+++ 
tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/resources/Resources.java
 Fri Oct  8 01:20:19 2010
@@ -13,7 +13,7 @@
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
- */ 
+ */
 
 package org.apache.taglibs.standard.resources;
 
@@ -24,104 +24,54 @@ import java.util.ResourceBundle;
 /**
  * <p>Provides locale-neutral access to string resources.  Only the
  * documentation and code are in English. :-)
- *
+ * <p/>
  * <p>The major goal, aside from globalization, is convenience.
  * Access to resources with no parameters is made in the form:</p>
  * <pre>
  *     Resources.getMessage(MESSAGE_NAME);
  * </pre>
- *
+ * <p/>
  * <p>Access to resources with one parameter works like</p>
  * <pre>
  *     Resources.getMessage(MESSAGE_NAME, arg1);
  * </pre>
- *
+ * <p/>
  * <p>... and so on.</p>
  *
  * @author Shawn Bayern
  */
 public class Resources {
 
-    //*********************************************************************
-    // Static data
-
-    /** The location of our resources. */
-    private static final String RESOURCE_LOCATION
-       = "org.apache.taglibs.standard.resources.Resources";
-
-    /** Our class-wide ResourceBundle. */
-    private static ResourceBundle rb =
-       ResourceBundle.getBundle(RESOURCE_LOCATION);
+    /**
+     * Our class-wide ResourceBundle.
+     */
+    private static final ResourceBundle rb = 
ResourceBundle.getBundle(Resources.class.getName());
 
 
     //*********************************************************************
     // Public static methods
 
-    /** Retrieves a message with no arguments. */
-    public static String getMessage(String name)
-           throws MissingResourceException {
-       return rb.getString(name);
+    /**
+     * Retrieves a message with no arguments.
+     *
+     * @param name the name of the message
+     * @return the localized message text
+     * @throws MissingResourceException if the message does not exist
+     */
+    public static String getMessage(String name) throws 
MissingResourceException {
+        return rb.getString(name);
+    }
+
+    /**
+     * Retrieves a message with arbitrarily many arguments.
+     *
+     * @param name the name of the message
+     * @param a    arguments to be substituted into the message text
+     * @return the localized message text
+     * @throws MissingResourceException if the message does not exist
+     */
+    public static String getMessage(String name, Object... a) throws 
MissingResourceException {
+        String res = rb.getString(name);
+        return MessageFormat.format(res, a);
     }
-
-    /** Retrieves a message with arbitrarily many arguments. */
-    public static String getMessage(String name, Object[] a)
-           throws MissingResourceException {
-       String res = rb.getString(name);
-       return MessageFormat.format(res, a);
-    }
-
-    /** Retrieves a message with one argument. */
-    public static String getMessage(String name, Object a1)
-           throws MissingResourceException {
-       return getMessage(name, new Object[] { a1 });
-    }
-
-    /** Retrieves a message with two arguments. */
-    public static String getMessage(String name, Object a1, Object a2)
-           throws MissingResourceException {
-       return getMessage(name, new Object[] { a1, a2 });
-    }
-
-    /** Retrieves a message with three arguments. */
-    public static String getMessage(String name,
-                                   Object a1,
-                                   Object a2,
-                                   Object a3)
-           throws MissingResourceException {
-       return getMessage(name, new Object[] { a1, a2, a3 });
-    }
-
-    /** Retrieves a message with four arguments. */
-    public static String getMessage(String name,
-                                   Object a1,
-                                   Object a2,
-                                   Object a3,
-                                   Object a4)
-           throws MissingResourceException {
-       return getMessage(name, new Object[] { a1, a2, a3, a4 });
-    }
-
-    /** Retrieves a message with five arguments. */
-    public static String getMessage(String name,
-                                   Object a1,
-                                   Object a2,
-                                   Object a3,
-                                   Object a4,
-                                   Object a5)
-           throws MissingResourceException {
-       return getMessage(name, new Object[] { a1, a2, a3, a4, a5 });
-    }
-
-    /** Retrieves a message with six arguments. */
-    public static String getMessage(String name,
-                                   Object a1,
-                                   Object a2,
-                                   Object a3,
-                                   Object a4,
-                                   Object a5,
-                                   Object a6)
-           throws MissingResourceException {
-       return getMessage(name, new Object[] { a1, a2, a3, a4, a5, a6 });
-    }
-
 }

Modified: 
tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/resources/Resources.properties
URL: 
http://svn.apache.org/viewvc/tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/resources/Resources.properties?rev=1005692&r1=1005691&r2=1005692&view=diff
==============================================================================
--- 
tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/resources/Resources.properties
 (original)
+++ 
tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/resources/Resources.properties
 Fri Oct  8 01:20:19 2010
@@ -10,6 +10,13 @@
 
 
 #########################################################################
+# Test messages - do not localize
+#########################################################################
+TEST_NO_ARGUMENTS=test no arguments
+TEST_ONE_ARGUMENT=test argument {0}
+TEST_MULTIPLE_ARGUMENT=test argument {0} {1}
+
+#########################################################################
 # Generic tag error messages
 #########################################################################
 

Added: 
tomcat/taglibs/standard/trunk/impl/src/test/java/org/apache/taglibs/standard/resources/TestResources.java
URL: 
http://svn.apache.org/viewvc/tomcat/taglibs/standard/trunk/impl/src/test/java/org/apache/taglibs/standard/resources/TestResources.java?rev=1005692&view=auto
==============================================================================
--- 
tomcat/taglibs/standard/trunk/impl/src/test/java/org/apache/taglibs/standard/resources/TestResources.java
 (added)
+++ 
tomcat/taglibs/standard/trunk/impl/src/test/java/org/apache/taglibs/standard/resources/TestResources.java
 Fri Oct  8 01:20:19 2010
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.taglibs.standard.resources;
+
+import org.junit.Test;
+
+import static junit.framework.Assert.assertEquals;
+
+public class TestResources {
+
+    @Test
+    public void testMessageNoArguments() {
+        assertEquals("test no arguments", 
Resources.getMessage("TEST_NO_ARGUMENTS"));
+    }
+
+    @Test
+    public void testMessageOneArgument() {
+        assertEquals("test argument one", 
Resources.getMessage("TEST_ONE_ARGUMENT", "one"));
+    }
+
+    @Test
+    public void testMessageMultipleArguments() {
+        assertEquals("test argument one 2", 
Resources.getMessage("TEST_MULTIPLE_ARGUMENT", "one", 2));
+    }
+
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to