1 package fr.ove.utils;
2
3 import java.net.*;
4 import java.util.*;
5
6 /***
7 * A resources manager.<BR>
8 * All the resources are specified in a properties file, each property defined in a key = val1:val2:....:valn.<BR>
9 * The key represents the name of the property. The different vali the parameters identifying the property.<BR>
10 * Each parameter is separated by the ':' character.
11 *
12 * @author © 1999 DIRAT Laurent
13 * @version 2.0 17/12/1999
14 */
15 public class ResourcesManager implements java.io.Serializable {
16 private ResourceBundle resources;
17
18 /***
19 * Constructor
20 * @param resourcesName the name of the resources file. <BR> he name is specified without the ".properties"
21 * extension. If the property file is located in a package, the fully qualified name (e.g. my.package.filename)
22 * must be used.
23 */
24 public ResourcesManager(String resourcesName) {
25 try {
26
27 resources = ResourceBundle.getBundle(resourcesName);
28 }
29 catch (MissingResourceException mre) {
30 System.err.println(resourcesName+".properties not found");
31 System.exit(1);
32 }
33 }
34
35 /***
36 * Get the raw string for the given property
37 */
38 public String getResourceString(String prop) {
39 String str;
40 try {
41 str = resources.getString(prop);
42 }
43 catch (MissingResourceException mre) {
44 str = null;
45 }
46
47 return str;
48 }
49
50 /***
51 * Get the resource strings for the given property
52 */
53 public String [] getResourceStrings(String prop) {
54 return tokenize(getResourceString (prop));
55 }
56
57 /***
58 * Take the given string and chop it up into a series
59 * of strings on whitespace boundries. This is useful
60 * for trying to get an array of strings out of the
61 * resource file.
62 */
63 private String[] tokenize(String input) {
64 if (input != null) {
65 Vector v = new Vector();
66 StringTokenizer t = new StringTokenizer (input, ":");
67 String cmd[];
68
69 while (t.hasMoreTokens())
70 v.addElement(t.nextToken());
71
72 cmd = new String[v.size()];
73 for (int i = 0; i < cmd.length; i++)
74 cmd[i] = (String) v.elementAt(i);
75
76 return cmd;
77 }
78 else
79 return new String [0];
80 }
81 }