01: package jtaDiscRack;
02:
03: import java.util.*;
04: import java.net.URL;
05:
06: /**
07: * Implements the static methods that are used to implement
08: * multilanguage support.
09: *
10: * @author Sasa Bojanic
11: * @version 1.0
12: */
13: public class ResourceManager {
14: private static final String resourcePath = "jtaDiscRack.resources.jtaDiscRack";
15:
16: public static ResourceBundle defaultResource;
17:
18: static {
19: try {
20: defaultResource = ResourceBundle.getBundle(resourcePath);
21: } catch (MissingResourceException mre) {
22: System.err.println(resourcePath + ".properties not found");
23: System.exit(1);
24: }
25: }
26:
27: /**
28: * Gets a resource string from the resource bundle.<p> Resource bundle
29: * represents the <i>property file</i>. For example, if property file
30: * contains something like this:<BR><CENTER>menubar=file edit help</CENTER>
31: * method call getResourceString("menubar") will give the string
32: * <i>file edit help</i> as a result. <BR> This method reads information
33: * from property file. If can't find desired resource, returns <b>null</b>.
34: * @param nm name of the resource to fetch.
35: * @return String value of named resource.
36: */
37: public static String getResourceString(String nm) {
38: String str;
39: try {
40: str = defaultResource.getString(nm);
41: } catch (MissingResourceException mre1) {
42: str = null;
43: }
44: return str;
45: }
46:
47: /**
48: * Gets the url from a resource string.
49: * @param key the string key to the url in the resource bundle.
50: * @return the resource location.
51: * @see java.lang.Class#getResource
52: */
53: public static URL getResource(String key) {
54: String name = getResourceString(key);
55: if (name != null) {
56: URL url = ResourceManager.class.getClassLoader()
57: .getResource(name);
58: return url;
59: }
60: return null;
61: }
62: }
|