01: package com.quantum.flatfiles;
02:
03: import java.text.MessageFormat;
04: import java.util.MissingResourceException;
05: import java.util.ResourceBundle;
06:
07: /**
08: * Provides resources for the plugin.
09: *
10: * @TODO: there must be a good way to generalize this...
11: *
12: * @author BC Holmes
13: */
14: public class MessageUtil {
15:
16: private static final String BUNDLE_NAME = "com.quantum.flatfiles.QuantumFlatFilesResources"; //$NON-NLS-1$
17: private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle
18: .getBundle(BUNDLE_NAME);
19:
20: private MessageUtil() {
21: }
22:
23: public static String getString(Class resourceClass, String key) {
24: return getString(createKey(resourceClass, key));
25: }
26:
27: private static String createKey(Class resourceClass, String key) {
28: return resourceClass.getName()
29: + (key.startsWith(".") ? key : "." + key);
30: }
31:
32: private static String getString(String key) {
33: try {
34: return RESOURCE_BUNDLE.getString(key);
35: } catch (MissingResourceException e) {
36: return '!' + key + '!';
37: }
38: }
39:
40: public static String getString(Class resourceClass, String key,
41: Object[] arguments) {
42: return getString(createKey(resourceClass, key), arguments);
43: }
44:
45: private static String getString(String key, Object[] arguments) {
46: String string = getString(key);
47: return MessageFormat.format(string, arguments);
48: }
49: }
|