• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package org.unicode.cldr.test;
2 
3 import java.util.List;
4 
5 import org.unicode.cldr.test.CheckCLDR.CheckStatus.Subtype;
6 import org.unicode.cldr.util.XPathParts;
7 
8 import com.ibm.icu.lang.UCharacter;
9 
10 public class CheckCurrencies extends CheckCLDR {
11     // remember to add this class to the list in CheckCLDR.getCheckAll
12     // to run just this test, on just locales starting with 'nl', use CheckCLDR with -fnl.* -t.*Currencies.*
13 
14     XPathParts parts = new XPathParts(); // used to parse out a path
15 
16     // If you don't need any file initialization or postprocessing, you only need this one routine
handleCheck(String path, String fullPath, String value, Options options, List<CheckStatus> result)17     public CheckCLDR handleCheck(String path, String fullPath, String value, Options options,
18         List<CheckStatus> result) {
19         // it helps performance to have a quick reject of most paths
20         if (fullPath == null) return this; // skip paths that we don't have
21         if (path.indexOf("/currency") < 0 || path.indexOf("/symbol") < 0) return this;
22 
23         // parts.set(path); // normally you have to parse out a path to get the exact one, but in this case the quick
24         // reject suffices
25 
26         // we're simply going to test the length. might do something more complicated later
27         if (value != null && value.length() > 5) {
28             // The following test no longer applies, choice format is not used for INR
29             // if (path.indexOf("[@type=\"INR\"]") >= 0) { // skip INR, since it is typically a choice (could do more
30             // sophisticated check later)
31             // return this;
32             // }
33             if (!getCldrFileToCheck().getSourceLocaleID(path, null).equals(getCldrFileToCheck().getLocaleID())) { // skip
34                 // if
35                 // inherited
36                 // --
37                 // we
38                 // only
39                 // need
40                 // parent
41                 // instance
42                 return this;
43             }
44             // Don't include Cf format chars in length test
45             int adjustedLength = value.length();
46             for (int idx = 0; idx < value.length(); idx++) {
47                 if (UCharacter.getType(value.charAt(idx)) == UCharacter.FORMAT) {
48                     if (--adjustedLength <= 5) {
49                         return this;
50                     }
51                 }
52             }
53 
54             // the following is how you signal an error or warning (or add a demo....)
55             result.add(new CheckStatus().setCause(this).setMainType(CheckStatus.warningType)
56                 .setSubtype(Subtype.currencySymbolTooWide) // typically warningType or errorType
57                 .setMessage("Currency symbol length > 5")); // the message; can be MessageFormat with arguments
58         }
59         return this;
60     }
61 }
62