001: /*
002: * Copyright 1999-2004 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: /*
017: * $Id: XResourceBundle.java,v 1.8 2004/12/15 17:35:52 jycli Exp $
018: */
019: package org.apache.xml.utils.res;
020:
021: import java.util.ListResourceBundle;
022: import java.util.Locale;
023: import java.util.MissingResourceException;
024: import java.util.ResourceBundle;
025:
026: /**
027: * The default (english) resource bundle.
028: * @xsl.usage internal
029: */
030: public class XResourceBundle extends ListResourceBundle {
031:
032: /** Error resource constants */
033: public static final String ERROR_RESOURCES = "org.apache.xalan.res.XSLTErrorResources",
034: XSLT_RESOURCE = "org.apache.xml.utils.res.XResourceBundle",
035: LANG_BUNDLE_NAME = "org.apache.xml.utils.res.XResources",
036: MULT_ORDER = "multiplierOrder",
037: MULT_PRECEDES = "precedes",
038: MULT_FOLLOWS = "follows",
039: LANG_ORIENTATION = "orientation",
040: LANG_RIGHTTOLEFT = "rightToLeft",
041: LANG_LEFTTORIGHT = "leftToRight",
042: LANG_NUMBERING = "numbering",
043: LANG_ADDITIVE = "additive",
044: LANG_MULT_ADD = "multiplicative-additive",
045: LANG_MULTIPLIER = "multiplier",
046: LANG_MULTIPLIER_CHAR = "multiplierChar",
047: LANG_NUMBERGROUPS = "numberGroups",
048: LANG_NUM_TABLES = "tables",
049: LANG_ALPHABET = "alphabet",
050: LANG_TRAD_ALPHABET = "tradAlphabet";
051:
052: /**
053: * Return a named ResourceBundle for a particular locale. This method mimics the behavior
054: * of ResourceBundle.getBundle().
055: *
056: * @param className Name of local-specific subclass.
057: * @param locale the locale to prefer when searching for the bundle
058: */
059: public static final XResourceBundle loadResourceBundle(
060: String className, Locale locale)
061: throws MissingResourceException {
062:
063: String suffix = getResourceSuffix(locale);
064:
065: //System.out.println("resource " + className + suffix);
066: try {
067:
068: // first try with the given locale
069: String resourceName = className + suffix;
070: return (XResourceBundle) ResourceBundle.getBundle(
071: resourceName, locale);
072: } catch (MissingResourceException e) {
073: try // try to fall back to en_US if we can't load
074: {
075:
076: // Since we can't find the localized property file,
077: // fall back to en_US.
078: return (XResourceBundle) ResourceBundle.getBundle(
079: XSLT_RESOURCE, new Locale("en", "US"));
080: } catch (MissingResourceException e2) {
081:
082: // Now we are really in trouble.
083: // very bad, definitely very bad...not going to get very far
084: throw new MissingResourceException(
085: "Could not load any resource bundles.",
086: 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: String lang = locale.getLanguage();
102: String country = locale.getCountry();
103: String variant = locale.getVariant();
104: String suffix = "_" + locale.getLanguage();
105:
106: if (lang.equals("zh"))
107: suffix += "_" + country;
108:
109: if (country.equals("JP"))
110: suffix += "_" + country + "_" + variant;
111:
112: return suffix;
113: }
114:
115: /**
116: * Get the association list.
117: *
118: * @return The association list.
119: */
120: public Object[][] getContents() {
121: return new Object[][] {
122: { "ui_language", "en" },
123: { "help_language", "en" },
124: { "language", "en" },
125: {
126: "alphabet",
127: new CharArrayWrapper(
128: new char[] { 'A', 'B', 'C', 'D', 'E',
129: 'F', 'G', 'H', 'I', 'J', 'K',
130: 'L', 'M', 'N', 'O', 'P', 'Q',
131: 'R', 'S', 'T', 'U', 'V', 'W',
132: 'X', 'Y', 'Z' }) },
133: {
134: "tradAlphabet",
135: new CharArrayWrapper(
136: new char[] { 'A', 'B', 'C', 'D', 'E',
137: 'F', 'G', 'H', 'I', 'J', 'K',
138: 'L', 'M', 'N', 'O', 'P', 'Q',
139: 'R', 'S', 'T', 'U', 'V', 'W',
140: 'X', 'Y', 'Z' }) },
141:
142: //language orientation
143: { "orientation", "LeftToRight" },
144:
145: //language numbering
146: { "numbering", "additive" }, };
147: }
148: }
|