Commit 3377f1ba authored by Derek DeMoro's avatar Derek DeMoro Committed by derek

Update LocaleUtils to retrieve ResourceBundles for an individual plugin.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@3953 b35dd754-fafc-0310-a699-88a17e54d16e
parent 0f32fe9f
...@@ -38,7 +38,7 @@ import java.util.concurrent.ConcurrentHashMap; ...@@ -38,7 +38,7 @@ import java.util.concurrent.ConcurrentHashMap;
public class LocaleUtils { public class LocaleUtils {
private static final Map<Locale, String[][]> timeZoneLists = private static final Map<Locale, String[][]> timeZoneLists =
new ConcurrentHashMap<Locale, String[][]>(); new ConcurrentHashMap<Locale, String[][]>();
// The basename to use for looking up the appropriate resource bundles // The basename to use for looking up the appropriate resource bundles
// TODO - extract this out into a test that grabs the resource name from JiveGlobals // TODO - extract this out into a test that grabs the resource name from JiveGlobals
...@@ -72,8 +72,8 @@ public class LocaleUtils { ...@@ -72,8 +72,8 @@ public class LocaleUtils {
} }
} }
locale = new Locale(language, locale = new Locale(language,
((country != null) ? country : ""), ((country != null) ? country : ""),
((variant != null) ? variant : "")); ((variant != null) ? variant : ""));
} }
return locale; return locale;
} }
...@@ -81,80 +81,80 @@ public class LocaleUtils { ...@@ -81,80 +81,80 @@ public class LocaleUtils {
// The list of supported timezone ids. The list tries to include all of the relevant // The list of supported timezone ids. The list tries to include all of the relevant
// time zones for the world without any extraneous zones. // time zones for the world without any extraneous zones.
private static String[] timeZoneIds = new String[]{"GMT", private static String[] timeZoneIds = new String[]{"GMT",
"Pacific/Apia", "Pacific/Apia",
"HST", "HST",
"AST", "AST",
"America/Los_Angeles", "America/Los_Angeles",
"America/Phoenix", "America/Phoenix",
"America/Mazatlan", "America/Mazatlan",
"America/Denver", "America/Denver",
"America/Belize", "America/Belize",
"America/Chicago", "America/Chicago",
"America/Mexico_City", "America/Mexico_City",
"America/Regina", "America/Regina",
"America/Bogota", "America/Bogota",
"America/New_York", "America/New_York",
"America/Indianapolis", "America/Indianapolis",
"America/Halifax", "America/Halifax",
"America/Caracas", "America/Caracas",
"America/Santiago", "America/Santiago",
"America/St_Johns", "America/St_Johns",
"America/Sao_Paulo", "America/Sao_Paulo",
"America/Buenos_Aires", "America/Buenos_Aires",
"America/Godthab", "America/Godthab",
"Atlantic/South_Georgia", "Atlantic/South_Georgia",
"Atlantic/Azores", "Atlantic/Azores",
"Atlantic/Cape_Verde", "Atlantic/Cape_Verde",
"Africa/Casablanca", "Africa/Casablanca",
"Europe/Dublin", "Europe/Dublin",
"Europe/Berlin", "Europe/Berlin",
"Europe/Belgrade", "Europe/Belgrade",
"Europe/Paris", "Europe/Paris",
"Europe/Warsaw", "Europe/Warsaw",
"ECT", "ECT",
"Europe/Athens", "Europe/Athens",
"Europe/Bucharest", "Europe/Bucharest",
"Africa/Cairo", "Africa/Cairo",
"Africa/Harare", "Africa/Harare",
"Europe/Helsinki", "Europe/Helsinki",
"Asia/Jerusalem", "Asia/Jerusalem",
"Asia/Baghdad", "Asia/Baghdad",
"Asia/Kuwait", "Asia/Kuwait",
"Europe/Moscow", "Europe/Moscow",
"Africa/Nairobi", "Africa/Nairobi",
"Asia/Tehran", "Asia/Tehran",
"Asia/Muscat", "Asia/Muscat",
"Asia/Baku", "Asia/Baku",
"Asia/Kabul", "Asia/Kabul",
"Asia/Yekaterinburg", "Asia/Yekaterinburg",
"Asia/Karachi", "Asia/Karachi",
"Asia/Calcutta", "Asia/Calcutta",
"Asia/Katmandu", "Asia/Katmandu",
"Asia/Almaty", "Asia/Almaty",
"Asia/Dhaka", "Asia/Dhaka",
"Asia/Colombo", "Asia/Colombo",
"Asia/Rangoon", "Asia/Rangoon",
"Asia/Bangkok", "Asia/Bangkok",
"Asia/Krasnoyarsk", "Asia/Krasnoyarsk",
"Asia/Hong_Kong", "Asia/Hong_Kong",
"Asia/Irkutsk", "Asia/Irkutsk",
"Asia/Kuala_Lumpur", "Asia/Kuala_Lumpur",
"Australia/Perth", "Australia/Perth",
"Asia/Taipei", "Asia/Taipei",
"Asia/Tokyo", "Asia/Tokyo",
"Asia/Seoul", "Asia/Seoul",
"Asia/Yakutsk", "Asia/Yakutsk",
"Australia/Adelaide", "Australia/Adelaide",
"Australia/Darwin", "Australia/Darwin",
"Australia/Brisbane", "Australia/Brisbane",
"Australia/Sydney", "Australia/Sydney",
"Pacific/Guam", "Pacific/Guam",
"Australia/Hobart", "Australia/Hobart",
"Asia/Vladivostok", "Asia/Vladivostok",
"Pacific/Noumea", "Pacific/Noumea",
"Pacific/Auckland", "Pacific/Auckland",
"Pacific/Fiji", "Pacific/Fiji",
"Pacific/Tongatapu" "Pacific/Tongatapu"
}; };
// A mapping from the supported timezone ids to friendly english names. // A mapping from the supported timezone ids to friendly english names.
...@@ -322,8 +322,8 @@ public class LocaleUtils { ...@@ -322,8 +322,8 @@ public class LocaleUtils {
} }
else { else {
buf.append( buf.append(
zone.getDisplayName(true, TimeZone.LONG, locale).replace('_', ' ').replace('/', zone.getDisplayName(true, TimeZone.LONG, locale).replace('_', ' ').replace('/',
' ')); ' '));
} }
return buf.toString(); return buf.toString();
...@@ -412,11 +412,11 @@ public class LocaleUtils { ...@@ -412,11 +412,11 @@ public class LocaleUtils {
* Returns an internationalized string loaded from a resource bundle from the passed * Returns an internationalized string loaded from a resource bundle from the passed
* in plugin. * in plugin.
* *
* @param key the key to use for retrieving the string from the * @param key the key to use for retrieving the string from the
* appropriate resource bundle. * appropriate resource bundle.
* @param pluginName the name of the plugin to load the require resource bundle from. * @param pluginName the name of the plugin to load the require resource bundle from.
* @param arguments a list of objects to use which are formatted, then * @param arguments a list of objects to use which are formatted, then
* inserted into the pattern at the appropriate places. * inserted into the pattern at the appropriate places.
* @return the localized string. * @return the localized string.
*/ */
public static String getLocalizedString(String key, String pluginName, List arguments) { public static String getLocalizedString(String key, String pluginName, List arguments) {
...@@ -428,7 +428,7 @@ public class LocaleUtils { ...@@ -428,7 +428,7 @@ public class LocaleUtils {
final XMPPServer xmppServer = XMPPServer.getInstance(); final XMPPServer xmppServer = XMPPServer.getInstance();
PluginManager pluginManager = xmppServer.getPluginManager(); PluginManager pluginManager = xmppServer.getPluginManager();
Plugin plugin = pluginManager.getPlugin(pluginName); Plugin plugin = pluginManager.getPlugin(pluginName);
if (plugin == null){ if (plugin == null) {
throw new NullPointerException("Plugin could not be located."); throw new NullPointerException("Plugin could not be located.");
} }
...@@ -437,17 +437,41 @@ public class LocaleUtils { ...@@ -437,17 +437,41 @@ public class LocaleUtils {
return getLocalizedString(key, locale, arguments, bundle); return getLocalizedString(key, locale, arguments, bundle);
} }
/**
* Retrieve the <code>ResourceBundle</code> that is used with this plugin.
*
* @param pluginName the name of the plugin.
* @return the ResourceBundle used with this plugin.
* @throws Exception thrown if an exception occurs.
*/
public static ResourceBundle getPluginResourceBundle(String pluginName) throws Exception {
final Locale locale = JiveGlobals.getLocale();
String i18nFile = pluginName + "_i18n";
// Retrieve classloader from pluginName.
final XMPPServer xmppServer = XMPPServer.getInstance();
PluginManager pluginManager = xmppServer.getPluginManager();
Plugin plugin = pluginManager.getPlugin(pluginName);
if (plugin == null) {
throw new NullPointerException("Plugin could not be located.");
}
ClassLoader pluginClassLoader = pluginManager.getPluginClassloader(plugin).getClassLoader();
return ResourceBundle.getBundle(i18nFile, locale, pluginClassLoader);
}
/** /**
* Returns an internationalized string loaded from a resource bundle using * Returns an internationalized string loaded from a resource bundle using
* the passed in Locale substituting the passed in arguments. Substitution * the passed in Locale substituting the passed in arguments. Substitution
* is handled using the {@link MessageFormat} class. * is handled using the {@link MessageFormat} class.
* *
* @param key the key to use for retrieving the string from the * @param key the key to use for retrieving the string from the
* appropriate resource bundle. * appropriate resource bundle.
* @param locale the locale to use for retrieving the appropriate * @param locale the locale to use for retrieving the appropriate
* locale-specific string. * locale-specific string.
* @param arguments a list of objects to use which are formatted, then * @param arguments a list of objects to use which are formatted, then
* inserted into the pattern at the appropriate places. * inserted into the pattern at the appropriate places.
* @return the localized string. * @return the localized string.
*/ */
public static String getLocalizedString(String key, Locale locale, List arguments, ResourceBundle bundle) { public static String getLocalizedString(String key, Locale locale, List arguments, ResourceBundle bundle) {
...@@ -514,14 +538,14 @@ public class LocaleUtils { ...@@ -514,14 +538,14 @@ public class LocaleUtils {
} }
catch (IllegalArgumentException e) { catch (IllegalArgumentException e) {
Log.error("Unable to format resource string for key: " Log.error("Unable to format resource string for key: "
+ key + ", argument type not supported"); + key + ", argument type not supported");
value = ""; value = "";
} }
} }
} }
catch (java.util.MissingResourceException mre) { catch (java.util.MissingResourceException mre) {
Log.warn("Missing resource for key: " + key Log.warn("Missing resource for key: " + key
+ " in locale " + locale.toString()); + " in locale " + locale.toString());
value = ""; value = "";
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment