• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package org.unicode.cldr.tool;
2 
3 import java.io.IOException;
4 import java.io.PrintWriter;
5 import java.util.Iterator;
6 import java.util.ListResourceBundle;
7 import java.util.Set;
8 
9 import org.unicode.cldr.draft.FileUtilities;
10 import org.unicode.cldr.util.CLDRFile;
11 import org.unicode.cldr.util.CLDRPaths;
12 import org.unicode.cldr.util.Factory;
13 import org.unicode.cldr.util.XPathParts;
14 
15 public class GenerateTempDateData {
16     /*
17      * <dates>
18      * <calendars>
19      * <calendar type="gregorian">
20      * <dateTimeFormats>
21      * <availableFormats>
22      * <dateFormatItem id="HHmm" draft="provisional">HH:mm</dateFormatItem>
23      */
main(String[] args)24     public static void main(String[] args) throws IOException {
25         Factory cldrFactory = Factory.make(CLDRPaths.MAIN_DIRECTORY, ".*");
26         Set<String> x = cldrFactory.getAvailable();
27         PrintWriter pw = FileUtilities.openUTF8Writer(CLDRPaths.GEN_DIRECTORY + "datedata/", "DateData.java");
28         pw.println("package com.ibm.icu.impl.data;");
29         pw.println("import java.util.ListResourceBundle;");
30         pw.println("class DateData { // extracted from CLDR 1.4");
31         for (Iterator<String> it = x.iterator(); it.hasNext();) {
32             String locale = it.next();
33             CLDRFile file = cldrFactory.make(locale, false);
34             if (file.isNonInheriting()) continue;
35             System.out.println(locale);
36             boolean gotOne = false;
37             for (Iterator<String> it2 = file.iterator("//ldml/dates/calendars/calendar[@type=\"gregorian\"]/"); it2.hasNext();) {
38                 String path = it2.next();
39                 if (path.indexOf("dateTimeFormats/availableFormats/dateFormatItem") >= 0) {
40                     gotOne = doHeader(pw, locale, gotOne);
41                     XPathParts parts = XPathParts.getFrozenInstance(path);
42                     String id = parts.getAttributeValue(-1, "id");
43                     String pattern = file.getStringValue(path);
44                     pw.println("     {\"pattern/" + id + "\",\"" + com.ibm.icu.impl.Utility.escape(pattern) + "\"},");
45                 } else if (path.indexOf("dateTimeFormats/appendItems") >= 0) {
46                     gotOne = doHeader(pw, locale, gotOne);
47                     XPathParts parts = XPathParts.getFrozenInstance(path);
48                     String request = parts.getAttributeValue(-1, "request");
49                     String pattern = file.getStringValue(path);
50                     pw.println("     {\"append/" + request + "\",\"" + com.ibm.icu.impl.Utility.escape(pattern)
51                         + "\"},");
52                 } else if (path.indexOf("fields/field") >= 0) {
53                     gotOne = doHeader(pw, locale, gotOne);
54                     XPathParts parts = XPathParts.getFrozenInstance(path);
55                     String type = parts.getAttributeValue(-2, "type");
56                     String pattern = file.getStringValue(path);
57                     pw.println("     {\"field/" + type + "\",\"" + com.ibm.icu.impl.Utility.escape(pattern) + "\"},");
58                 }
59             }
60             if (gotOne) {
61                 pw.println(" };}}");
62             }
63         }
64         pw.println("}");
65         pw.close();
66     }
67 
doHeader(PrintWriter pw, String locale, boolean gotOne)68     private static boolean doHeader(PrintWriter pw, String locale, boolean gotOne) {
69         if (!gotOne) {
70             gotOne = true;
71             String suffix = locale.equals("root") ? "" : "_" + locale;
72             pw.println(" public static class MyDateResources" + suffix + " extends ListResourceBundle {");
73             pw.println("  protected Object[][] getContents() {");
74             pw.println("   return new Object[][] {");
75         }
76         return gotOne;
77     }
78 
79     /*
80      * * public class MyResources_fr extends ListResourceBundle {
81      * protected Object[][] getContents() {
82      * return new Object[][] = {
83      * // LOCALIZE THIS
84      * {"s1", "Le disque \"{1}\" {0}."}, // MessageFormat pattern
85      * {"s2", "1"}, // location of {0} in pattern
86      * {"s3", "Mon disque"}, // sample disk name
87      * {"s4", "ne contient pas de fichiers"}, // first ChoiceFormat choice
88      * {"s5", "contient un fichier"}, // second ChoiceFormat choice
89      * {"s6", "contient {0,number} fichiers"}, // third ChoiceFormat choice
90      * {"s7", "3 mars 1996"}, // sample date
91      * {"s8", new Dimension(1,3)} // real object, not just string
92      * // END OF MATERIAL TO LOCALIZE
93      * };
94      * }
95      * }
96      */
97     static class RBundle extends ListResourceBundle {
98         @Override
getContents()99         protected Object[][] getContents() {
100             // TODO Auto-generated method stub
101             return null;
102         }
103     }
104 }