You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2009/04/28 15:14:14 UTC

svn commit: r769384 - in /tomcat/tc6.0.x/trunk: ./ java/org/apache/tomcat/util/res/ test/org/apache/tomcat/ test/org/apache/tomcat/util/ test/org/apache/tomcat/util/res/ webapps/docs/

Author: markt
Date: Tue Apr 28 13:14:14 2009
New Revision: 769384

URL: http://svn.apache.org/viewvc?rev=769384&view=rev
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=46933
Simplify StringManager using Java 5. Includes test case
Based on a patch by Jens Kapitza

Added:
    tomcat/tc6.0.x/trunk/test/org/apache/tomcat/
    tomcat/tc6.0.x/trunk/test/org/apache/tomcat/util/
    tomcat/tc6.0.x/trunk/test/org/apache/tomcat/util/res/
    tomcat/tc6.0.x/trunk/test/org/apache/tomcat/util/res/TestStringManager.java
Modified:
    tomcat/tc6.0.x/trunk/   (props changed)
    tomcat/tc6.0.x/trunk/STATUS.txt
    tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/res/StringManager.java
    tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml

Propchange: tomcat/tc6.0.x/trunk/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Apr 28 13:14:14 2009
@@ -1 +1 @@
-/tomcat/trunk:601180,606992,612607,630314,640888,652744,653247,673796,673820,683982,684001,684081,684234,684269-684270,685177,687503,687645,689402,690781,691392,691805,692748,693378,694992,695053,695311,696780,696782,698012,698227,698236,698613,699427,699634,701355,709294,709811,709816,710063,710066,710125,710205,711126,711600,712461,712467,718360,719119,719124,719602,719626,719628,720046,720069,721040,723404,723738,726052,727303,728032,728768,728947,729057,729567,729569,729571,729681,729809,729815,729934,730250,730590,731651,732859,732863,734734,740675,740684,742677,742697,742714,744160,744238,746321,746384,747834,747863,748344,750258,750291,750921,751286-751287,751295,757774,758596,758616,758664,759074,761601,762868,762929,762936-762937,763166,768335
+/tomcat/trunk:601180,606992,612607,630314,640888,652744,653247,673796,673820,683982,684001,684081,684234,684269-684270,685177,687503,687645,689402,690781,691392,691805,692748,693378,694992,695053,695311,696780,696782,698012,698227,698236,698613,699427,699634,701355,709294,709811,709816,710063,710066,710125,710205,711126,711600,712461,712467,718360,719119,719124,719602,719626,719628,720046,720069,721040,723404,723738,726052,727303,728032,728768,728947,729057,729567,729569,729571,729681,729809,729815,729934,730250,730590,731651,732859,732863,734734,740675,740684,742677,742697,742714,744160,744238,746321,746384,747834,747863,748344,750258,750291,750921,751286-751287,751295,757774,758596,758616,758664,759074,761601,762868,762929,762936-762937,763166,763183,768335

Modified: tomcat/tc6.0.x/trunk/STATUS.txt
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/STATUS.txt?rev=769384&r1=769383&r2=769384&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/STATUS.txt (original)
+++ tomcat/tc6.0.x/trunk/STATUS.txt Tue Apr 28 13:14:14 2009
@@ -104,15 +104,6 @@
   +1: markt, remm
   -1: 
 
-* Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=46933
-  Simplify StringManager using Java 5. Includes test case. Based on a patch by
-  Jens Kapitza
-  http://svn.apache.org/viewvc?rev=763183&view=rev
-  +1: markt, remm, rjung
-  -1: 
-  rjung: J. Kapitza added later another patch to StringManager as
-  https://issues.apache.org/bugzilla/attachment.cgi?id=23550
-
 * Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=46958
   Allow xml manager status to work irrespective of context path
   http://svn.apache.org/viewvc?rev=763193&view=rev

Modified: tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/res/StringManager.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/res/StringManager.java?rev=769384&r1=769383&r2=769384&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/res/StringManager.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/res/StringManager.java Tue Apr 28 13:14:14 2009
@@ -131,107 +131,17 @@
      * @param args
      */
 
