|
| 1 | +package org.unicode.cldr.tool; |
| 2 | + |
| 3 | +import java.io.IOException; |
| 4 | +import java.io.Writer; |
| 5 | +import java.util.ArrayList; |
| 6 | +import java.util.List; |
| 7 | +import java.util.Set; |
| 8 | +import java.util.TreeSet; |
| 9 | +import org.unicode.cldr.test.CheckCLDR.CheckStatus; |
| 10 | +import org.unicode.cldr.test.CheckCLDR.SubtypeToURLProvider; |
| 11 | +import org.unicode.cldr.test.TestCache.TestResultBundle; |
| 12 | +import org.unicode.cldr.util.CLDRConfig; |
| 13 | +import org.unicode.cldr.util.CLDRFile; |
| 14 | +import org.unicode.cldr.util.CLDRPaths; |
| 15 | +import org.unicode.cldr.util.Factory; |
| 16 | + |
| 17 | +public class ChartSupplemental extends Chart { |
| 18 | + private static final CLDRConfig CLDR_CONFIG = CLDRConfig.getInstance(); |
| 19 | + static final CLDRFile ENGLISH = CLDR_CONFIG.getEnglish(); |
| 20 | + static final String DIR = CLDRPaths.CHART_DIRECTORY + "verify/supplemental/"; |
| 21 | + |
| 22 | + private final String locale; |
| 23 | + |
| 24 | + public ChartSupplemental(String locale) { |
| 25 | + super(); |
| 26 | + this.locale = locale; |
| 27 | + } |
| 28 | + |
| 29 | + @Override |
| 30 | + public String getDirectory() { |
| 31 | + return DIR; |
| 32 | + } |
| 33 | + |
| 34 | + @Override |
| 35 | + public String getTitle() { |
| 36 | + return ENGLISH.getName(locale) + ": Overall Errors"; |
| 37 | + } |
| 38 | + |
| 39 | + @Override |
| 40 | + public String getExplanation() { |
| 41 | + return "<p>This chart shows errors which apply to the entire locale.</p>"; |
| 42 | + } |
| 43 | + |
| 44 | + @Override |
| 45 | + public String getFileName() { |
| 46 | + return locale; |
| 47 | + } |
| 48 | + |
| 49 | + @Override |
| 50 | + public void writeContents( |
| 51 | + Writer pw, Factory factory, TestResultBundle test, SubtypeToURLProvider urlProvider) |
| 52 | + throws IOException { |
| 53 | + CLDRFile cldrFile = factory.make(locale, true); |
| 54 | + |
| 55 | + if (test != null) { |
| 56 | + Set<CheckStatus> pp = new TreeSet<CheckStatus>(); |
| 57 | + |
| 58 | + // add any 'early' errors |
| 59 | + pp.addAll(test.getPossibleProblems()); |
| 60 | + |
| 61 | + // add all non-path status |
| 62 | + for (final String x : cldrFile) { |
| 63 | + List<CheckStatus> result = new ArrayList<CheckStatus>(); |
| 64 | + test.check(x, result, cldrFile.getStringValue(x)); |
| 65 | + for (final CheckStatus s : result) { |
| 66 | + if (s.isEntireLocale()) pp.add(s); |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + // report |
| 71 | + |
| 72 | + if (pp.isEmpty()) { |
| 73 | + pw.write("<h3>No Errors</h3>\n"); |
| 74 | + pw.write("There are no overall locale issues to report"); |
| 75 | + } else { |
| 76 | + pw.write("<h3>Overall Errors</h3>\n"); |
| 77 | + pw.write("<ol>\n"); |
| 78 | + for (final CheckStatus s : pp) { |
| 79 | + pw.write( |
| 80 | + String.format( |
| 81 | + "<li> <b>%s</b> <i title='%s'>%s</i>\n", |
| 82 | + s.getType(), s.getSubtype().name(), s.getSubtype())); |
| 83 | + pw.write("<p>" + s.getMessage() + "</p>"); |
| 84 | + if (urlProvider != null) { |
| 85 | + final String moreDetailsUrl = urlProvider.apply(s.getSubtype()); |
| 86 | + pw.write(String.format("<a href=\"%s\">more details</a>", moreDetailsUrl)); |
| 87 | + } |
| 88 | + pw.write("</li>\n"); |
| 89 | + } |
| 90 | + pw.write("</ol>\n\n"); |
| 91 | + } |
| 92 | + } |
| 93 | + |
| 94 | + pw.write("</div> <!-- ReportSupplemental -->\n"); |
| 95 | + } |
| 96 | +} |
0 commit comments