rt/emul/compact/src/main/java/java/util/PropertyResourceBundle.java
branchjdk7-b147
changeset 1334 588d5bf7a560
child 1337 c794024954b5
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/rt/emul/compact/src/main/java/java/util/PropertyResourceBundle.java	Thu Oct 03 15:40:35 2013 +0200
     1.3 @@ -0,0 +1,190 @@
     1.4 +/*
     1.5 + * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * questions.
    1.27 + */
    1.28 +
    1.29 +/*
    1.30 + * (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
    1.31 + * (C) Copyright IBM Corp. 1996 - 1998 - All Rights Reserved
    1.32 + *
    1.33 + * The original version of this source code and documentation
    1.34 + * is copyrighted and owned by Taligent, Inc., a wholly-owned
    1.35 + * subsidiary of IBM. These materials are provided under terms
    1.36 + * of a License Agreement between Taligent and Sun. This technology
    1.37 + * is protected by multiple US and International patents.
    1.38 + *
    1.39 + * This notice and attribution to Taligent may not be removed.
    1.40 + * Taligent is a registered trademark of Taligent, Inc.
    1.41 + */
    1.42 +
    1.43 +package java.util;
    1.44 +
    1.45 +import java.io.InputStream;
    1.46 +import java.io.Reader;
    1.47 +import java.io.IOException;
    1.48 +import sun.util.ResourceBundleEnumeration;
    1.49 +
    1.50 +/**
    1.51 + * <code>PropertyResourceBundle</code> is a concrete subclass of
    1.52 + * <code>ResourceBundle</code> that manages resources for a locale
    1.53 + * using a set of static strings from a property file. See
    1.54 + * {@link ResourceBundle ResourceBundle} for more information about resource
    1.55 + * bundles.
    1.56 + *
    1.57 + * <p>
    1.58 + * Unlike other types of resource bundle, you don't subclass
    1.59 + * <code>PropertyResourceBundle</code>.  Instead, you supply properties
    1.60 + * files containing the resource data.  <code>ResourceBundle.getBundle</code>
    1.61 + * will automatically look for the appropriate properties file and create a
    1.62 + * <code>PropertyResourceBundle</code> that refers to it. See
    1.63 + * {@link ResourceBundle#getBundle(java.lang.String, java.util.Locale, java.lang.ClassLoader) ResourceBundle.getBundle}
    1.64 + * for a complete description of the search and instantiation strategy.
    1.65 + *
    1.66 + * <p>
    1.67 + * The following <a name="sample">example</a> shows a member of a resource
    1.68 + * bundle family with the base name "MyResources".
    1.69 + * The text defines the bundle "MyResources_de",
    1.70 + * the German member of the bundle family.
    1.71 + * This member is based on <code>PropertyResourceBundle</code>, and the text
    1.72 + * therefore is the content of the file "MyResources_de.properties"
    1.73 + * (a related <a href="ListResourceBundle.html#sample">example</a> shows
    1.74 + * how you can add bundles to this family that are implemented as subclasses
    1.75 + * of <code>ListResourceBundle</code>).
    1.76 + * The keys in this example are of the form "s1" etc. The actual
    1.77 + * keys are entirely up to your choice, so long as they are the same as
    1.78 + * the keys you use in your program to retrieve the objects from the bundle.
    1.79 + * Keys are case-sensitive.
    1.80 + * <blockquote>
    1.81 + * <pre>
    1.82 + * # MessageFormat pattern
    1.83 + * s1=Die Platte \"{1}\" enth&auml;lt {0}.
    1.84 + *
    1.85 + * # location of {0} in pattern
    1.86 + * s2=1
    1.87 + *
    1.88 + * # sample disk name
    1.89 + * s3=Meine Platte
    1.90 + *
    1.91 + * # first ChoiceFormat choice
    1.92 + * s4=keine Dateien
    1.93 + *
    1.94 + * # second ChoiceFormat choice
    1.95 + * s5=eine Datei
    1.96 + *
    1.97 + * # third ChoiceFormat choice
    1.98 + * s6={0,number} Dateien
    1.99 + *
   1.100 + * # sample date
   1.101 + * s7=3. M&auml;rz 1996
   1.102 + * </pre>
   1.103 + * </blockquote>
   1.104 + *
   1.105 + * <p>
   1.106 + * <strong>Note:</strong> PropertyResourceBundle can be constructed either
   1.107 + * from an InputStream or a Reader, which represents a property file.
   1.108 + * Constructing a PropertyResourceBundle instance from an InputStream requires
   1.109 + * that the input stream be encoded in ISO-8859-1.  In that case, characters
   1.110 + * that cannot be represented in ISO-8859-1 encoding must be represented by Unicode Escapes
   1.111 + * as defined in section 3.3 of
   1.112 + * <cite>The Java&trade; Language Specification</cite>
   1.113 + * whereas the other constructor which takes a Reader does not have that limitation.
   1.114 + *
   1.115 + * @see ResourceBundle
   1.116 + * @see ListResourceBundle
   1.117 + * @see Properties
   1.118 + * @since JDK1.1
   1.119 + */
   1.120 +public class PropertyResourceBundle extends ResourceBundle {
   1.121 +    /**
   1.122 +     * Creates a property resource bundle from an {@link java.io.InputStream
   1.123 +     * InputStream}.  The property file read with this constructor
   1.124 +     * must be encoded in ISO-8859-1.
   1.125 +     *
   1.126 +     * @param stream an InputStream that represents a property file
   1.127 +     *        to read from.
   1.128 +     * @throws IOException if an I/O error occurs
   1.129 +     * @throws NullPointerException if <code>stream</code> is null
   1.130 +     */
   1.131 +    public PropertyResourceBundle (InputStream stream) throws IOException {
   1.132 +        Properties properties = new Properties();
   1.133 +        properties.load(stream);
   1.134 +        lookup = new HashMap(properties);
   1.135 +    }
   1.136 +
   1.137 +    /**
   1.138 +     * Creates a property resource bundle from a {@link java.io.Reader
   1.139 +     * Reader}.  Unlike the constructor
   1.140 +     * {@link #PropertyResourceBundle(java.io.InputStream) PropertyResourceBundle(InputStream)},
   1.141 +     * there is no limitation as to the encoding of the input property file.
   1.142 +     *
   1.143 +     * @param reader a Reader that represents a property file to
   1.144 +     *        read from.
   1.145 +     * @throws IOException if an I/O error occurs
   1.146 +     * @throws NullPointerException if <code>reader</code> is null
   1.147 +     * @since 1.6
   1.148 +     */
   1.149 +    public PropertyResourceBundle (Reader reader) throws IOException {
   1.150 +        Properties properties = new Properties();
   1.151 +        properties.load(reader);
   1.152 +        lookup = new HashMap(properties);
   1.153 +    }
   1.154 +
   1.155 +    // Implements java.util.ResourceBundle.handleGetObject; inherits javadoc specification.
   1.156 +    public Object handleGetObject(String key) {
   1.157 +        if (key == null) {
   1.158 +            throw new NullPointerException();
   1.159 +        }
   1.160 +        return lookup.get(key);
   1.161 +    }
   1.162 +
   1.163 +    /**
   1.164 +     * Returns an <code>Enumeration</code> of the keys contained in
   1.165 +     * this <code>ResourceBundle</code> and its parent bundles.
   1.166 +     *
   1.167 +     * @return an <code>Enumeration</code> of the keys contained in
   1.168 +     *         this <code>ResourceBundle</code> and its parent bundles.
   1.169 +     * @see #keySet()
   1.170 +     */
   1.171 +    public Enumeration<String> getKeys() {
   1.172 +        ResourceBundle parent = this.parent;
   1.173 +        return new ResourceBundleEnumeration(lookup.keySet(),
   1.174 +                (parent != null) ? parent.getKeys() : null);
   1.175 +    }
   1.176 +
   1.177 +    /**
   1.178 +     * Returns a <code>Set</code> of the keys contained
   1.179 +     * <em>only</em> in this <code>ResourceBundle</code>.
   1.180 +     *
   1.181 +     * @return a <code>Set</code> of the keys contained only in this
   1.182 +     *         <code>ResourceBundle</code>
   1.183 +     * @since 1.6
   1.184 +     * @see #keySet()
   1.185 +     */
   1.186 +    protected Set<String> handleKeySet() {
   1.187 +        return lookup.keySet();
   1.188 +    }
   1.189 +
   1.190 +    // ==================privates====================
   1.191 +
   1.192 +    private Map<String,Object> lookup;
   1.193 +}