01: /**
02: * CertAdminLocale.java
03: * @author ss133690
04: * @version 0.1
05: */package com.sun.portal.cli.cert;
06:
07: import java.io.*;
08: import com.sun.portal.log.common.PortalLogger;
09: import java.lang.*;
10: import java.util.*;
11: import java.text.*;
12: import com.iplanet.am.util.Locale;
13:
14: public class CertAdminLocale {
15:
16: public static final String RESOURCENAME = "sraCertAdmin";
17: private static ResourceBundle platformRB;
18: private static java.util.Locale platformLocale;
19: private static String platformLocaleStr = "en_US";
20:
21: public static java.util.Locale getLocale() {
22: return getLocale(platformLocaleStr);
23: }
24:
25: public static java.util.Locale getLocale(String stringformat) {
26: if (stringformat == null)
27: return java.util.Locale.getDefault();
28: StringTokenizer tk = new StringTokenizer(stringformat, "_");
29: String lang = "";
30: String country = "";
31: String variant = "";
32: if (tk.hasMoreTokens())
33: lang = tk.nextToken();
34: if (tk.hasMoreTokens())
35: country = tk.nextToken();
36: if (tk.hasMoreTokens())
37: variant = tk.nextToken();
38: return new java.util.Locale(lang, country, variant);
39: }
40:
41: public static ResourceBundle getInstallResourceBundle(String bundle) {
42: return ResourceBundle.getBundle(bundle, platformLocale);
43: }
44:
45: public static String getPFString(String key, String defaultVal) {
46: String value = getPFString(key);
47: if (value == null) {
48: return defaultVal;
49: } else {
50: return value;
51: }
52:
53: }
54:
55: private static String getPFString(String key) {
56: try {
57: return (platformRB.getString(key));
58: } catch (Exception ex) {
59: return null;
60: }
61: }
62:
63: public static void createDefault() {
64: try {
65: platformLocale = getLocale();
66: platformRB = getInstallResourceBundle(RESOURCENAME);
67: } catch (MissingResourceException mre) {
68: System.out.println(mre);
69: System.exit(1);
70: }
71: }
72:
73: public static void createDefault(String locale) {
74: try {
75: platformLocale = getLocale(locale);
76: platformRB = getInstallResourceBundle(RESOURCENAME);
77: } catch (MissingResourceException mre) {
78: System.out.println(mre);
79: System.exit(1);
80: }
81: }
82:
83: }
|