KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > discRack > ResourceManager


1 package discRack;
2
3 import java.awt.*;
4 import java.util.*;
5 import java.text.*;
6 import java.net.URL JavaDoc;
7 import javax.accessibility.*;
8
9 /**
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 JavaDoc resourcePath=
18          "discRack.resources.DiscRack";
19
20    public static ResourceBundle defaultResource;
21
22
23    static {
24       try {
25          defaultResource = ResourceBundle.
26             getBundle(resourcePath);
27       }
28       catch (MissingResourceException mre) {
29          System.err.println(resourcePath+".properties not found");
30          System.exit(1);
31       }
32    }
33
34    /**
35     * Gets a resource string from the resource bundle.<p> Resource bundle
36     * represents the <i>property file</i>. For example, if property file
37     * contains something like this:<BR><CENTER>menubar=file edit help</CENTER>
38     * method call getResourceString("menubar") will give the string
39     * <i>file edit help</i> as a result. <BR> This method reads information
40     * from property file. If can't find desired resource, returns <b>null</b>.
41     * @param nm name of the resource to fetch.
42     * @return String value of named resource.
43     */

44    public static String JavaDoc getResourceString (String JavaDoc nm) {
45       String JavaDoc str;
46       try {
47          str=defaultResource.getString(nm);
48       } catch (MissingResourceException mre1) {
49          str = null;
50       }
51       return str;
52    }
53
54    /**
55     * Gets the url from a resource string.
56     * @param key the string key to the url in the resource bundle.
57     * @return the resource location.
58     * @see java.lang.Class#getResource
59     */

60    public static URL JavaDoc getResource (String JavaDoc key) {
61       String JavaDoc name = getResourceString(key);
62       if (name != null) {
63          URL JavaDoc url = ResourceManager.class.getClassLoader().getResource(name);
64          return url;
65       }
66       return null;
67    }
68 }
Popular Tags