20 /* |
20 /* |
21 * $Id: XResourceBundle.java,v 1.2.4.1 2005/09/15 08:16:04 suresh_emailid Exp $ |
21 * $Id: XResourceBundle.java,v 1.2.4.1 2005/09/15 08:16:04 suresh_emailid Exp $ |
22 */ |
22 */ |
23 package com.sun.org.apache.xml.internal.utils.res; |
23 package com.sun.org.apache.xml.internal.utils.res; |
24 |
24 |
|
25 import java.security.AccessController; |
|
26 import java.security.PrivilegedAction; |
25 import java.util.ListResourceBundle; |
27 import java.util.ListResourceBundle; |
26 import java.util.Locale; |
28 import java.util.Locale; |
27 import java.util.MissingResourceException; |
29 import java.util.MissingResourceException; |
28 import java.util.ResourceBundle; |
30 import java.util.ResourceBundle; |
29 |
31 |
30 /** |
32 /** |
31 * The default (english) resource bundle. |
33 * The default (english) resource bundle. |
|
34 * |
32 * @xsl.usage internal |
35 * @xsl.usage internal |
33 */ |
36 */ |
34 public class XResourceBundle extends ListResourceBundle |
37 public class XResourceBundle extends ListResourceBundle { |
35 { |
|
36 |
38 |
37 /** Error resource constants */ |
39 /** |
38 public static final String ERROR_RESOURCES = |
40 * Error resource constants |
39 "com.sun.org.apache.xalan.internal.res.XSLTErrorResources", XSLT_RESOURCE = |
41 */ |
40 "com.sun.org.apache.xml.internal.utils.res.XResourceBundle", LANG_BUNDLE_NAME = |
42 public static final String ERROR_RESOURCES = |
41 "com.sun.org.apache.xml.internal.utils.res.XResources", MULT_ORDER = |
43 "com.sun.org.apache.xalan.internal.res.XSLTErrorResources", XSLT_RESOURCE = |
42 "multiplierOrder", MULT_PRECEDES = "precedes", MULT_FOLLOWS = |
44 "com.sun.org.apache.xml.internal.utils.res.XResourceBundle", LANG_BUNDLE_NAME = |
43 "follows", LANG_ORIENTATION = "orientation", LANG_RIGHTTOLEFT = |
45 "com.sun.org.apache.xml.internal.utils.res.XResources", MULT_ORDER = |
44 "rightToLeft", LANG_LEFTTORIGHT = "leftToRight", LANG_NUMBERING = |
46 "multiplierOrder", MULT_PRECEDES = "precedes", MULT_FOLLOWS = |
45 "numbering", LANG_ADDITIVE = "additive", LANG_MULT_ADD = |
47 "follows", LANG_ORIENTATION = "orientation", LANG_RIGHTTOLEFT = |
46 "multiplicative-additive", LANG_MULTIPLIER = |
48 "rightToLeft", LANG_LEFTTORIGHT = "leftToRight", LANG_NUMBERING = |
47 "multiplier", LANG_MULTIPLIER_CHAR = |
49 "numbering", LANG_ADDITIVE = "additive", LANG_MULT_ADD = |
48 "multiplierChar", LANG_NUMBERGROUPS = "numberGroups", LANG_NUM_TABLES = |
50 "multiplicative-additive", LANG_MULTIPLIER = |
49 "tables", LANG_ALPHABET = "alphabet", LANG_TRAD_ALPHABET = "tradAlphabet"; |
51 "multiplier", LANG_MULTIPLIER_CHAR = |
|
52 "multiplierChar", LANG_NUMBERGROUPS = "numberGroups", LANG_NUM_TABLES = |
|
53 "tables", LANG_ALPHABET = "alphabet", LANG_TRAD_ALPHABET = "tradAlphabet"; |
50 |
54 |
51 /** |
|
52 * Return a named ResourceBundle for a particular locale. This method mimics the behavior |
|
53 * of ResourceBundle.getBundle(). |
|
54 * |
|
55 * @param className Name of local-specific subclass. |
|
56 * @param locale the locale to prefer when searching for the bundle |
|
57 */ |
|
58 public static final XResourceBundle loadResourceBundle( |
|
59 String className, Locale locale) throws MissingResourceException |
|
60 { |
|
61 |
55 |
62 String suffix = getResourceSuffix(locale); |
56 /** |
63 |
57 * Get the association list. |
64 //System.out.println("resource " + className + suffix); |
58 * |
65 try |
59 * @return The association list. |
66 { |
60 */ |
67 |
61 public Object[][] getContents() { |
68 // first try with the given locale |
62 return new Object[][]{ |
69 String resourceName = className + suffix; |
63 {"ui_language", "en"}, {"help_language", "en"}, {"language", "en"}, |
70 return (XResourceBundle) ResourceBundle.getBundle(resourceName, locale); |
64 {"alphabet", new CharArrayWrapper(new char[]{'A', 'B', 'C', 'D', 'E', 'F', 'G', |
|
65 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', |
|
66 'V', 'W', 'X', 'Y', 'Z'})}, |
|
67 {"tradAlphabet", new CharArrayWrapper(new char[]{'A', 'B', 'C', 'D', 'E', 'F', |
|
68 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', |
|
69 'U', 'V', 'W', 'X', 'Y', 'Z'})}, |
|
70 //language orientation |
|
71 {"orientation", "LeftToRight"}, |
|
72 //language numbering |
|
73 {"numbering", "additive"},}; |
71 } |
74 } |
72 catch (MissingResourceException e) |
|
73 { |
|
74 try // try to fall back to en_US if we can't load |
|
75 { |
|
76 |
|
77 // Since we can't find the localized property file, |
|
78 // fall back to en_US. |
|
79 return (XResourceBundle) ResourceBundle.getBundle( |
|
80 XSLT_RESOURCE, new Locale("en", "US")); |
|
81 } |
|
82 catch (MissingResourceException e2) |
|
83 { |
|
84 |
|
85 // Now we are really in trouble. |
|
86 // very bad, definitely very bad...not going to get very far |
|
87 throw new MissingResourceException( |
|
88 "Could not load any resource bundles.", className, ""); |
|
89 } |
|
90 } |
|
91 } |
|
92 |
|
93 /** |
|
94 * Return the resource file suffic for the indicated locale |
|
95 * For most locales, this will be based the language code. However |
|
96 * for Chinese, we do distinguish between Taiwan and PRC |
|
97 * |
|
98 * @param locale the locale |
|
99 * @return an String suffix which canbe appended to a resource name |
|
100 */ |
|
101 private static final String getResourceSuffix(Locale locale) |
|
102 { |
|
103 |
|
104 String lang = locale.getLanguage(); |
|
105 String country = locale.getCountry(); |
|
106 String variant = locale.getVariant(); |
|
107 String suffix = "_" + locale.getLanguage(); |
|
108 |
|
109 if (lang.equals("zh")) |
|
110 suffix += "_" + country; |
|
111 |
|
112 if (country.equals("JP")) |
|
113 suffix += "_" + country + "_" + variant; |
|
114 |
|
115 return suffix; |
|
116 } |
|
117 |
|
118 /** |
|
119 * Get the association list. |
|
120 * |
|
121 * @return The association list. |
|
122 */ |
|
123 public Object[][] getContents() |
|
124 { |
|
125 return new Object[][] |
|
126 { |
|
127 { "ui_language", "en" }, { "help_language", "en" }, { "language", "en" }, |
|
128 { "alphabet", new CharArrayWrapper(new char[]{ 'A', 'B', 'C', 'D', 'E', 'F', 'G', |
|
129 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', |
|
130 'V', 'W', 'X', 'Y', 'Z' })}, |
|
131 { "tradAlphabet", new CharArrayWrapper(new char[]{ 'A', 'B', 'C', 'D', 'E', 'F', |
|
132 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', |
|
133 'U', 'V', 'W', 'X', 'Y', 'Z' }) }, |
|
134 |
|
135 //language orientation |
|
136 { "orientation", "LeftToRight" }, |
|
137 |
|
138 //language numbering |
|
139 { "numbering", "additive" }, |
|
140 }; |
|
141 } |
|
142 } |
75 } |