1 package org.unicode.cldr.tool; 2 3 import java.io.IOException; 4 import java.io.PrintWriter; 5 6 import org.unicode.cldr.draft.FileUtilities; 7 import org.unicode.cldr.util.CLDRFile; 8 import org.unicode.cldr.util.CLDRPaths; 9 import org.unicode.cldr.util.Emoji; 10 import org.unicode.cldr.util.Factory; 11 import org.unicode.cldr.util.SimpleFactory; 12 import org.unicode.cldr.util.XPathParts; 13 14 import com.ibm.icu.dev.util.UnicodeMap; 15 16 public class PrepareRootAnnotations { 17 main(String[] args)18 public static void main(String[] args) throws IOException { 19 // flesh out root with new values 20 Factory factoryAnnotations = SimpleFactory.make(CLDRPaths.ANNOTATIONS_DIRECTORY, ".*"); 21 CLDRFile oldAnnotations = factoryAnnotations.make("root", false); 22 UnicodeMap<String> oldValues = new UnicodeMap<>(); 23 for (String path : oldAnnotations) { 24 XPathParts parts = XPathParts.getFrozenInstance(path); 25 if (parts.getElement(1).equals("identity")) { 26 continue; 27 } 28 String cp = parts.getAttributeValue(-1, "cp"); 29 String value = oldAnnotations.getStringValue(path); 30 oldValues.put(cp, value); 31 } 32 CLDRFile annotations = oldAnnotations.cloneAsThawed(); 33 int counter = oldValues.size(); 34 for (String cp : Emoji.getNonConstructed()) { 35 String value = oldValues.get(cp); 36 if (value == null) { 37 oldValues.put(cp, value = "E" + (counter++)); 38 } 39 String base = "//ldml/annotations/annotation[@cp=\"" + cp + "\"]"; 40 String namePath = base + Emoji.TYPE_TTS; 41 String keywordPath = base; 42 annotations.add(namePath, value); 43 annotations.add(keywordPath, value); 44 } 45 46 try (PrintWriter pw = FileUtilities.openUTF8Writer(CLDRPaths.GEN_DIRECTORY + "annotations/", "root.xml")) { 47 annotations.write(pw); 48 pw.flush(); 49 } 50 } 51 } 52