38 * containing localization data for a class.
39 */
40 class I18NResourceBundle extends ResourceBundle
41 {
42 static I18NResourceBundle getDefaultBundle() {
43 if (defaultBundle == null)
44 defaultBundle = getBundleForClass(I18NResourceBundle.class);
45
46 return defaultBundle;
47 }
48
49 private static I18NResourceBundle defaultBundle;
50
51 /**
52 * Get a package-specific resource bundle for a class containing localization data.
53 * The bundle is named i18n.properties in the same
54 * package as the given class.
55 * @param c the class for which to obtain the resource bundle
56 * @return the appropriate resource bundle for the class
57 */
58 public static I18NResourceBundle getBundleForClass(Class c) {
59 String cn = c.getName();
60 int dot = cn.lastIndexOf('.');
61 String rn = (dot == -1 ? "i18n" : cn.substring(0, dot) + ".i18n");
62 boolean logging = (logClassPrefix == null ? false : cn.startsWith(logClassPrefix));
63 return new I18NResourceBundle(rn, logging, c.getClassLoader());
64 }
65
66 /**
67 * Get an entry from the resource bundle.
68 * If the resource cannot be found, a message is printed to the console
69 * and the result will be a string containing the method parameters.
70 * @param key the name of the entry to be returned
71 * @param arg an argument to be formatted into the result using
72 * {@link java.text.MessageFormat#format}
73 * @return the formatted string
74 */
75 public String getString(String key, Object arg) {
76 return getString(key, new Object[] {arg});
77 }
78
|
38 * containing localization data for a class.
39 */
40 class I18NResourceBundle extends ResourceBundle
41 {
42 static I18NResourceBundle getDefaultBundle() {
43 if (defaultBundle == null)
44 defaultBundle = getBundleForClass(I18NResourceBundle.class);
45
46 return defaultBundle;
47 }
48
49 private static I18NResourceBundle defaultBundle;
50
51 /**
52 * Get a package-specific resource bundle for a class containing localization data.
53 * The bundle is named i18n.properties in the same
54 * package as the given class.
55 * @param c the class for which to obtain the resource bundle
56 * @return the appropriate resource bundle for the class
57 */
58 public static I18NResourceBundle getBundleForClass(Class<?> c) {
59 String cn = c.getName();
60 int dot = cn.lastIndexOf('.');
61 String rn = (dot == -1 ? "i18n" : cn.substring(0, dot) + ".i18n");
62 boolean logging = (logClassPrefix == null ? false : cn.startsWith(logClassPrefix));
63 return new I18NResourceBundle(rn, logging, c.getClassLoader());
64 }
65
66 /**
67 * Get an entry from the resource bundle.
68 * If the resource cannot be found, a message is printed to the console
69 * and the result will be a string containing the method parameters.
70 * @param key the name of the entry to be returned
71 * @param arg an argument to be formatted into the result using
72 * {@link java.text.MessageFormat#format}
73 * @return the formatted string
74 */
75 public String getString(String key, Object arg) {
76 return getString(key, new Object[] {arg});
77 }
78
|