1. /*
  2. * @(#)PropertyResourceBundle.java 1.25 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. /*
  8. * (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
  9. * (C) Copyright IBM Corp. 1996 - 1998 - All Rights Reserved
  10. *
  11. * The original version of this source code and documentation
  12. * is copyrighted and owned by Taligent, Inc., a wholly-owned
  13. * subsidiary of IBM. These materials are provided under terms
  14. * of a License Agreement between Taligent and Sun. This technology
  15. * is protected by multiple US and International patents.
  16. *
  17. * This notice and attribution to Taligent may not be removed.
  18. * Taligent is a registered trademark of Taligent, Inc.
  19. */
  20. package java.util;
  21. import java.io.InputStream;
  22. import java.io.IOException;
  23. /**
  24. * <code>PropertyResourceBundle</code> is a concrete subclass of
  25. * <code>ResourceBundle</code> that manages resources for a locale
  26. * using a set of static strings from a property file. See
  27. * {@link ResourceBundle ResourceBundle} for more information about resource
  28. * bundles. See {@link Properties Properties} for more information
  29. * about properties files, in particular the
  30. * <a href="Properties.html#encoding">information on character encodings</a>.
  31. *
  32. * <p>
  33. * Unlike other types of resource bundle, you don't subclass
  34. * <code>PropertyResourceBundle</code>. Instead, you supply properties
  35. * files containing the resource data. <code>ResourceBundle.getBundle</code>
  36. * will automatically look for the appropriate properties file and create a
  37. * <code>PropertyResourceBundle</code> that refers to it. See
  38. * {@link ResourceBundle#getBundle(java.lang.String, java.util.Locale, java.lang.ClassLoader) ResourceBundle.getBundle}
  39. * for a complete description of the search and instantiation strategy.
  40. *
  41. * <p>
  42. * The following <a name="sample">example</a> shows a member of a resource
  43. * bundle family with the base name "MyResources".
  44. * The text defines the bundle "MyResources_de",
  45. * the German member of the bundle family.
  46. * This member is based on <code>PropertyResourceBundle</code>, and the text
  47. * therefore is the content of the file "MyResources_de.properties"
  48. * (a related <a href="ListResourceBundle.html#sample">example</a> shows
  49. * how you can add bundles to this family that are implemented as subclasses
  50. * of <code>ListResourceBundle</code>).
  51. * The keys in this example are of the form "s1" etc. The actual
  52. * keys are entirely up to your choice, so long as they are the same as
  53. * the keys you use in your program to retrieve the objects from the bundle.
  54. * Keys are case-sensitive.
  55. * <blockquote>
  56. * <pre>
  57. * # MessageFormat pattern
  58. * s1=Die Platte \"{1}\" enthält {0}.
  59. *
  60. * # location of {0} in pattern
  61. * s2=1
  62. *
  63. * # sample disk name
  64. * s3=Meine Platte
  65. *
  66. * # first ChoiceFormat choice
  67. * s4=keine Dateien
  68. *
  69. * # second ChoiceFormat choice
  70. * s5=eine Datei
  71. *
  72. * # third ChoiceFormat choice
  73. * s6={0,number} Dateien
  74. *
  75. * # sample date
  76. * s7=3. März 1996
  77. * </pre>
  78. * </blockquote>
  79. *
  80. * @see ResourceBundle
  81. * @see ListResourceBundle
  82. * @see Properties
  83. * @since JDK1.1
  84. */
  85. public class PropertyResourceBundle extends ResourceBundle {
  86. /**
  87. * Creates a property resource bundle.
  88. * @param stream property file to read from.
  89. */
  90. public PropertyResourceBundle (InputStream stream) throws IOException {
  91. Properties properties = new Properties();
  92. properties.load(stream);
  93. lookup = new HashMap(properties);
  94. }
  95. // Implements java.util.ResourceBundle.handleGetObject; inherits javadoc specification.
  96. public Object handleGetObject(String key) {
  97. if (key == null) {
  98. throw new NullPointerException();
  99. }
  100. return lookup.get(key);
  101. }
  102. /**
  103. * Implementation of ResourceBundle.getKeys.
  104. */
  105. public Enumeration getKeys() {
  106. ResourceBundle parent = this.parent;
  107. return new ResourceBundleEnumeration(lookup.keySet(),
  108. (parent != null) ? parent.getKeys() : null);
  109. }
  110. // ==================privates====================
  111. private Map lookup;
  112. }