Path: blob/master/test/jdk/java/util/Locale/GenerateKeyList.java
41149 views
/*1* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/22/**23* This is a simple program that will generate a key list that can be used as the basis24* for a LocaleData file suitable for use with LocaleDataTest. It always sends its25* output to standard out.26*/27import java.util.Locale;28import java.util.ResourceBundle;29import java.util.Enumeration;30import java.io.PrintStream;3132public class GenerateKeyList {33public static void main(String[] args) throws Exception {34doOutputFor("sun.util.resources", "CalendarData", System.out);35doOutputFor("sun.util.resources", "CurrencyNames", System.out);36doOutputFor("sun.util.resources", "LocaleNames", System.out);37doOutputFor("sun.util.resources", "TimeZoneNames", System.out);38doOutputFor("sun.text.resources", "CollationData", System.out);39doOutputFor("sun.text.resources", "FormatData", System.out);40};4142public static void doOutputFor(String packageName,43String resourceBundleName, PrintStream out)44throws Exception {45Locale[] availableLocales = Locale.getAvailableLocales();4647ResourceBundle bundle = ResourceBundle.getBundle(packageName +48resourceBundleName, new Locale("", "", ""));49dumpResourceBundle(resourceBundleName + "/", bundle, out);50for (int i = 0; i < availableLocales.length; i++) {51bundle = ResourceBundle.getBundle(packageName + resourceBundleName,52availableLocales[i]);53dumpResourceBundle(resourceBundleName + "/" + availableLocales[i].toString(),54bundle, out);55}56}5758public static void dumpResourceBundle(String pathName, ResourceBundle bundle,59PrintStream out) throws Exception {60Enumeration keys = bundle.getKeys();61while(keys.hasMoreElements()) {62String key = (String)(keys.nextElement());63dumpResource(pathName + "/" + key, bundle.getObject(key), out);64}65}6667public static void dumpResource(String pathName, Object resource, PrintStream out)68throws Exception {69if (resource instanceof String[]) {70String[] stringList = (String[])resource;71for (int i = 0; i < stringList.length; i++)72out.println(pathName + "/" + i);73}74else if (resource instanceof String[][]) {75String[][] stringArray = (String[][])resource;76if (pathName.startsWith("TimeZoneNames")) {77for (int i = 0; i < stringArray.length; i++)78for (int j = 0; j < stringArray[i].length; j++)79out.println(pathName + "/" + i + "/" + j);80}81else {82for (int i = 0; i < stringArray.length; i++)83out.println(pathName + "/" + stringArray[i][0]);84}85}86else87out.println(pathName);88}89}909192