www.pudn.com > talk-plugins.rar > Bundles.java
package talkServer.business;
import java.text.MessageFormat;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
public class Bundles {
// bundles in the application
private static ResourceBundle maps_resourceBundle = ResourceBundle.getBundle("maps");
public static ResourceBundle getMaps_resourceBundle() {
return maps_resourceBundle;
}
public static void setMaps_resourceBundle(ResourceBundle maps_resourceBundle) {
Bundles.maps_resourceBundle = maps_resourceBundle;
}
private Bundles() {
}
/**
* Gets a string from the resource bundle.
* We don't want to crash because of a missing String.
* Returns the key if not found.
*/
public static String getResourceString(String key,ResourceBundle resourceBundle) {
try {
return resourceBundle.getString(key);
} catch (MissingResourceException e) {
return key;
} catch (NullPointerException e) {
return "!" + key + "!";
}
}
// public static String[] getResourceStringArray(String key, ResourceBundle resourceBundle) {
// try {
// return resourceBundle.getStringArray(key);
// } catch (MissingResourceException e) {
// return null;
// } catch (NullPointerException e) {
// return null;
// }
// }
/**
* Gets a string from the resource bundle and binds it
* with the given arguments. If the key is not found,
* return the key.
*/
public static String getResourceString(String key, Object[] args, ResourceBundle resourceBundle) {
try {
return MessageFormat.format(getResourceString(key,resourceBundle), args);
} catch (MissingResourceException e) {
return key;
} catch (NullPointerException e) {
return "!" + key + "!";
}
}
}