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