• 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.LogicalGrouping;
7 import org.unicode.cldr.util.XPathParts;
8 
9 public class CheckMetazones extends CheckCLDR {
10     // remember to add this class to the list in CheckCLDR.getCheckAll
11     // to run just this test, on just locales starting with 'nl', use CheckCLDR with -fnl.* -t.*Metazones.*
12 
13     // If you don't need any file initialization or postprocessing, you only need this one routine
14     @Override
handleCheck(String path, String fullPath, String value, Options options, List<CheckStatus> result)15     public CheckCLDR handleCheck(String path, String fullPath, String value, Options options,
16         List<CheckStatus> result) {
17         // it helps performance to have a quick reject of most paths
18         if (fullPath == null) return this; // skip paths that we don't have
19         if (value == null) return this; // skip empty values
20         if (path.indexOf("/metazone") < 0) return this;
21 
22         // we're simply going to test to make sure that metazone values don't contain any digits
23         if (value.matches(".*\\p{Nd}.*")) {
24             if (!getCldrFileToCheck().getSourceLocaleID(path, null).equals(getCldrFileToCheck().getLocaleID())) { // skip
25                 // if
26                 // inherited
27                 // --
28                 // we
29                 // only
30                 // need
31                 // parent
32                 // instance
33                 return this;
34             }
35             // the following is how you signal an error or warning (or add a demo....)
36             result.add(new CheckStatus().setCause(this).setMainType(CheckStatus.errorType)
37                 .setSubtype(Subtype.metazoneContainsDigit) // typically warningType or errorType
38                 .setMessage("Metazone name contains digits - translate only the name")); // the message; can be
39             // MessageFormat with arguments
40         }
41 
42         if (path.indexOf("/long") >= 0) {
43             XPathParts parts = XPathParts.getFrozenInstance(path);
44             String metazoneName = parts.getAttributeValue(3, "type");
45             if (!metazoneUsesDST(metazoneName) && path.indexOf("/standard") < 0) {
46                 result.add(new CheckStatus().setCause(this).setMainType(CheckStatus.errorType)
47                     .setSubtype(Subtype.extraMetazoneString) // typically warningType or errorType
48                     .setMessage("Extra metazone string - should only contain standard value for a non-DST metazone"));
49                 // the message can be MessageFormat with arguments
50             }
51         }
52         return this;
53     }
54 
metazoneUsesDST(String name)55     private boolean metazoneUsesDST(String name) {
56         return LogicalGrouping.metazonesDSTSet.contains(name);
57     }
58 }
59