001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the "License"); 007 * you may not use this file except in compliance with the License. 008 * You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 /* 019 * $Id: XResourceBundle.java 468655 2006-10-28 07:12:06Z minchau $ 020 */ 021 package org.apache.xml.utils.res; 022 023 import java.util.ListResourceBundle; 024 import java.util.Locale; 025 import java.util.MissingResourceException; 026 import java.util.ResourceBundle; 027 028 /** 029 * The default (english) resource bundle. 030 * @xsl.usage internal 031 */ 032 public class XResourceBundle extends ListResourceBundle 033 { 034 035 /** Error resource constants */ 036 public static final String ERROR_RESOURCES = 037 "org.apache.xalan.res.XSLTErrorResources", XSLT_RESOURCE = 038 "org.apache.xml.utils.res.XResourceBundle", LANG_BUNDLE_NAME = 039 "org.apache.xml.utils.res.XResources", MULT_ORDER = 040 "multiplierOrder", MULT_PRECEDES = "precedes", MULT_FOLLOWS = 041 "follows", LANG_ORIENTATION = "orientation", LANG_RIGHTTOLEFT = 042 "rightToLeft", LANG_LEFTTORIGHT = "leftToRight", LANG_NUMBERING = 043 "numbering", LANG_ADDITIVE = "additive", LANG_MULT_ADD = 044 "multiplicative-additive", LANG_MULTIPLIER = 045 "multiplier", LANG_MULTIPLIER_CHAR = 046 "multiplierChar", LANG_NUMBERGROUPS = "numberGroups", LANG_NUM_TABLES = 047 "tables", LANG_ALPHABET = "alphabet", LANG_TRAD_ALPHABET = "tradAlphabet"; 048 049 /** 050 * Return a named ResourceBundle for a particular locale. This method mimics the behavior 051 * of ResourceBundle.getBundle(). 052 * 053 * @param className Name of local-specific subclass. 054 * @param locale the locale to prefer when searching for the bundle 055 */ 056 public static final XResourceBundle loadResourceBundle( 057 String className, Locale locale) throws MissingResourceException 058 { 059 060 String suffix = getResourceSuffix(locale); 061 062 //System.out.println("resource " + className + suffix); 063 try 064 { 065 066 // first try with the given locale 067 String resourceName = className + suffix; 068 return (XResourceBundle) ResourceBundle.getBundle(resourceName, locale); 069 } 070 catch (MissingResourceException e) 071 { 072 try // try to fall back to en_US if we can't load 073 { 074 075 // Since we can't find the localized property file, 076 // fall back to en_US. 077 return (XResourceBundle) ResourceBundle.getBundle( 078 XSLT_RESOURCE, new Locale("en", "US")); 079 } 080 catch (MissingResourceException e2) 081 { 082 083 // Now we are really in trouble. 084 // very bad, definitely very bad...not going to get very far 085 throw new MissingResourceException( 086 "Could not load any resource bundles.", className, ""); 087 } 088 } 089 } 090 091 /** 092 * Return the resource file suffic for the indicated locale 093 * For most locales, this will be based the language code. However 094 * for Chinese, we do distinguish between Taiwan and PRC 095 * 096 * @param locale the locale 097 * @return an String suffix which canbe appended to a resource name 098 */ 099 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 */ 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 }