01: /*
02: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
03: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
04: */
05: package com.sun.portal.search.rdmgr;
06:
07: import java.util.*;
08: import java.text.*;
09: import java.io.*;
10:
11: class RDMgrUtil {
12:
13: public static String RESOURCE_BASE = "rdmgr";
14: public static ResourceBundle rb = PropertyResourceBundle.getBundle(
15: RESOURCE_BASE, Locale.getDefault());
16:
17: public static void setLocale(java.util.Locale locale) {
18: // load resource bundle based on locale
19: rb = PropertyResourceBundle.getBundle(RESOURCE_BASE, locale);
20: }
21:
22: /**
23: * given a string representation of the locale (i.e. en_US)
24: * create a Locale obj.
25: */
26: public static Locale getLocale(String stringformat) {
27:
28: if (stringformat == null)
29: return Locale.getDefault();
30: StringTokenizer tk = new StringTokenizer(stringformat, "_");
31: String lang = "";
32: String country = "";
33: String variant = "";
34: if (tk.hasMoreTokens())
35: lang = tk.nextToken();
36: if (tk.hasMoreTokens())
37: country = tk.nextToken();
38: if (tk.hasMoreTokens())
39: variant = tk.nextToken();
40: return new java.util.Locale(lang, country, variant);
41:
42: }
43:
44: public static String getLocalizedString(String key) {
45: return rb.getString(key);
46: }
47:
48: public static String getLocalizedString(String key, Object[] objs) {
49:
50: if (objs != null && objs.length > 0) {
51: MessageFormat mf = new MessageFormat("");
52: mf.setLocale(rb.getLocale());
53: mf.applyPattern(rb.getString(key));
54: return mf.format(objs);
55: } else {
56: return rb.getString(key);
57: }
58: }
59:
60: }
|