20 /* |
20 /* |
21 * $Id: XMLMessages.java,v 1.2.4.1 2005/09/15 07:45:48 suresh_emailid Exp $ |
21 * $Id: XMLMessages.java,v 1.2.4.1 2005/09/15 07:45:48 suresh_emailid Exp $ |
22 */ |
22 */ |
23 package com.sun.org.apache.xml.internal.res; |
23 package com.sun.org.apache.xml.internal.res; |
24 |
24 |
|
25 import com.sun.org.apache.xalan.internal.utils.SecuritySupport; |
25 import java.util.ListResourceBundle; |
26 import java.util.ListResourceBundle; |
26 import java.util.Locale; |
27 import java.util.Locale; |
27 import java.util.MissingResourceException; |
|
28 import java.util.ResourceBundle; |
|
29 |
28 |
30 /** |
29 /** |
31 * A utility class for issuing XML error messages. |
30 * A utility class for issuing XML error messages. |
32 * @xsl.usage internal |
31 * @xsl.usage internal |
33 */ |
32 */ |
80 * |
79 * |
81 * @return The formatted message string. |
80 * @return The formatted message string. |
82 */ |
81 */ |
83 public static final String createXMLMessage(String msgKey, Object args[]) |
82 public static final String createXMLMessage(String msgKey, Object args[]) |
84 { |
83 { |
85 if (XMLBundle == null) |
84 if (XMLBundle == null) { |
86 XMLBundle = loadResourceBundle(XML_ERROR_RESOURCES); |
85 XMLBundle = SecuritySupport.getResourceBundle(XML_ERROR_RESOURCES); |
|
86 } |
87 |
87 |
88 if (XMLBundle != null) |
88 if (XMLBundle != null) |
89 { |
89 { |
90 return createMsg(XMLBundle, msgKey, args); |
90 return createMsg(XMLBundle, msgKey, args); |
91 } |
91 } |
154 } |
154 } |
155 |
155 |
156 return fmsg; |
156 return fmsg; |
157 } |
157 } |
158 |
158 |
159 /** |
|
160 * Return a named ResourceBundle for a particular locale. This method mimics the behavior |
|
161 * of ResourceBundle.getBundle(). |
|
162 * |
|
163 * @param className The class name of the resource bundle. |
|
164 * @return the ResourceBundle |
|
165 * @throws MissingResourceException |
|
166 */ |
|
167 public static ListResourceBundle loadResourceBundle(String className) |
|
168 throws MissingResourceException |
|
169 { |
|
170 Locale locale = Locale.getDefault(); |
|
171 |
|
172 try |
|
173 { |
|
174 return (ListResourceBundle)ResourceBundle.getBundle(className, locale); |
|
175 } |
|
176 catch (MissingResourceException e) |
|
177 { |
|
178 try // try to fall back to en_US if we can't load |
|
179 { |
|
180 |
|
181 // Since we can't find the localized property file, |
|
182 // fall back to en_US. |
|
183 return (ListResourceBundle)ResourceBundle.getBundle( |
|
184 className, new Locale("en", "US")); |
|
185 } |
|
186 catch (MissingResourceException e2) |
|
187 { |
|
188 |
|
189 // Now we are really in trouble. |
|
190 // very bad, definitely very bad...not going to get very far |
|
191 throw new MissingResourceException( |
|
192 "Could not load any resource bundles." + className, className, ""); |
|
193 } |
|
194 } |
|
195 } |
|
196 |
|
197 /** |
|
198 * Return the resource file suffic for the indicated locale |
|
199 * For most locales, this will be based the language code. However |
|
200 * for Chinese, we do distinguish between Taiwan and PRC |
|
201 * |
|
202 * @param locale the locale |
|
203 * @return an String suffix which can be appended to a resource name |
|
204 */ |
|
205 protected static String getResourceSuffix(Locale locale) |
|
206 { |
|
207 |
|
208 String suffix = "_" + locale.getLanguage(); |
|
209 String country = locale.getCountry(); |
|
210 |
|
211 if (country.equals("TW")) |
|
212 suffix += "_" + country; |
|
213 |
|
214 return suffix; |
|
215 } |
|
216 } |
159 } |