make/src/classes/build/tools/cldrconverter/ResourceBundleGenerator.java

Print this page
rev 10560 : 8038436: Re-examine the mechanism to determine available localedata and cldrdata
Reviewed-by:


 142     private static final String METAINFO_CLASS = "CLDRLocaleDataMetaInfo";
 143 
 144     @Override
 145     public void generateMetaInfo(Map<String, SortedSet<String>> metaInfo) throws IOException {
 146         String dirName = CLDRConverter.DESTINATION_DIR + File.separator + "sun" + File.separator + "util" + File.separator
 147                 + "cldr" + File.separator;
 148         File dir = new File(dirName);
 149         if (!dir.exists()) {
 150             dir.mkdirs();
 151         }
 152         File file = new File(dir, METAINFO_CLASS + ".java");
 153         if (!file.exists()) {
 154             file.createNewFile();
 155         }
 156         CLDRConverter.info("Generating file " + file);
 157 
 158         try (PrintWriter out = new PrintWriter(file, "us-ascii")) {
 159             out.println(CopyrightHeaders.getOpenJDKCopyright());
 160 
 161             out.println("package sun.util.cldr;\n\n"
 162                       + "import java.util.ListResourceBundle;\n");
 163             out.printf("public class %s extends ListResourceBundle {\n", METAINFO_CLASS);


 164             out.println("    @Override\n" +
 165                         "    protected final Object[][] getContents() {\n" +
 166                         "        final Object[][] data = new Object[][] {");
 167             for (String key : metaInfo.keySet()) {
 168                 out.printf("            { \"%s\",\n", key);
 169                 out.printf("              \"%s\" },\n", toLocaleList(metaInfo.get(key)));
 170             }
 171             out.println("        };\n        return data;\n    }\n}");








 172         }
 173     }
 174 
 175     private static String toLocaleList(SortedSet<String> set) {
 176         StringBuilder sb = new StringBuilder(set.size() * 6);
 177         for (String id : set) {
 178             if (!"root".equals(id)) {
 179                 if (sb.length() > 0) {
 180                     sb.append(' ');
 181                 }
 182                 sb.append(id);
 183             }
 184         }
 185         return sb.toString();
 186     }
 187 }


 142     private static final String METAINFO_CLASS = "CLDRLocaleDataMetaInfo";
 143 
 144     @Override
 145     public void generateMetaInfo(Map<String, SortedSet<String>> metaInfo) throws IOException {
 146         String dirName = CLDRConverter.DESTINATION_DIR + File.separator + "sun" + File.separator + "util" + File.separator
 147                 + "cldr" + File.separator;
 148         File dir = new File(dirName);
 149         if (!dir.exists()) {
 150             dir.mkdirs();
 151         }
 152         File file = new File(dir, METAINFO_CLASS + ".java");
 153         if (!file.exists()) {
 154             file.createNewFile();
 155         }
 156         CLDRConverter.info("Generating file " + file);
 157 
 158         try (PrintWriter out = new PrintWriter(file, "us-ascii")) {
 159             out.println(CopyrightHeaders.getOpenJDKCopyright());
 160 
 161             out.println("package sun.util.cldr;\n\n"
 162                       + "import java.util.ListResourceBundle;\n"
 163                       + "import sun.util.locale.provider.LocaleProviderAdapter;\n"
 164                       + "import sun.util.locale.provider.LocaleDataMetaInfo;\n");
 165             out.printf("public class %s extends ListResourceBundle implements LocaleDataMetaInfo {\n", METAINFO_CLASS);
 166             out.println("    @Override\n" +
 167                         "    protected final Object[][] getContents() {\n" +
 168                         "        final Object[][] data = new Object[][] {");
 169             for (String key : metaInfo.keySet()) {
 170                 out.printf("            { \"%s\",\n", key);
 171                 out.printf("              \"%s\" },\n", toLocaleList(metaInfo.get(key)));
 172             }
 173             out.println("        };\n        return data;\n    }\n\n");
 174             
 175             out.println("    public LocaleProviderAdapter.Type getType() {\n" +
 176                         "        return LocaleProviderAdapter.Type.CLDR;\n" +
 177                         "    }\n\n");
 178             
 179             out.println("    public String availableLanguageTags(String category) {\n" +
 180                         "        return getString(category);\n" +
 181                         "    };\n}");
 182         }
 183     }
 184 
 185     private static String toLocaleList(SortedSet<String> set) {
 186         StringBuilder sb = new StringBuilder(set.size() * 6);
 187         for (String id : set) {
 188             if (!"root".equals(id)) {
 189                 if (sb.length() > 0) {
 190                     sb.append(' ');
 191                 }
 192                 sb.append(id);
 193             }
 194         }
 195         return sb.toString();
 196     }
 197 }