21 * $Id: XPATHErrorResources_it.java,v 1.2.4.1 2005/09/15 00:39:21 jeffsuttor Exp $ |
21 * $Id: XPATHErrorResources_it.java,v 1.2.4.1 2005/09/15 00:39:21 jeffsuttor Exp $ |
22 */ |
22 */ |
23 package com.sun.org.apache.xpath.internal.res; |
23 package com.sun.org.apache.xpath.internal.res; |
24 |
24 |
25 import java.util.ListResourceBundle; |
25 import java.util.ListResourceBundle; |
26 import java.util.Locale; |
|
27 import java.util.MissingResourceException; |
|
28 import java.util.ResourceBundle; |
|
29 |
26 |
30 /** |
27 /** |
31 * Set up error messages. |
28 * Set up error messages. |
32 * We build a two dimensional array of message keys and |
29 * We build a two dimensional array of message keys and |
33 * message strings. In order to add a new message here, |
30 * message strings. In order to add a new message here, |
937 public static final String XML_HEADER = "XML "; |
934 public static final String XML_HEADER = "XML "; |
938 |
935 |
939 /** Field QUERY_HEADER */ |
936 /** Field QUERY_HEADER */ |
940 public static final String QUERY_HEADER = "PATTERN "; |
937 public static final String QUERY_HEADER = "PATTERN "; |
941 |
938 |
942 |
|
943 /** |
|
944 * Return a named ResourceBundle for a particular locale. This method mimics the behavior |
|
945 * of ResourceBundle.getBundle(). |
|
946 * |
|
947 * @param className Name of local-specific subclass. |
|
948 * @return the ResourceBundle |
|
949 * @throws MissingResourceException |
|
950 */ |
|
951 public static final XPATHErrorResources loadResourceBundle(String className) |
|
952 throws MissingResourceException |
|
953 { |
|
954 |
|
955 Locale locale = Locale.getDefault(); |
|
956 String suffix = getResourceSuffix(locale); |
|
957 |
|
958 try |
|
959 { |
|
960 |
|
961 // first try with the given locale |
|
962 return (XPATHErrorResources) ResourceBundle.getBundle(className |
|
963 + suffix, locale); |
|
964 } |
|
965 catch (MissingResourceException e) |
|
966 { |
|
967 try // try to fall back to en_US if we can't load |
|
968 { |
|
969 |
|
970 // Since we can't find the localized property file, |
|
971 // fall back to en_US. |
|
972 return (XPATHErrorResources) ResourceBundle.getBundle(className, |
|
973 new Locale("en", "US")); |
|
974 } |
|
975 catch (MissingResourceException e2) |
|
976 { |
|
977 |
|
978 // Now we are really in trouble. |
|
979 // very bad, definitely very bad...not going to get very far |
|
980 throw new MissingResourceException( |
|
981 "Could not load any resource bundles.", className, ""); |
|
982 } |
|
983 } |
|
984 } |
|
985 |
|
986 /** |
|
987 * Return the resource file suffic for the indicated locale |
|
988 * For most locales, this will be based the language code. However |
|
989 * for Chinese, we do distinguish between Taiwan and PRC |
|
990 * |
|
991 * @param locale the locale |
|
992 * @return an String suffix which canbe appended to a resource name |
|
993 */ |
|
994 private static final String getResourceSuffix(Locale locale) |
|
995 { |
|
996 |
|
997 String suffix = "_" + locale.getLanguage(); |
|
998 String country = locale.getCountry(); |
|
999 |
|
1000 if (country.equals("TW")) |
|
1001 suffix += "_" + country; |
|
1002 |
|
1003 return suffix; |
|
1004 } |
|
1005 |
|
1006 } |
939 } |