1 package org.unicode.cldr.test; 2 3 import java.util.List; 4 import org.unicode.cldr.test.CheckCLDR.CheckStatus.Subtype; 5 import org.unicode.cldr.util.LogicalGrouping; 6 import org.unicode.cldr.util.XPathParts; 7 8 public class CheckMetazones extends CheckCLDR { 9 // remember to add this class to the list in CheckCLDR.getCheckAll 10 // to run just this test, on just locales starting with 'nl', use CheckCLDR with -fnl.* 11 // -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( 16 String path, String fullPath, String value, Options options, 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 if (!accept(result)) 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() 26 .getSourceLocaleID(path, null) 27 .equals(getCldrFileToCheck().getLocaleID())) { // skip 28 // if 29 // inherited 30 // -- 31 // we 32 // only 33 // need 34 // parent 35 // instance 36 return this; 37 } 38 // the following is how you signal an error or warning (or add a demo....) 39 result.add( 40 new CheckStatus() 41 .setCause(this) 42 .setMainType(CheckStatus.errorType) 43 .setSubtype(Subtype.metazoneContainsDigit) // typically warningType or 44 // errorType 45 .setMessage( 46 "Metazone name contains digits - translate only the name")); // the message; can be 47 // MessageFormat with arguments 48 } 49 50 if (isDSTPathForNonDSTMetazone(path)) { 51 result.add( 52 new CheckStatus() 53 .setCause(this) 54 .setMainType(CheckStatus.errorType) 55 .setSubtype(Subtype.extraMetazoneString) // typically warningType or 56 // errorType 57 .setMessage( 58 "Extra metazone string - should only contain standard value for a non-DST metazone")); 59 } 60 return this; 61 } 62 63 /** 64 * True if this is a DST path, but a non DST metazone. Such an XPath should not be present in a 65 * CLDRFile. 66 * 67 * @param path (assumes it is a /metazone path) 68 * @return 69 */ isDSTPathForNonDSTMetazone(String path)70 public static boolean isDSTPathForNonDSTMetazone(String path) { 71 if (path.indexOf("/long") >= 0 || path.indexOf("/short") >= 0) { 72 XPathParts parts = XPathParts.getFrozenInstance(path); 73 String metazoneName = parts.getAttributeValue(3, "type"); 74 if (!metazoneUsesDST(metazoneName) && path.indexOf("/standard") < 0) { 75 return true; 76 } 77 } 78 return false; 79 } 80 metazoneUsesDST(String name)81 public static boolean metazoneUsesDST(String name) { 82 return LogicalGrouping.metazonesDSTSet.contains(name); 83 } 84 } 85