001: /*
002: *
003: * @(#)PropertyResourceBundle.java 1.25 06/10/10
004: *
005: * Portions Copyright 2000-2006 Sun Microsystems, Inc. All Rights
006: * Reserved. Use is subject to license terms.
007: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
008: *
009: * This program is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU General Public License version
011: * 2 only, as published by the Free Software Foundation.
012: *
013: * This program is distributed in the hope that it will be useful, but
014: * WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016: * General Public License version 2 for more details (a copy is
017: * included at /legal/license.txt).
018: *
019: * You should have received a copy of the GNU General Public License
020: * version 2 along with this work; if not, write to the Free Software
021: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
022: * 02110-1301 USA
023: *
024: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
025: * Clara, CA 95054 or visit www.sun.com if you need additional
026: * information or have any questions.
027: */
028:
029: /*
030: * (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
031: * (C) Copyright IBM Corp. 1996 - 1998 - All Rights Reserved
032: *
033: * The original version of this source code and documentation
034: * is copyrighted and owned by Taligent, Inc., a wholly-owned
035: * subsidiary of IBM. These materials are provided under terms
036: * of a License Agreement between Taligent and Sun. This technology
037: * is protected by multiple US and International patents.
038: *
039: * This notice and attribution to Taligent may not be removed.
040: * Taligent is a registered trademark of Taligent, Inc.
041: */
042:
043: package java.util;
044:
045: import java.io.InputStream;
046: import java.io.IOException;
047:
048: /**
049: * <code>PropertyResourceBundle</code> is a concrete subclass of
050: * <code>ResourceBundle</code> that manages resources for a locale
051: * using a set of static strings from a property file. See
052: * {@link ResourceBundle ResourceBundle} for more information about resource
053: * bundles. See {@link Properties Properties} for more information
054: * about properties files, in particular the
055: * <a href="Properties.html#encoding">information on character encodings</a>.
056: *
057: * <p>
058: * Unlike other types of resource bundle, you don't subclass
059: * <code>PropertyResourceBundle</code>. Instead, you supply properties
060: * files containing the resource data. <code>ResourceBundle.getBundle</code>
061: * will automatically look for the appropriate properties file and create a
062: * <code>PropertyResourceBundle</code> that refers to it. See
063: * {@link ResourceBundle#getBundle(java.lang.String, java.util.Locale, java.lang.ClassLoader) ResourceBundle.getBundle}
064: * for a complete description of the search and instantiation strategy.
065: *
066: * <p>
067: * The following <a name="sample">example</a> shows a member of a resource
068: * bundle family with the base name "MyResources".
069: * The text defines the bundle "MyResources_de",
070: * the German member of the bundle family.
071: * This member is based on <code>PropertyResourceBundle</code>, and the text
072: * therefore is the content of the file "MyResources_de.properties"
073: * (a related <a href="ListResourceBundle.html#sample">example</a> shows
074: * how you can add bundles to this family that are implemented as subclasses
075: * of <code>ListResourceBundle</code>).
076: * The keys in this example are of the form "s1" etc. The actual
077: * keys are entirely up to your choice, so long as they are the same as
078: * the keys you use in your program to retrieve the objects from the bundle.
079: * Keys are case-sensitive.
080: * <blockquote>
081: * <pre>
082: * # MessageFormat pattern
083: * s1=Die Platte \"{1}\" enthält {0}.
084: *
085: * # location of {0} in pattern
086: * s2=1
087: *
088: * # sample disk name
089: * s3=Meine Platte
090: *
091: * # first ChoiceFormat choice
092: * s4=keine Dateien
093: *
094: * # second ChoiceFormat choice
095: * s5=eine Datei
096: *
097: * # third ChoiceFormat choice
098: * s6={0,number} Dateien
099: *
100: * # sample date
101: * s7=3. März 1996
102: * </pre>
103: * </blockquote>
104: *
105: * @see ResourceBundle
106: * @see ListResourceBundle
107: * @see Properties
108: * @since JDK1.1
109: */
110: public class PropertyResourceBundle extends ResourceBundle {
111: /**
112: * Creates a property resource bundle.
113: * @param stream property file to read from.
114: */
115: public PropertyResourceBundle(InputStream stream)
116: throws IOException {
117: Properties properties = new Properties();
118: properties.load(stream);
119: lookup = new HashMap(properties);
120: }
121:
122: // Implements java.util.ResourceBundle.handleGetObject; inherits javadoc specification.
123: public Object handleGetObject(String key) {
124: if (key == null) {
125: throw new NullPointerException();
126: }
127: return lookup.get(key);
128: }
129:
130: /**
131: * Implementation of ResourceBundle.getKeys.
132: */
133: public Enumeration getKeys() {
134: ResourceBundle parent = this .parent;
135: return new ResourceBundleEnumeration(lookup.keySet(),
136: (parent != null) ? parent.getKeys() : null);
137: }
138:
139: // ==================privates====================
140:
141: private Map lookup;
142: }
|