1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 /* 19 * $Id: XResourceBundle.java 468655 2006-10-28 07:12:06Z minchau $ 20 */ 21 package org.apache.xml.utils.res; 22 23 import java.util.ListResourceBundle; 24 import java.util.Locale; 25 import java.util.MissingResourceException; 26 import java.util.ResourceBundle; 27 28 /** 29 * The default (english) resource bundle. 30 * @xsl.usage internal 31 */ 32 public class XResourceBundle extends ListResourceBundle 33 { 34 35 /** Error resource constants */ 36 public static final String ERROR_RESOURCES = 37 "org.apache.xalan.res.XSLTErrorResources", XSLT_RESOURCE = 38 "org.apache.xml.utils.res.XResourceBundle", LANG_BUNDLE_NAME = 39 "org.apache.xml.utils.res.XResources", MULT_ORDER = 40 "multiplierOrder", MULT_PRECEDES = "precedes", MULT_FOLLOWS = 41 "follows", LANG_ORIENTATION = "orientation", LANG_RIGHTTOLEFT = 42 "rightToLeft", LANG_LEFTTORIGHT = "leftToRight", LANG_NUMBERING = 43 "numbering", LANG_ADDITIVE = "additive", LANG_MULT_ADD = 44 "multiplicative-additive", LANG_MULTIPLIER = 45 "multiplier", LANG_MULTIPLIER_CHAR = 46 "multiplierChar", LANG_NUMBERGROUPS = "numberGroups", LANG_NUM_TABLES = 47 "tables", LANG_ALPHABET = "alphabet", LANG_TRAD_ALPHABET = "tradAlphabet"; 48 49 /** 50 * Return a named ResourceBundle for a particular locale. This method mimics the behavior 51 * of ResourceBundle.getBundle(). 52 * 53 * @param className Name of local-specific subclass. 54 * @param locale the locale to prefer when searching for the bundle 55 */ loadResourceBundle( String className, Locale locale)56 public static final XResourceBundle loadResourceBundle( 57 String className, Locale locale) throws MissingResourceException 58 { 59 60 String suffix = getResourceSuffix(locale); 61 62 //System.out.println("resource " + className + suffix); 63 try 64 { 65 66 // first try with the given locale 67 String resourceName = className + suffix; 68 return (XResourceBundle) ResourceBundle.getBundle(resourceName, locale); 69 } 70 catch (MissingResourceException e) 71 { 72 try // try to fall back to en_US if we can't load 73 { 74 75 // Since we can't find the localized property file, 76 // fall back to en_US. 77 return (XResourceBundle) ResourceBundle.getBundle( 78 XSLT_RESOURCE, new Locale("en", "US")); 79 } 80 catch (MissingResourceException e2) 81 { 82 83 // Now we are really in trouble. 84 // very bad, definitely very bad...not going to get very far 85 throw new MissingResourceException( 86 "Could not load any resource bundles.", className, ""); 87 } 88 } 89 } 90 91 /** 92 * Return the resource file suffic for the indicated locale 93 * For most locales, this will be based the language code. However 94 * for Chinese, we do distinguish between Taiwan and PRC 95 * 96 * @param locale the locale 97 * @return an String suffix which canbe appended to a resource name 98 */ getResourceSuffix(Locale locale)99 private static final String getResourceSuffix(Locale locale) 100 { 101 102 String lang = locale.getLanguage(); 103 String country = locale.getCountry(); 104 String variant = locale.getVariant(); 105 String suffix = "_" + locale.getLanguage(); 106 107 if (lang.equals("zh")) 108 suffix += "_" + country; 109 110 if (country.equals("JP")) 111 suffix += "_" + country + "_" + variant; 112 113 return suffix; 114 } 115 116 /** 117 * Get the association list. 118 * 119 * @return The association list. 120 */ getContents()121 public Object[][] getContents() 122 { 123 return new Object[][] 124 { 125 { "ui_language", "en" }, { "help_language", "en" }, { "language", "en" }, 126 { "alphabet", new CharArrayWrapper(new char[]{ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 127 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 128 'V', 'W', 'X', 'Y', 'Z' })}, 129 { "tradAlphabet", new CharArrayWrapper(new char[]{ 'A', 'B', 'C', 'D', 'E', 'F', 130 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 131 'U', 'V', 'W', 'X', 'Y', 'Z' }) }, 132 133 //language orientation 134 { "orientation", "LeftToRight" }, 135 136 //language numbering 137 { "numbering", "additive" }, 138 }; 139 } 140 } 141