1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. *
  5. * Copyright (c) 1999 The Apache Software Foundation. All rights
  6. * reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in
  17. * the documentation and/or other materials provided with the
  18. * distribution.
  19. *
  20. * 3. The end-user documentation included with the redistribution,
  21. * if any, must include the following acknowledgment:
  22. * "This product includes software developed by the
  23. * Apache Software Foundation (http://www.apache.org/)."
  24. * Alternately, this acknowledgment may appear in the software itself,
  25. * if and wherever such third-party acknowledgments normally appear.
  26. *
  27. * 4. The names "Xalan" and "Apache Software Foundation" must
  28. * not be used to endorse or promote products derived from this
  29. * software without prior written permission. For written
  30. * permission, please contact apache@apache.org.
  31. *
  32. * 5. Products derived from this software may not be called "Apache",
  33. * nor may "Apache" appear in their name, without prior written
  34. * permission of the Apache Software Foundation.
  35. *
  36. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  37. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  38. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  39. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  40. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  41. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  42. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  43. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  44. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  45. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  46. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  47. * SUCH DAMAGE.
  48. * ====================================================================
  49. *
  50. * This software consists of voluntary contributions made by many
  51. * individuals on behalf of the Apache Software Foundation and was
  52. * originally based on software copyright (c) 1999, Lotus
  53. * Development Corporation., http://www.lotus.com. For more
  54. * information on the Apache Software Foundation, please see
  55. * <http://www.apache.org/>.
  56. */
  57. package org.apache.xml.utils.res;
  58. import java.util.*;
  59. /**
  60. * <meta name="usage" content="internal"/>
  61. * The default (english) resource bundle.
  62. */
  63. public class XResourceBundle extends ListResourceBundle
  64. {
  65. /** Error resource constants */
  66. public static final String ERROR_RESOURCES =
  67. "org.apache.xalan.res.XSLTErrorResources", XSLT_RESOURCE =
  68. "org.apache.xml.utils.res.XResourceBundle", LANG_BUNDLE_NAME =
  69. "org.apache.xml.utils.res.XResources", MULT_ORDER =
  70. "multiplierOrder", MULT_PRECEDES = "precedes", MULT_FOLLOWS =
  71. "follows", LANG_ORIENTATION = "orientation", LANG_RIGHTTOLEFT =
  72. "rightToLeft", LANG_LEFTTORIGHT = "leftToRight", LANG_NUMBERING =
  73. "numbering", LANG_ADDITIVE = "additive", LANG_MULT_ADD =
  74. "multiplicative-additive", LANG_MULTIPLIER =
  75. "multiplier", LANG_MULTIPLIER_CHAR =
  76. "multiplierChar", LANG_NUMBERGROUPS = "numberGroups", LANG_NUM_TABLES =
  77. "tables", LANG_ALPHABET = "alphabet", LANG_TRAD_ALPHABET = "tradAlphabet";
  78. /**
  79. * Return a named ResourceBundle for a particular locale. This method mimics the behavior
  80. * of ResourceBundle.getBundle().
  81. *
  82. * @param className Name of local-specific subclass.
  83. * @param locale the locale to prefer when searching for the bundle
  84. */
  85. public static final XResourceBundle loadResourceBundle(
  86. String className, Locale locale) throws MissingResourceException
  87. {
  88. String suffix = getResourceSuffix(locale);
  89. //System.out.println("resource " + className + suffix);
  90. try
  91. {
  92. // first try with the given locale
  93. String resourceName = className + suffix;
  94. return (XResourceBundle) ResourceBundle.getBundle(resourceName, locale);
  95. }
  96. catch (MissingResourceException e)
  97. {
  98. try // try to fall back to en_US if we can't load
  99. {
  100. // Since we can't find the localized property file,
  101. // fall back to en_US.
  102. return (XResourceBundle) ResourceBundle.getBundle(
  103. XSLT_RESOURCE, new Locale("en", "US"));
  104. }
  105. catch (MissingResourceException e2)
  106. {
  107. // Now we are really in trouble.
  108. // very bad, definitely very bad...not going to get very far
  109. throw new MissingResourceException(
  110. "Could not load any resource bundles.", className, "");
  111. }
  112. }
  113. }
  114. /**
  115. * Return the resource file suffic for the indicated locale
  116. * For most locales, this will be based the language code. However
  117. * for Chinese, we do distinguish between Taiwan and PRC
  118. *
  119. * @param locale the locale
  120. * @return an String suffix which canbe appended to a resource name
  121. */
  122. private static final String getResourceSuffix(Locale locale)
  123. {
  124. String lang = locale.getLanguage();
  125. String country = locale.getCountry();
  126. String variant = locale.getVariant();
  127. String suffix = "_" + locale.getLanguage();
  128. if (lang.equals("zh"))
  129. suffix += "_" + country;
  130. if (country.equals("JP"))
  131. suffix += "_" + country + "_" + variant;
  132. return suffix;
  133. }
  134. /**
  135. * Get the association list.
  136. *
  137. * @return The association list.
  138. */
  139. public Object[][] getContents()
  140. {
  141. return contents;
  142. }
  143. /** The association list. */
  144. static final Object[][] contents =
  145. {
  146. { "ui_language", "en" }, { "help_language", "en" }, { "language", "en" },
  147. { "alphabet",
  148. new char[]{ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
  149. 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
  150. 'Y', 'Z' } },
  151. { "tradAlphabet",
  152. new char[]{ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
  153. 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
  154. 'Y', 'Z' } },
  155. //language orientation
  156. { "orientation", "LeftToRight" },
  157. //language numbering
  158. { "numbering", "additive" },
  159. };
  160. }