• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package org.unicode.cldr.util;
2 
3 import java.lang.annotation.Annotation;
4 import java.util.Set;
5 import java.util.regex.Matcher;
6 import java.util.regex.Pattern;
7 
8 import com.google.common.collect.ImmutableSet;
9 
10 public enum DtdType {
11     ldml("common/dtd/ldml.dtd", null, null,
12         "main",
13         "annotations",
14         "annotationsDerived",
15         "casing",
16         "collation",
17         "rbnf",
18         "segments",
19         "subdivisions"), ldmlICU("common/dtd/ldmlICU.dtd", ldml), supplementalData("common/dtd/ldmlSupplemental.dtd", null, null,
20             "supplemental",
21             "transforms",
22             "validity"), ldmlBCP47("common/dtd/ldmlBCP47.dtd", "1.7.2", null,
23                 "bcp47"), keyboard("keyboards/dtd/ldmlKeyboard.dtd", "22.1", null,
24                     "../keyboards"), platform("keyboards/dtd/ldmlPlatform.dtd", "22.1", null,
25                         "../keyboards");
26 
27     static Pattern FIRST_ELEMENT = PatternCache.get("//([^/\\[]*)");
28 
29     public final String dtdPath;
30     public final DtdType rootType;
31     public final String firstVersion;
32     public final Set<String> directories;
33 
DtdType(String dtdPath)34     private DtdType(String dtdPath) {
35         this(dtdPath, null, null);
36     }
37 
DtdType(String dtdPath, DtdType realType)38     private DtdType(String dtdPath, DtdType realType) {
39         this(dtdPath, null, realType);
40     }
41 
DtdType(String dtdPath, String firstVersion, DtdType realType, String... directories)42     private DtdType(String dtdPath, String firstVersion, DtdType realType, String... directories) {
43         this.dtdPath = dtdPath;
44         this.rootType = realType == null ? this : realType;
45         this.firstVersion = firstVersion;
46         this.directories = ImmutableSet.copyOf(directories);
47     }
48 
fromPath(String elementOrPath)49     public static DtdType fromPath(String elementOrPath) {
50         Matcher m = FIRST_ELEMENT.matcher(elementOrPath);
51         m.lookingAt();
52         return DtdType.valueOf(m.group(1));
53     }
54 
header(Class<?> generatedBy)55     public String header(Class<?> generatedBy) {
56         String gline = "";
57         if (generatedBy != null) {
58             gline = "\n\tGENERATED DATA — do not manually update!"
59                 + "\n\t\tGenerated by tool:\t" + generatedBy.getSimpleName() + "\n";
60             for (Annotation annotation : generatedBy.getAnnotations()) {
61                 if (annotation instanceof CLDRTool) {
62                     gline += "\t\tTool documented on:\t" + ((CLDRTool) annotation).url() + "\n";
63                     break;
64                 }
65             }
66         }
67 
68         return "<?xml version='1.0' encoding='UTF-8' ?>\n"
69             + "<!DOCTYPE " + this + " SYSTEM '../../" + dtdPath + "'>\n" // "common/dtd/ldmlSupplemental.dtd"
70             + "<!--\n"
71             + "\t© 1991-2017 Unicode, Inc.\n"
72             + "\tUnicode and the Unicode Logo are registered trademarks of Unicode, Inc. in the U.S. and other countries.\n"
73             + "\tFor terms of use, see http://www.unicode.org/copyright.html.\n"
74             + "\tCLDR data files are interpreted according to the LDML specification (http://unicode.org/reports/tr35/).\n"
75             + gline
76             + " -->\n"
77             + "<" + this + ">\n";
78     }
79 }