incubator-connectors-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject svn commit: r1329957 - in /incubator/lcf/trunk: CHANGES.txt framework/core/src/main/java/org/apache/manifoldcf/core/i18n/Messages.java framework/ui-core/src/main/java/org/apache/manifoldcf/ui/i18n/Messages.java
Date Tue, 24 Apr 2012 19:27:21 GMT
Author: kwright
Date: Tue Apr 24 19:27:21 2012
New Revision: 1329957

URL: http://svn.apache.org/viewvc?rev=1329957&view=rev
Log:
Fix for CONNECTORS-468.

Modified:
    incubator/lcf/trunk/CHANGES.txt
    incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/i18n/Messages.java
    incubator/lcf/trunk/framework/ui-core/src/main/java/org/apache/manifoldcf/ui/i18n/Messages.java

Modified: incubator/lcf/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/CHANGES.txt?rev=1329957&r1=1329956&r2=1329957&view=diff
==============================================================================
--- incubator/lcf/trunk/CHANGES.txt (original)
+++ incubator/lcf/trunk/CHANGES.txt Tue Apr 24 19:27:21 2012
@@ -3,6 +3,10 @@ $Id$
 
 ======================= 0.6-dev =====================
 
+CONNECTORS-468: Wrap ResourceBundle class so that missing keys
+in a resource bundle are dealt with in a friendlier way.
+(Karl Wright)
+
 CONNECTORS-466: Fix expression error in CMIS connector javascript.
 (Karl Wright)
 

Modified: incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/i18n/Messages.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/i18n/Messages.java?rev=1329957&r1=1329956&r2=1329957&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/i18n/Messages.java
(original)
+++ incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/i18n/Messages.java
Tue Apr 24 19:27:21 2012
@@ -174,6 +174,14 @@ public class Messages
     if (resources == null)
       return null;
     
+    return getMessage(resources,bundleName,locale,messageKey);
+  }
+  
+  /** Obtain a message given a resource bundle and message key.
+  *@return null if the message could not be found.
+  */
+  public static String getMessage(ResourceBundle resources, String bundleName, Locale locale,
String messageKey)
+  {
     String message;
     try
     {
@@ -187,6 +195,14 @@ public class Messages
     }
   }
   
+  /** Obtain a string given a resource bundle and message key.
+  */
+  public static String getString(ResourceBundle resourceBundle, String bundleName,
+    Locale locale, String messageKey)
+  {
+    return getString(resourceBundle, bundleName, locale, messageKey, null);
+  }
+  
   /** Obtain a string given a class, bundle, locale, message key, and arguments.
   */
   public static String getString(Class clazz, String bundleName, Locale locale,
@@ -211,6 +227,31 @@ public class Messages
     return formatMessage;
   }
 
+  /** Obtain a string given a resource bundle, message key, and arguments.
+  */
+  public static String getString(ResourceBundle resourceBundle, String bundleName,
+    Locale locale, String messageKey, Object[] args)
+  {
+    String message = getMessage(resourceBundle,bundleName,locale,messageKey);
+    if (message == null)
+      return messageKey;
+
+    // Format the message
+    String formatMessage;
+    if (args != null)
+    {
+      MessageFormat fm = new MessageFormat(message);
+      fm.setLocale(locale);
+      formatMessage = fm.format(args);
+    }
+    else
+    {
+      formatMessage = message;
+    }
+    return formatMessage;
+
+  }
+  
   protected static void complainMissingBundle(String errorMessage, Throwable exception, String
bundleName, Locale locale)
   {
     String localeName = locale.toString();

Modified: incubator/lcf/trunk/framework/ui-core/src/main/java/org/apache/manifoldcf/ui/i18n/Messages.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/ui-core/src/main/java/org/apache/manifoldcf/ui/i18n/Messages.java?rev=1329957&r1=1329956&r2=1329957&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/ui-core/src/main/java/org/apache/manifoldcf/ui/i18n/Messages.java
(original)
+++ incubator/lcf/trunk/framework/ui-core/src/main/java/org/apache/manifoldcf/ui/i18n/Messages.java
Tue Apr 24 19:27:21 2012
@@ -139,7 +139,7 @@ public class Messages extends org.apache
       
       // Add in the resource bundle
       ResourceBundle rb = getResourceBundle(clazz,bundleName,locale);
-      context.put("ResourceBundle",rb);
+      context.put("ResourceBundle",new ResourceBundleWrapper(rb,bundleName,locale));
       
       if (contextObjects != null)
       {



Mime
View raw message