• 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     XPathParts parts = new XPathParts(); // used to parse out a path
14 
15     // 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)16     public CheckCLDR handleCheck(String path, String fullPath, String value, Options options,
17         List<CheckStatus> result) {
18         // it helps performance to have a quick reject of most paths
19         if (fullPath == null) return this; // skip paths that we don't have
20         if (value == null) return this; // skip empty values
21         if (path.indexOf("/metazone") < 0) return this;
22 
23         // we're simply going to test to make sure that metazone values don't contain any digits
24         if (value.matches(".*\\p{Nd}.*")) {
25             if (!getCldrFileToCheck().getSourceLocaleID(path, null).equals(getCldrFileToCheck().getLocaleID())) { // skip
26                 // if
27                 // inherited
28                 // --
29                 // we
30                 // only
31                 // need
32                 // parent
33                 // instance
34                 return this;
35             }
36             // the following is how you signal an error or warning (or add a demo....)
37             result.add(new CheckStatus().setCause(this).setMainType(CheckStatus.errorType)
38                 .setSubtype(Subtype.metazoneContainsDigit) // typically warningType or errorType
39                 .setMessage("Metazone name contains digits - translate only the name")); // the message; can be
40             // MessageFormat with arguments
41         }
42 
43         if (path.indexOf("/long") >= 0) {
44             parts.set(path);
45             String metazoneName = parts.getAttributeValue(3, "type");
46             if (!metazoneUsesDST(metazoneName) && path.indexOf("/standard") < 0) {
47                 result.add(new CheckStatus().setCause(this).setMainType(CheckStatus.errorType)
48                     .setSubtype(Subtype.extraMetazoneString) // typically warningType or errorType
49                     .setMessage("Extra metazone string - should only contain standard value for a non-DST metazone")); // the
50                 // message;
51                 // can
52                 // be
53                 // MessageFormat
54                 // with
55                 // arguments
56             }
57         }
58         return this;
59     }
60 
metazoneUsesDST(String name)61     private boolean metazoneUsesDST(String name) {
62         return LogicalGrouping.metazonesDSTSet.contains(name);
63     }
64 }
65