jdk/test/sun/text/resources/LocaleDataTest.java
author yhuang
Wed, 29 Jul 2015 23:36:51 -0700
changeset 31914 1b365849fcfa
parent 31263 a81a0af34ca0
child 34725 4ddbc841ced3
permissions -rw-r--r--
8129361: ISO 4217 amendment 160 Reviewed-by: naoto
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
29391
b4fad461f2b5 8074791: Long-form date format incorrect month string for Finnish locale
okutsu
parents: 26858
diff changeset
     2
 * Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5304
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5304
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5304
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @bug 4052473 4052679 4055602 4066550 4067619 4068012 4068073 4070174 4070452
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 *      4070178 4070450 4070695 4070725 4070795 4071003 4071183 4071782 4072013
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 *      4072388 4072773 4075404 4084356 4087238 4092361 4094033 4094371 4098518
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *      4099810 4103218 4103220 4103861 4112136 4113638 4113654 4117054 4122468
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *      4122840 4139860 4156708 4175306 4215747 4209960 4290801 4900884 4942982
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *      4518811 4945388 4936845 4794068 4461740 4965260 4984277 4826794 5032580
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 *      5102005 5074431 6182685 6208712 6277020 6245766 6351682 6386647 6379382
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 *      6414459 6455680 6498742 6558863 6488119 6547501 6497154 6558856 6481177
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 *      6379214 6485516 6486607 4225362 4494727 6533691 6531591 6531593 6570259
4607
a1e4ca30a49a 6646611: Incorrect spelling of month name in locale for Belarusian language ("be", "BY")
yhuang
parents: 4606
diff changeset
    34
 *      6509039 6609737 6610748 6645271 6507067 6873931 6450945 6645268 6646611
5303
0c91825f1cfa 6916787: Ukrainian currency name needs to be fixed
yhuang
parents: 4616
diff changeset
    35
 *      6645405 6650730 6910489 6573250 6870908 6585666 6716626 6914413 6916787
10838
72552ade759a 7101495: In Latvia first day of week is Monday
yhuang
parents: 10293
diff changeset
    36
 *      6919624 6998391 7019267 7020960 7025837 7020583 7036905 7066203 7101495
15281
dd43cb9be0e1 8004489: Add support for Minguo and Hijrah calendars to CalendarNameProvider SPI
okutsu
parents: 14858
diff changeset
    37
 *      7003124 7085757 7028073 7171028 7189611 8000983 7195759 8004489 8006509
31263
a81a0af34ca0 8008577: Use CLDR Locale Data by Default
naoto
parents: 31062
diff changeset
    38
 *      7114053 7074882 7040556 8008577 8013836 8021121 6192407 6931564 8027695
31914
1b365849fcfa 8129361: ISO 4217 amendment 160
yhuang
parents: 31263
diff changeset
    39
 *      8017142 8037343 8055222 8042126 8074791 8075173 8080774 8129361
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * @summary Verify locale data
31263
a81a0af34ca0 8008577: Use CLDR Locale Data by Default
naoto
parents: 31062
diff changeset
    41
 * @run main LocaleDataTest
