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 (isDSTPathForNonDSTMetazone(path)) { 43 result.add(new CheckStatus().setCause(this).setMainType(CheckStatus.errorType) 44 .setSubtype(Subtype.extraMetazoneString) // typically warningType or errorType 45 .setMessage("Extra metazone string - should only contain standard value for a non-DST metazone")); 46 } 47 return this; 48 } 49 50 /** 51 * True if this is a DST path, but a non DST metazone. 52 * Such an XPath should not be present in a CLDRFile. 53 * @param path (assumes it is a /metazone path) 54 * @return 55 */ isDSTPathForNonDSTMetazone(String path)56 public static boolean isDSTPathForNonDSTMetazone(String path) { 57 if (path.indexOf("/long") >= 0 || path.indexOf("/short") >= 0) { 58 XPathParts parts = XPathParts.getFrozenInstance(path); 59 String metazoneName = parts.getAttributeValue(3, "type"); 60 if (!metazoneUsesDST(metazoneName) && path.indexOf("/standard") < 0) { 61 return true; 62 } 63 } 64 return false; 65 } 66 metazoneUsesDST(String name)67 public static boolean metazoneUsesDST(String name) { 68 return LogicalGrouping.metazonesDSTSet.contains(name); 69 } 70 } 71