01: package com.sun.portal.netlet.client.common;
02:
03: import java.util.PropertyResourceBundle;
04: import java.util.StringTokenizer;
05: import java.util.Properties;
06: import java.io.IOException;
07: import java.io.InputStream;
08:
09: public class ResourceProperties {
10:
11: private static PropertyResourceBundle resources = null;
12: private static Properties props = null;
13:
14: public static void loadResources() {
15: InputStream is = ClientUtil.netletConfig("loadResources");
16: if (is == null) {
17: System.err.println("Unable to load resources");
18: return;
19: }
20: try {
21: resources = new PropertyResourceBundle(is);
22: is.close();
23: } catch (IOException e) {
24: System.out.println("IOException " + e);
25: }
26: }
27:
28: public static void loadResources(String resourceStr) {
29: props = new Properties();
30: StringTokenizer entries = new StringTokenizer(resourceStr, "|");
31: while (entries.hasMoreTokens()) {
32: String entry = entries.nextToken();
33: int index;
34: String key = entry.substring(0,
35: (index = entry.indexOf("=")));
36: String value = entry.substring(index + 1);
37: props.setProperty(key, value);
38: }
39: }
40:
41: public static String getString(String key) {
42: String value = "";
43: if (resources != null) {
44: value = resources.getString(key);
45: } else if (props != null) {
46: value = props.getProperty(key);
47: }
48: return value;
49: }
50: }
|