a81a0af34ca0 8008577: Use CLDR Locale Data by Default
naoto
parents: 31062
diff changeset
    42
 * @run main LocaleDataTest -cldr
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * (C) Copyright IBM Corp. 1996 - 1998 - All Rights Reserved
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * Portions copyright (c) 2007 Sun Microsystems, Inc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * The original version of this source code and documentation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * is copyrighted and owned by Taligent, Inc., a wholly-owned
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * subsidiary of IBM. These materials are provided under terms
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * of a License Agreement between Taligent and Sun. This technology
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * is protected by multiple US and International patents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * This notice and attribution to Taligent may not be removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * Taligent is a registered trademark of Taligent, Inc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * Permission to use, copy, modify, and distribute this software
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * and its documentation for NON-COMMERCIAL purposes and without
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * fee is hereby granted provided that this copyright notice
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * appears in all copies. Please refer to the file "copyright.html"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * for further important copyright and licensing information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
/*    This test is a generalized test for verifying changes to the locale data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 *    It is driven by an external file that specifies the particular pieces of locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 *    data to check.  That file is in .properties file format: a series of key/value
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 *    pairs delimited by newline characters, with the keys separated from the values
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 *    by = signs.  The keys are similar in syntax to a Unix pathname, with keys at
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 *    successive levels of containment in the resource-data hierarchy separated by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 *    slashes.  The file is in ISO 8859-1 encoding, with control characters and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 *    non-ASCII characters denoted with backslash-u escape sequences.  The program also allows
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 *    blank lines and comment lines to be interspersed with the data.  Comment lines
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 *    begin with '#'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 *    A data file for this test would look something like this:<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 *        FormatData//MonthNames/0=January
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 *        FormatData//MonthNames/1=February
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 *        LocaleNames//US=United States
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 *        LocaleNames//FR=France
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 *        FormatData/fr_FR/MonthNames/0=janvier
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 *        FormatData/fr_FR/MonthNames/1=f\u00e9vrier
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 *        LocaleNames/fr_FR/US=\u00c9tats-Unis
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 *        LocaleNames/fr_FR/FR=France</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 *
8695
e83968c6ceda 6998391: Serbian (Latin) locale support
katakai
parents: 7668
diff changeset
    99
 *    You can use language tag with '-' in locale field like this:<pre>
e83968c6ceda 6998391: Serbian (Latin) locale support
katakai
parents: 7668
diff changeset
   100
 *        LocaleNames/sr-Latn/SR=Surinam
e83968c6ceda 6998391: Serbian (Latin) locale support
katakai
parents: 7668
diff changeset
   101
 *        FormatData/sr-Latn-BA/DayNames/2=utorak</pre>
e83968c6ceda 6998391: Serbian (Latin) locale support
katakai
parents: 7668
diff changeset
   102
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 *    The command-line syntax of this test is
31263
a81a0af34ca0 8008577: Use CLDR Locale Data by Default
naoto
parents: 31062
diff changeset
   104
 *        <tt>java LocaleDataTest [-w] [{ -s | <filename> }] [-cldr]</tt>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 *    This program always sends its results to standard output.   If -w is not specified,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 *    this program prints out only the differences between the data file and the actual
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 *    resource data.  If -w is specified, the program prints out every entry, comment,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 *    and blank line from the data file.  Where there is a difference between the data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 *    file and the resource data, the data is the data from the resources.  This feature
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 *    can be used to quickly generate a new data file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 *    The user can specify an optional filename or -s.  If the user specifies a filename,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 *    the program uses that file as the data file.  If the user specifies -s, the program
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 *    reads its input from standard input rather than from a file.  If the user specifies
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 *    neither, the program reads its input from a file called LocaleData in the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 *    directory the program itself resides in.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 *    The -nothrow option prevents the program from throwing an exception when it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 *    gets an error.  -w implies -nothrow.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 *
31263
a81a0af34ca0 8008577: Use CLDR Locale Data by Default
naoto
parents: 31062
diff changeset
   122
 *    -cldr option specifies to test CLDR locale data. The default data file name for this
a81a0af34ca0 8008577: Use CLDR Locale Data by Default
naoto
parents: 31062
diff changeset
   123
 *    option is "LocaleData.cldr".
a81a0af34ca0 8008577: Use CLDR Locale Data by Default
naoto
parents: 31062
diff changeset
   124
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 *    Other command-line options can be specified, but are ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 *    It's important to note what this test will NOT test.  Certain changes to the locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 *    data are meant to have certain effects on the internationalization frameworks.  For
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 *    instance, we could ensure round-trip formatting/parsing integrity for the full
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 *    date/time format of SimpleDateFormat by making sure that the full date and time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 *    patterns include sufficient data.  The test of this is not whether changes were
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 *    made to the locale data; it's whether using this data gives round-trip integrity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 *    Likewise, changing the currency patterns to use \u00a4 instead of local currency
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 *    symbols isn't something that can be tested by this test; instead, you want to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 *    actually format currency values and make sure the proper currency symbol was used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
 *    This test by itself doesn't do an exhaustive comparison of locale data.  It is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
 *    possible to do this manually, however:  Use the GenerateKeyList tool to produce
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
 *    a complete list of keys for the two versions of the locales you want to compare,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 *    and then diff them.  This will flag additions and deletions.  Generate a data file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 *    for the base version of the data using the -w option and the output from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 *    GenerateKeyList, and then use the resultant file as the data file when you run
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 *    this test against the new version of the data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
import java.text.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
import java.util.Locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
import java.util.ResourceBundle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
import java.util.ResourceBundle.Control;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
import java.util.MissingResourceException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
public class LocaleDataTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
{
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12850
diff changeset
   155
    static final String TEXT_RESOURCES_PACKAGE ="sun.text.resources";
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12850
diff changeset
   156
    static final String UTIL_RESOURCES_PACKAGE ="sun.util.resources";
31263
a81a0af34ca0 8008577: Use CLDR Locale Data by Default
naoto
parents: 31062
diff changeset
   157
    static final String DEFAULT_DATAFILE ="LocaleData";
a81a0af34ca0 8008577: Use CLDR Locale Data by Default
naoto
parents: 31062
diff changeset
   158
    static String cldrSuffix = "";
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12850
diff changeset
   159
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        // set up our flags and our input and output streams based on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        // command-line arguments (exceptions generated here will propagate out
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        // to the environment)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        BufferedReader in = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        PrintWriter out = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        boolean writeNewFile = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        boolean doThrow = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        for (int i = 0; i < args.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            if (args[i].equals("-w")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                writeNewFile = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                doThrow = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            else if (args[i].equals("-nothrow"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                doThrow = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
31263
a81a0af34ca0 8008577: Use CLDR Locale Data by Default
naoto
parents: 31062
diff changeset
   179
            else if (args[i].equals("-cldr")) {
a81a0af34ca0 8008577: Use CLDR Locale Data by Default
naoto
parents: 31062
diff changeset
   180
                cldrSuffix = ".cldr";
a81a0af34ca0 8008577: Use CLDR Locale Data by Default
naoto
parents: 31062
diff changeset
   181
            }
a81a0af34ca0 8008577: Use CLDR Locale Data by Default
naoto
parents: 31062
diff changeset
   182
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            else if (args[i].equals("-s") && in == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                in = new BufferedReader(new EscapeReader(new InputStreamReader(System.in,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                                "ISO8859_1")));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            else if (!args[i].startsWith("-") && in == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                in = new BufferedReader(new EscapeReader(new InputStreamReader(new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                                FileInputStream(args[i]), "ISO8859_1")));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        if (in == null) {
31263
a81a0af34ca0 8008577: Use CLDR Locale Data by Default
naoto
parents: 31062
diff changeset
   191
            File localeData = new File(System.getProperty("test.src", "."), DEFAULT_DATAFILE + cldrSuffix);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            in = new BufferedReader(new EscapeReader(new InputStreamReader(new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                            FileInputStream(localeData), "ISO8859_1")));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        out = new PrintWriter(new EscapeWriter(new OutputStreamWriter(System.out,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                        "ISO8859_1")), true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        // perform the actual test
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        int errorCount = doTest(in, out, writeNewFile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        // write out the error count, and throw an exception out into the environment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        // if there were any errors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        if (errorCount != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            if (!writeNewFile)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                out.println("Test failed.  " + errorCount + " errors.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            if (doThrow)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                throw new Exception("Test failed.  " + errorCount + " errors.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        else if (!writeNewFile)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            out.println("Test passed.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        in.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        out.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    static int doTest(BufferedReader in, PrintWriter out, boolean writeNewFile)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                    throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        int errorCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        String key = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        String expectedValue = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        String line = in.readLine();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        while (line != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            if (line.startsWith("#") || line.length() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                if (writeNewFile)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                    out.println(line);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                int index  = line.indexOf("=");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                if (index == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                    key = line;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                    expectedValue = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                    key = line.substring(0, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                    if (index + 1 == line.length())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                        expectedValue = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                        expectedValue = line.substring(index + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                if (!processLine(key, expectedValue, out, writeNewFile))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                    ++errorCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            line = in.readLine();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        return errorCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    static boolean processLine(String key, String expectedValue, PrintWriter out,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                    boolean writeNewFile) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        String rbName, localeName, resTag, qualifier;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        String language = "", country = "", variant = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        int index, oldIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        index = key.indexOf("/");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        if (index == -1 || index + 1 == key.length())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            throw new Exception("Malformed input file: no slashes in \"" + key + "\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        rbName = key.substring(0, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        oldIndex = index + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        index = key.indexOf("/", oldIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        if (index == -1 || index + 1 == key.length())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            throw new Exception("Malformed input file: \"" + key + "\" is missing locale name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        localeName = key.substring(oldIndex, index);
8695
e83968c6ceda 6998391: Serbian (Latin) locale support
katakai
parents: 7668
diff changeset
   266
        boolean use_tag = localeName.indexOf("-") != -1;
e83968c6ceda 6998391: Serbian (Latin) locale support
katakai
parents: 7668
diff changeset
   267
e83968c6ceda 6998391: Serbian (Latin) locale support
katakai
parents: 7668
diff changeset
   268
        if (use_tag == false && localeName.length() > 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            language = localeName.substring(0, 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            if (localeName.length() > 3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                country = localeName.substring(3, 5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                if (localeName.length() > 5)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                    variant = localeName.substring(6);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        oldIndex = index + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        index = key.indexOf("/", oldIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        if (index == -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            index = key.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        resTag = key.substring(oldIndex, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
4600
d49895808acd 6610748: Dateformat - AM-PM indicator in Finnish appears to be from English
yhuang
parents: 891
diff changeset
   283
        // TimeZone name may have "/" in it, for example "Asia/Taipei", so use "Asia\/Taipei in LocaleData.
d49895808acd 6610748: Dateformat - AM-PM indicator in Finnish appears to be from English
yhuang
parents: 891
diff changeset
   284
        if(resTag.endsWith("\\")) {
d49895808acd 6610748: Dateformat - AM-PM indicator in Finnish appears to be from English
yhuang
parents: 891
diff changeset
   285
            resTag = resTag.substring(0, resTag.length() - 1);
d49895808acd 6610748: Dateformat - AM-PM indicator in Finnish appears to be from English
yhuang
parents: 891
diff changeset
   286
            oldIndex = index;
d49895808acd 6610748: Dateformat - AM-PM indicator in Finnish appears to be from English
yhuang
parents: 891
diff changeset
   287
            index = key.indexOf("/", oldIndex + 1);
d49895808acd 6610748: Dateformat - AM-PM indicator in Finnish appears to be from English
yhuang
parents: 891
diff changeset
   288
            if (index == -1) index = key.length();
d49895808acd 6610748: Dateformat - AM-PM indicator in Finnish appears to be from English
yhuang
parents: 891
diff changeset
   289
            resTag += key.substring(oldIndex, index);
d49895808acd 6610748: Dateformat - AM-PM indicator in Finnish appears to be from English
yhuang
parents: 891
diff changeset
   290
        }
d49895808acd 6610748: Dateformat - AM-PM indicator in Finnish appears to be from English
yhuang
parents: 891
diff changeset
   291
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        if (index < key.length() - 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            qualifier = key.substring(index + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            qualifier = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        String retrievedValue = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        Object resource = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            String fullName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            if (rbName.equals("CalendarData")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                    || rbName.equals("CurrencyNames")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                    || rbName.equals("LocaleNames")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                    || rbName.equals("TimeZoneNames")) {
31263
a81a0af34ca0 8008577: Use CLDR Locale Data by Default
naoto
parents: 31062
diff changeset
   305
                fullName = UTIL_RESOURCES_PACKAGE + cldrSuffix + "." + rbName;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            } else {
31263
a81a0af34ca0 8008577: Use CLDR Locale Data by Default
naoto
parents: 31062
diff changeset
   307
                fullName = TEXT_RESOURCES_PACKAGE + cldrSuffix + "." + rbName;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            }
8695
e83968c6ceda 6998391: Serbian (Latin) locale support
katakai
parents: 7668
diff changeset
   309
            Locale locale;
e83968c6ceda 6998391: Serbian (Latin) locale support
katakai
parents: 7668
diff changeset
   310
            if (use_tag) {
e83968c6ceda 6998391: Serbian (Latin) locale support
katakai
parents: 7668
diff changeset
   311
                locale = Locale.forLanguageTag(localeName);
e83968c6ceda 6998391: Serbian (Latin) locale support
katakai
parents: 7668
diff changeset
   312
            } else {
e83968c6ceda 6998391: Serbian (Latin) locale support
katakai
parents: 7668
diff changeset
   313
                locale = new Locale(language, country, variant);
e83968c6ceda 6998391: Serbian (Latin) locale support
katakai
parents: 7668
diff changeset
   314
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            ResourceBundle bundle = ResourceBundle.getBundle(fullName,
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12850
diff changeset
   316
                                                             locale,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12850
diff changeset
   317
                                                             JRELocaleResourceBundleControl.INSTANCE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            resource = bundle.getObject(resTag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        catch (MissingResourceException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        if (resource != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            if (resource instanceof String) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                retrievedValue = (String)resource;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            else if (resource instanceof String[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                int element = Integer.valueOf(qualifier).intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                String[] stringList = (String[])resource;
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12850
diff changeset
   330
                if (element >= 0 && element < stringList.length)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                    retrievedValue = stringList[element];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            else if (resource instanceof String[][]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                String[][] stringArray = (String[][])resource;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                int slash = qualifier.indexOf("/");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                if (slash == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                    for (int i = 0; i < stringArray.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                        if (stringArray[i][0].equals(qualifier))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                            retrievedValue = stringArray[i][1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                    int row = Integer.valueOf(qualifier.substring(0, slash)).intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                    int column = Integer.valueOf(qualifier.substring(slash + 1)).intValue();
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12850
diff changeset
   345
                    if (row >= 0 && row < stringArray.length && column >= 0 && column <
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                                    stringArray[row].length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                        retrievedValue = stringArray[row][column];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        if (retrievedValue == null || !retrievedValue.equals(expectedValue)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            if (retrievedValue == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                retrievedValue = "<MISSING!>";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            if (writeNewFile)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                out.println(key + "=" + retrievedValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                out.println("Mismatch in " + key + ":");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                out.println("  file = \"" + expectedValue + "\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                out.println("   jvm = \"" + retrievedValue + "\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            if (writeNewFile)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                out.println(key + "=" + expectedValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    }
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12850
diff changeset
   371
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12850
diff changeset
   372
    private static class JRELocaleResourceBundleControl extends ResourceBundle.Control {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12850
diff changeset
   373
        static final JRELocaleResourceBundleControl INSTANCE = new JRELocaleResourceBundleControl();
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12850
diff changeset
   374
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12850
diff changeset
   375
        private JRELocaleResourceBundleControl() {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12850
diff changeset
   376
        }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12850
diff changeset
   377
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12850
diff changeset
   378
        @Override
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12850
diff changeset
   379
        public Locale getFallbackLocale(String baseName, Locale locale) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12850
diff changeset
   380
            if (baseName == null || locale == null) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12850
diff changeset
   381
                throw new NullPointerException();
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12850
diff changeset
   382
            }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12850
diff changeset
   383
            return null;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12850
diff changeset
   384
        }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12850
diff changeset
   385
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12850
diff changeset
   386
        /**
31263
a81a0af34ca0 8008577: Use CLDR Locale Data by Default
naoto
parents: 31062
diff changeset
   387
         * Changes baseName to its per-language/country package name and
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12850
diff changeset
   388
         * calls the super class implementation. For example,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12850
diff changeset
   389
         * if the baseName is "sun.text.resources.FormatData" and locale is ja_JP,
31263
a81a0af34ca0 8008577: Use CLDR Locale Data by Default
naoto
parents: 31062
diff changeset
   390
         * the baseName is changed to "sun.text.resources.ja.JP.FormatData". If
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12850
diff changeset
   391
         * baseName contains "cldr", such as "sun.text.resources.cldr.FormatData",
31263
a81a0af34ca0 8008577: Use CLDR Locale Data by Default
naoto
parents: 31062
diff changeset
   392
         * the name is changed to "sun.text.resources.cldr.ja.JP.FormatData".
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12850
diff changeset
   393
         */
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12850
diff changeset
   394
        @Override
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12850
diff changeset
   395
        public String toBundleName(String baseName, Locale locale) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12850