-    public String getString(String key, Object[] args) {
-        String iString = null;
+    public String getString(final String key, final Object... args) {
         String value = getString(key);
-
-        // this check for the runtime exception is some pre 1.1.6
-        // VM's don't do an automatic toString() on the passed in
-        // objects and barf out
-
-        try {
-            // ensure the arguments are not null so pre 1.2 VM's don't barf
-            if(args==null){
-                args = new Object[1];
-            }
-            
-            Object[] nonNullArgs = args;
-            for (int i=0; i<args.length; i++) {
-                if (args[i] == null) {
-                    if (nonNullArgs==args){
-                        nonNullArgs=(Object[])args.clone();
-                    }
-                    nonNullArgs[i] = "null";
-                }
-            }
-            if( value==null ) value=key;
-	    MessageFormat mf = new MessageFormat(value);
-            mf.setLocale(locale);
-            iString = mf.format(nonNullArgs, new StringBuffer(), null).toString();
-        } catch (IllegalArgumentException iae) {
-            StringBuffer buf = new StringBuffer();
-            buf.append(value);
-            for (int i = 0; i < args.length; i++) {
-                buf.append(" arg[" + i + "]=" + args[i]);
-            }
-            iString = buf.toString();
+        if (value == null) {
+            value = key;
         }
-        return iString;
-    }
-
-    /**
-     * Get a string from the underlying resource bundle and format it
-     * with the given object argument. This argument can of course be
-     * a String object.
-     *
-     * @param key
-     * @param arg
-     */
-
-    public String getString(String key, Object arg) {
-	Object[] args = new Object[] {arg};
-	return getString(key, args);
-    }
-
-    /**
-     * Get a string from the underlying resource bundle and format it
-     * with the given object arguments. These arguments can of course
-     * be String objects.
-     *
-     * @param key
-     * @param arg1
-     * @param arg2
-     */
-
-    public String getString(String key, Object arg1, Object arg2) {
-	Object[] args = new Object[] {arg1, arg2};
-	return getString(key, args);
-    }
-    
-    /**
-     * Get a string from the underlying resource bundle and format it
-     * with the given object arguments. These arguments can of course
-     * be String objects.
-     *
-     * @param key
-     * @param arg1
-     * @param arg2
-     * @param arg3
-     */
 
-    public String getString(String key, Object arg1, Object arg2,
-			    Object arg3) {
-	Object[] args = new Object[] {arg1, arg2, arg3};
-	return getString(key, args);
+        MessageFormat mf = new MessageFormat(value);
+        mf.setLocale(locale);
+        return mf.format(args, new StringBuffer(), null).toString();
     }
 
-    /**
-     * Get a string from the underlying resource bundle and format it
-     * with the given object arguments. These arguments can of course
-     * be String objects.
-     *
-     * @param key
-     * @param arg1
-     * @param arg2
-     * @param arg3
-     * @param arg4
-     */
-
-    public String getString(String key, Object arg1, Object arg2,
-			    Object arg3, Object arg4) {
-	Object[] args = new Object[] {arg1, arg2, arg3, arg4};
-	return getString(key, args);
-    }
     // --------------------------------------------------------------
     // STATIC SUPPORT METHODS
     // --------------------------------------------------------------

Added: tomcat/tc6.0.x/trunk/test/org/apache/tomcat/util/res/TestStringManager.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/test/org/apache/tomcat/util/res/TestStringManager.java?rev=769384&view=auto
==============================================================================
--- tomcat/tc6.0.x/trunk/test/org/apache/tomcat/util/res/TestStringManager.java (added)
+++ tomcat/tc6.0.x/trunk/test/org/apache/tomcat/util/res/TestStringManager.java Tue Apr 28 13:14:14 2009
@@ -0,0 +1,44 @@
+/*
+ * 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.tomcat.util.res;
+
+import junit.framework.TestCase;
+
+public class TestStringManager extends TestCase {
+
+    private static final StringManager sm =
+        StringManager.getManager("org.apache.naming");
+
+    public void testNullKey() {
+        boolean iaeThrown = false;
+        
+        try {
+            sm.getString(null);
+        } catch (IllegalArgumentException iae) {
+            iaeThrown = true;
+        }
+        assertEquals("IAE not thrown on null key", true, iaeThrown);
+    }
+    
+    public void testBug46933() {
+        // Check null args are OK
+        sm.getString("namingContext.nameNotBound");
+        sm.getString("namingContext.nameNotBound", (Object[]) null);
+        sm.getString("namingContext.nameNotBound", new Object[1]);
+    }
+}

Modified: tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml?rev=769384&r1=769383&r2=769384&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml Tue Apr 28 13:14:14 2009
@@ -57,6 +57,10 @@
         Correct some errors reported when testing the WebDAV servlet with the
         Litmus test suite. (markt)
       </fix>
+      <update>
+        <bug>46933</bug>: Update StringManager to use Java 5 features. Patch
+        provided by Jens Kapitza. (markt)
+      </update>
     </changelog>
   </subsection>
   <subsection name="Coyote">



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