22 */ |
22 */ |
23 package com.sun.org.apache.xml.internal.res; |
23 package com.sun.org.apache.xml.internal.res; |
24 |
24 |
25 |
25 |
26 import java.util.ListResourceBundle; |
26 import java.util.ListResourceBundle; |
27 import java.util.Locale; |
|
28 import java.util.MissingResourceException; |
|
29 import java.util.ResourceBundle; |
|
30 |
27 |
31 /** |
28 /** |
32 * Set up error messages. |
29 * Set up error messages. |
33 * We build a two dimensional array of message keys and |
30 * We build a two dimensional array of message keys and |
34 * message strings. In order to add a new message here, |
31 * message strings. In order to add a new message here, |
451 |
448 |
452 protected Object[][] getContents() { |
449 protected Object[][] getContents() { |
453 return _contents; |
450 return _contents; |
454 } |
451 } |
455 |
452 |
456 /** |
|
457 * Return a named ResourceBundle for a particular locale. This method mimics the behavior |
|
458 * of ResourceBundle.getBundle(). |
|
459 * |
|
460 * @param className the name of the class that implements the resource bundle. |
|
461 * @return the ResourceBundle |
|
462 * @throws MissingResourceException |
|
463 */ |
|
464 public static final XMLErrorResources loadResourceBundle(String className) |
|
465 throws MissingResourceException |
|
466 { |
|
467 |
|
468 Locale locale = Locale.getDefault(); |
|
469 String suffix = getResourceSuffix(locale); |
|
470 |
|
471 try |
|
472 { |
|
473 |
|
474 // first try with the given locale |
|
475 return (XMLErrorResources) ResourceBundle.getBundle(className |
|
476 + suffix, locale); |
|
477 } |
|
478 catch (MissingResourceException e) |
|
479 { |
|
480 try // try to fall back to en_US if we can't load |
|
481 { |
|
482 |
|
483 // Since we can't find the localized property file, |
|
484 // fall back to en_US. |
|
485 return (XMLErrorResources) ResourceBundle.getBundle(className, |
|
486 new Locale("en", "US")); |
|
487 } |
|
488 catch (MissingResourceException e2) |
|
489 { |
|
490 |
|
491 // Now we are really in trouble. |
|
492 // very bad, definitely very bad...not going to get very far |
|
493 throw new MissingResourceException( |
|
494 "Could not load any resource bundles.", className, ""); |
|
495 } |
|
496 } |
|
497 } |
|
498 |
|
499 /** |
|
500 * Return the resource file suffic for the indicated locale |
|
501 * For most locales, this will be based the language code. However |
|
502 * for Chinese, we do distinguish between Taiwan and PRC |
|
503 * |
|
504 * @param locale the locale |
|
505 * @return an String suffix which canbe appended to a resource name |
|
506 */ |
|
507 private static final String getResourceSuffix(Locale locale) |
|
508 { |
|
509 |
|
510 String suffix = "_" + locale.getLanguage(); |
|
511 String country = locale.getCountry(); |
|
512 |
|
513 if (country.equals("TW")) |
|
514 suffix += "_" + country; |
|
515 |
|
516 return suffix; |
|
517 } |
|
518 |
|
519 } |
453 } |