diff changeset
   396
            String newBaseName = baseName;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12850
diff changeset
   397
            String lang = locale.getLanguage();
31263
a81a0af34ca0 8008577: Use CLDR Locale Data by Default
naoto
parents: 31062
diff changeset
   398
            String ctry = locale.getCountry();
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12850
diff changeset
   399
            if (lang.length() > 0) {
31263
a81a0af34ca0 8008577: Use CLDR Locale Data by Default
naoto
parents: 31062
diff changeset
   400
                if (baseName.startsWith(UTIL_RESOURCES_PACKAGE + cldrSuffix)
a81a0af34ca0 8008577: Use CLDR Locale Data by Default
naoto
parents: 31062
diff changeset
   401
                    || baseName.startsWith(TEXT_RESOURCES_PACKAGE + cldrSuffix)) {
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12850
diff changeset
   402
                    // Assume the lengths are the same.
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12850
diff changeset
   403
                    if (UTIL_RESOURCES_PACKAGE.length()
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12850
diff changeset
   404
                        != TEXT_RESOURCES_PACKAGE.length()) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12850
diff changeset
   405
                        throw new InternalError("The resources package names have different lengths.");
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12850
diff changeset
   406
                    }
31263
a81a0af34ca0 8008577: Use CLDR Locale Data by Default
naoto
parents: 31062
diff changeset
   407
                    int index = (TEXT_RESOURCES_PACKAGE + cldrSuffix).length();
a81a0af34ca0 8008577: Use CLDR Locale Data by Default
naoto
parents: 31062
diff changeset
   408
                    ctry = (ctry.length() == 2) ? ("." + ctry) : "";
a81a0af34ca0 8008577: Use CLDR Locale Data by Default
naoto
parents: 31062
diff changeset
   409
                    newBaseName = baseName.substring(0, index + 1) + lang + ctry
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12850
diff changeset
   410
                                      + baseName.substring(index);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12850
diff changeset
   411
                }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12850
