• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package org.unicode.cldr.tool;
2 
3 import java.io.IOException;
4 
5 import org.unicode.cldr.tool.FormattedFileWriter.Anchors;
6 import org.unicode.cldr.util.CLDRConfig;
7 import org.unicode.cldr.util.CLDRFile;
8 import org.unicode.cldr.util.SupplementalDataInfo;
9 
10 import com.ibm.icu.util.ICUUncheckedIOException;
11 
12 /**
13  * To add a new chart, subclass this, and add the subclass to {@link ShowLanguages.printLanguageData()}. There isn't much
14  * documentation, so best to look at a simple subclass to see how it works.
15  * @author markdavis
16  */
17 public abstract class Chart {
18     public static final CLDRConfig CONFIG = CLDRConfig.getInstance();
19     public static final SupplementalDataInfo SDI = CONFIG.getSupplementalDataInfo();
20     public static final CLDRFile ENGLISH = CONFIG.getEnglish();
21     public static final String LS = System.lineSeparator();
22 
23     /**
24      * null means a string will be constructed from the title. Otherwise a real file name (no html extension).
25      * @return
26      */
getFileName()27     public String getFileName() {
28         return null;
29     };
30 
31     /**
32      * Show Date?
33      * @return
34      */
getExplanation()35     public String getExplanation() {
36         return null;
37     }
38 
39     /**
40      * Short explanation that will go just after the title/dates.
41      * @return
42      */
getShowDate()43     public boolean getShowDate() {
44         return true;
45     }
46 
47     /**
48      * Directory for the file to go into.
49      * @return
50      */
getDirectory()51     public abstract String getDirectory();
52 
53     /**
54      * Short title for page. Will appear at the top, and in the window title, and in the index.
55      * @return
56      */
getTitle()57     public abstract String getTitle();
58 
59     /**
60      * Work
61      * @param pw
62      * @throws IOException
63      */
writeContents(FormattedFileWriter pw)64     public abstract void writeContents(FormattedFileWriter pw) throws IOException;
65 
writeFooter(FormattedFileWriter pw)66     public void writeFooter(FormattedFileWriter pw) throws IOException {
67         standardFooter(pw, AnalyticsID.CLDR);
68     }
69 
70     enum AnalyticsID {
71         CLDR("UA-7672775-1"), ICU("UA-7670213-1"), ICU_GUIDE("UA-7670256-1"), UNICODE("UA-7670213-1"), UNICODE_UTILITY("UA-8314904-1");
72         public final String id;
73 
AnalyticsID(String id)74         private AnalyticsID(String id) {
75             this.id = id;
76         }
77     }
78 
standardFooter(FormattedFileWriter pw, AnalyticsID analytics)79     public static void standardFooter(FormattedFileWriter pw, AnalyticsID analytics) throws IOException {
80         pw.write("<div style='text-align: center; margin-top:2em; margin-bottom: 60em;'><br>\n"
81             + "<a href='http://www.unicode.org/unicode/copyright.html'>\n"
82             + "<img src='http://www.unicode.org/img/hb_notice.gif' style='border-style: none; width: 216px; height=50px;' alt='Access to Copyright and terms of use'>"
83             + "</a><br>\n<script language='Javascript' type='text/javascript' src='http://www.unicode.org/webscripts/lastModified.js'></script>"
84             + "</div><script>\n\n"
85             + "(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){"
86             + "(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),"
87             + "m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)"
88             + "})(window,document,'script','//www.google-analytics.com/analytics.js','ga');"
89             + "  ga('create', '"
90             + analytics
91             + "', 'auto');"
92             + "  ga('send', 'pageview');"
93             + "</script>\n");
94     }
95 
writeChart(Anchors anchors)96     public final void writeChart(Anchors anchors) {
97         try (
98             FormattedFileWriter x = new FormattedFileWriter(getFileName(), getTitle(), getExplanation(), anchors);) {
99             x.setDirectory(getDirectory());
100             x.setShowDate(getShowDate());
101             writeContents(x);
102             writeFooter(x);
103         } catch (IOException e) {
104             throw new ICUUncheckedIOException(e);
105         }
106     }
107 
getTsvDir(String targetDir, String topicName)108     public static String getTsvDir(String targetDir, String topicName) {
109         String target = targetDir.replaceAll(topicName, "tsv");
110         if (target.equals(targetDir)) {
111             throw new IllegalArgumentException("Can't make TSV directory from " + targetDir);
112         }
113         return target;
114     }
115 }
116