openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p..@apache.org
Subject svn commit: r981340 - in /openjpa/trunk/openjpa-lib/src: main/java/org/apache/openjpa/lib/util/Localizer.java test/java/org/apache/openjpa/lib/util/TestLocalizer.java
Date Sun, 01 Aug 2010 23:21:43 GMT
Author: pcl
Date: Sun Aug  1 23:21:42 2010
New Revision: 981340

URL: http://svn.apache.org/viewvc?rev=981340&view=rev
Log:
resolve OPENJPA-1756.

Modified:
    openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Localizer.java
    openjpa/trunk/openjpa-lib/src/test/java/org/apache/openjpa/lib/util/TestLocalizer.java

Modified: openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Localizer.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Localizer.java?rev=981340&r1=981339&r2=981340&view=diff
==============================================================================
--- openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Localizer.java (original)
+++ openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Localizer.java Sun
Aug  1 23:21:42 2010
@@ -247,6 +247,7 @@ public class Localizer {
         private final String _key;
         private final Object[] _subs;
         private final String _localizedMessage;
+        private boolean _localizedMessageFound;
 
         private Message(String packageName, ResourceBundle bundle, String key,
             Object[] subs, boolean fatal) {
@@ -258,13 +259,16 @@ public class Localizer {
             _subs = subs;
             if (bundle == null) {
                 _localizedMessage = key;
+                _localizedMessageFound = false;
             } else {
                 String localized = null;
                 try {
                     localized = bundle.getString(key);
+                    _localizedMessageFound = true;
                 } catch (MissingResourceException mre) {
                     if (fatal)
                         throw mre;
+                    _localizedMessageFound = false;
                 }
                 _localizedMessage = (localized == null) ? key : localized;
             }
@@ -274,7 +278,13 @@ public class Localizer {
          * The localized message.
          */
         public String getMessage() {
-            return MessageFormat.format(_localizedMessage, _subs);
+            if (_localizedMessageFound)
+                return MessageFormat.format(_localizedMessage, _subs);
+            else if (_subs == null || _subs.length == 0)
+                return "localized message key: " + _localizedMessage;
+            else
+                return "localized message key: " + _localizedMessage 
+                    + "; substitutions: " + Arrays.asList(_subs).toString();
         }
 
         /**

Modified: openjpa/trunk/openjpa-lib/src/test/java/org/apache/openjpa/lib/util/TestLocalizer.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-lib/src/test/java/org/apache/openjpa/lib/util/TestLocalizer.java?rev=981340&r1=981339&r2=981340&view=diff
==============================================================================
--- openjpa/trunk/openjpa-lib/src/test/java/org/apache/openjpa/lib/util/TestLocalizer.java
(original)
+++ openjpa/trunk/openjpa-lib/src/test/java/org/apache/openjpa/lib/util/TestLocalizer.java
Sun Aug  1 23:21:42 2010
@@ -102,7 +102,8 @@ public class TestLocalizer extends TestC
      */
     public void testMissingBundle() {
         Localizer missing = Localizer.forPackage(String.class);
-        assertEquals("foo.bar", missing.get("foo.bar"));
+        assertEquals("localized message key: foo.bar", missing.get("foo.bar"));
+        assertEquals("localized message key: foo.bar; substitutions: [baz, 1]", missing.get("foo.bar",
"baz", 1));
         try {
             missing.getFatal("foo.bar");
             fail("No exception for fatal get on missing bundle.");
@@ -114,7 +115,8 @@ public class TestLocalizer extends TestC
      * Test that a {@link MissingResourceException} is thrown for missing keys.
      */
     public void testMissingKey() {
-        assertEquals("foo.bar", _locals.get("foo.bar"));
+        assertEquals("localized message key: foo.bar", _locals.get("foo.bar"));
+        assertEquals("localized message key: foo.bar; substitutions: [baz, 1]", _locals.get("foo.bar",
"baz", 1));
         try {
             _locals.getFatal("foo.bar");
             fail("No exception for fatal get on missing key.");



Mime
View raw message