diff changeset
   412
            }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12850
diff changeset
   413
            return super.toBundleName(newBaseName, locale);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12850
diff changeset
   414
        }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12850
diff changeset
   415
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
class EscapeReader extends FilterReader {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    public EscapeReader(Reader in) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        super(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    public int read() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        if (buffer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            String b = buffer.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            int result = b.charAt(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            if (b.length() > 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                buffer = new StringBuffer(b.substring(1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                buffer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            int result = super.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            if (result != '\\')
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                buffer = new StringBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                result = super.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                buffer.append((char)result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                if (result == 'u') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                    for (int i = 0; i < 4; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                        result = super.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                        if (result == -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                        buffer.append((char)result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                    String number = buffer.toString().substring(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                    result = Integer.parseInt(number, 16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                    buffer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                    return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                return '\\';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    public int read(char[] cbuf, int start, int len) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        int p = start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        int end = start + len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        int c = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        while (c != -1 && p < end) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            c = read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
            if (c != -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                cbuf[p++] = (char)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        if (c == -1 && p == start)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            return p - start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    private StringBuffer buffer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
class EscapeWriter extends FilterWriter {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    public EscapeWriter(Writer out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        super(out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    public void write(int c) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        if ((c >= ' ' && c <= '\u007e') || c == '\r' || c == '\n')
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
            super.write(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            super.write('\\');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            super.write('u');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
            String number = Integer.toHexString(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            if (number.length() < 4)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                number = zeros.substring(0, 4 - number.length()) + number;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            super.write(number.charAt(0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            super.write(number.charAt(1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            super.write(number.charAt(2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            super.write(number.charAt(3));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    public void write(char[] cbuf, int off, int len) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        int end = off + len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        while (off < end)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            write(cbuf[off++]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    public void write(String str, int off, int len) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        int end = off + len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        while (off < end)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
            write(str.charAt(off++));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    private static String zeros = "0000";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
}