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 XPathParts parts = new XPathParts(); 28 PrintWriter pw = FileUtilities.openUTF8Writer(CLDRPaths.GEN_DIRECTORY + "datedata/", "DateData.java"); 29 pw.println("package com.ibm.icu.impl.data;"); 30 pw.println("import java.util.ListResourceBundle;"); 31 pw.println("class DateData { // extracted from CLDR 1.4"); 32 for (Iterator<String> it = x.iterator(); it.hasNext();) { 33 String locale = it.next(); 34 CLDRFile file = cldrFactory.make(locale, false); 35 if (file.isNonInheriting()) continue; 36 System.out.println(locale); 37 boolean gotOne = false; 38 for (Iterator<String> it2 = file.iterator("//ldml/dates/calendars/calendar[@type=\"gregorian\"]/"); it2.hasNext();) { 39 String path = it2.next(); 40 if (path.indexOf("dateTimeFormats/availableFormats/dateFormatItem") >= 0) { 41 gotOne = doHeader(pw, locale, gotOne); 42 String id = parts.set(path).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 String request = parts.set(path).getAttributeValue(-1, "request"); 48 String pattern = file.getStringValue(path); 49 pw.println(" {\"append/" + request + "\",\"" + com.ibm.icu.impl.Utility.escape(pattern) 50 + "\"},"); 51 } else if (path.indexOf("fields/field") >= 0) { 52 gotOne = doHeader(pw, locale, gotOne); 53 String type = parts.set(path).getAttributeValue(-2, "type"); 54 String pattern = file.getStringValue(path); 55 pw.println(" {\"field/" + type + "\",\"" + com.ibm.icu.impl.Utility.escape(pattern) + "\"},"); 56 } 57 } 58 if (gotOne) { 59 pw.println(" };}}"); 60 } 61 } 62 pw.println("}"); 63 pw.close(); 64 } 65 doHeader(PrintWriter pw, String locale, boolean gotOne)66 private static boolean doHeader(PrintWriter pw, String locale, boolean gotOne) { 67 if (!gotOne) { 68 gotOne = true; 69 String suffix = locale.equals("root") ? "" : "_" + locale; 70 pw.println(" public static class MyDateResources" + suffix + " extends ListResourceBundle {"); 71 pw.println(" protected Object[][] getContents() {"); 72 pw.println(" return new Object[][] {"); 73 } 74 return gotOne; 75 } 76 77 /* 78 * * public class MyResources_fr extends ListResourceBundle { 79 * protected Object[][] getContents() { 80 * return new Object[][] = { 81 * // LOCALIZE THIS 82 * {"s1", "Le disque \"{1}\" {0}."}, // MessageFormat pattern 83 * {"s2", "1"}, // location of {0} in pattern 84 * {"s3", "Mon disque"}, // sample disk name 85 * {"s4", "ne contient pas de fichiers"}, // first ChoiceFormat choice 86 * {"s5", "contient un fichier"}, // second ChoiceFormat choice 87 * {"s6", "contient {0,number} fichiers"}, // third ChoiceFormat choice 88 * {"s7", "3 mars 1996"}, // sample date 89 * {"s8", new Dimension(1,3)} // real object, not just string 90 * // END OF MATERIAL TO LOCALIZE 91 * }; 92 * } 93 * } 94 */ 95 static class RBundle extends ListResourceBundle { getContents()96 protected Object[][] getContents() { 97 // TODO Auto-generated method stub 98 return null; 99 } 100 } 101 }