19f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson/* 29f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Licensed to the Apache Software Foundation (ASF) under one 39f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * or more contributor license agreements. See the NOTICE file 49f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * distributed with this work for additional information 59f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * regarding copyright ownership. The ASF licenses this file 69f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * to you under the Apache License, Version 2.0 (the "License"); 79f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * you may not use this file except in compliance with the License. 89f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * You may obtain a copy of the License at 99f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * http://www.apache.org/licenses/LICENSE-2.0 119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Unless required by applicable law or agreed to in writing, software 139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * distributed under the License is distributed on an "AS IS" BASIS, 149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * See the License for the specific language governing permissions and 169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * limitations under the License. 179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson/* 199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * $Id: XResourceBundle.java 468655 2006-10-28 07:12:06Z minchau $ 209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonpackage org.apache.xml.utils.res; 229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport java.util.ListResourceBundle; 249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport java.util.Locale; 259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport java.util.MissingResourceException; 269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport java.util.ResourceBundle; 279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson/** 299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * The default (english) resource bundle. 309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @xsl.usage internal 319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonpublic class XResourceBundle extends ListResourceBundle 339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson{ 349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** Error resource constants */ 369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public static final String ERROR_RESOURCES = 379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson "org.apache.xalan.res.XSLTErrorResources", XSLT_RESOURCE = 389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson "org.apache.xml.utils.res.XResourceBundle", LANG_BUNDLE_NAME = 399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson "org.apache.xml.utils.res.XResources", MULT_ORDER = 409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson "multiplierOrder", MULT_PRECEDES = "precedes", MULT_FOLLOWS = 419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson "follows", LANG_ORIENTATION = "orientation", LANG_RIGHTTOLEFT = 429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson "rightToLeft", LANG_LEFTTORIGHT = "leftToRight", LANG_NUMBERING = 439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson "numbering", LANG_ADDITIVE = "additive", LANG_MULT_ADD = 449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson "multiplicative-additive", LANG_MULTIPLIER = 459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson "multiplier", LANG_MULTIPLIER_CHAR = 469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson "multiplierChar", LANG_NUMBERGROUPS = "numberGroups", LANG_NUM_TABLES = 479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson "tables", LANG_ALPHABET = "alphabet", LANG_TRAD_ALPHABET = "tradAlphabet"; 489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Return a named ResourceBundle for a particular locale. This method mimics the behavior 519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * of ResourceBundle.getBundle(). 529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param className Name of local-specific subclass. 549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param locale the locale to prefer when searching for the bundle 559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public static final XResourceBundle loadResourceBundle( 579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson String className, Locale locale) throws MissingResourceException 589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson String suffix = getResourceSuffix(locale); 619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson //System.out.println("resource " + className + suffix); 639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson try 649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // first try with the given locale 679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson String resourceName = className + suffix; 689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return (XResourceBundle) ResourceBundle.getBundle(resourceName, locale); 699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson catch (MissingResourceException e) 719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson try // try to fall back to en_US if we can't load 739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // Since we can't find the localized property file, 769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // fall back to en_US. 779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return (XResourceBundle) ResourceBundle.getBundle( 789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson XSLT_RESOURCE, new Locale("en", "US")); 799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson catch (MissingResourceException e2) 819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // Now we are really in trouble. 849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // very bad, definitely very bad...not going to get very far 859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throw new MissingResourceException( 869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson "Could not load any resource bundles.", className, ""); 879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Return the resource file suffic for the indicated locale 939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * For most locales, this will be based the language code. However 949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * for Chinese, we do distinguish between Taiwan and PRC 959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param locale the locale 979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return an String suffix which canbe appended to a resource name 989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson private static final String getResourceSuffix(Locale locale) 1009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 1019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson String lang = locale.getLanguage(); 1039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson String country = locale.getCountry(); 1049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson String variant = locale.getVariant(); 1059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson String suffix = "_" + locale.getLanguage(); 1069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (lang.equals("zh")) 1089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson suffix += "_" + country; 1099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (country.equals("JP")) 1119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson suffix += "_" + country + "_" + variant; 1129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return suffix; 1149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 1159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 1179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Get the association list. 1189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return The association list. 1209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 1219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public Object[][] getContents() 1229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 1239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return new Object[][] 1249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 1259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { "ui_language", "en" }, { "help_language", "en" }, { "language", "en" }, 1269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { "alphabet", new CharArrayWrapper(new char[]{ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 1279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 1289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 'V', 'W', 'X', 'Y', 'Z' })}, 1299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { "tradAlphabet", new CharArrayWrapper(new char[]{ 'A', 'B', 'C', 'D', 'E', 'F', 1309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 1319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 'U', 'V', 'W', 'X', 'Y', 'Z' }) }, 1329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson //language orientation 1349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { "orientation", "LeftToRight" }, 1359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson //language numbering 1379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { "numbering", "additive" }, 1389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson }; 1399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 1409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson} 141