1 package org.unicode.cldr.test; 2 3 import java.util.HashSet; 4 import java.util.List; 5 import java.util.Set; 6 7 import org.unicode.cldr.test.CheckCLDR.CheckStatus.Subtype; 8 import org.unicode.cldr.util.CLDRFile; 9 import org.unicode.cldr.util.XPathParts; 10 11 public class CheckAlt extends CheckCLDR { 12 13 XPathParts parts = new XPathParts(); 14 // CLDRFile.Status status = new CLDRFile.Status(); 15 Set<String> seenSoFar = new HashSet<String>(); 16 17 // determine if we have an alt=...proposed 18 // if we have one, and there is not a non-proposed version -- in this same file, unaliased, there's a problem. handleCheck(String path, String fullPath, String value, Options options, List<CheckStatus> result)19 public CheckCLDR handleCheck(String path, String fullPath, String value, 20 Options options, List<CheckStatus> result) { 21 if (fullPath == null) return this; // skip paths that we don't have 22 23 // quick checks 24 if (path.indexOf("[@alt=") <= 0) { 25 return this; 26 } 27 if (path.indexOf("proposed") <= 0) { 28 return this; 29 } 30 31 String strippedPath = CLDRFile.getNondraftNonaltXPath(path); 32 if (strippedPath.equals(path)) { 33 return this; // paths equal, skip 34 } 35 36 String otherValue = getCldrFileToCheck().getStringValue(strippedPath); 37 if (otherValue != null) { 38 return this; 39 } 40 // String localeID = getCldrFileToCheck().getSourceLocaleID(path, null); 41 // if (!localeID.equals(getCldrFileToCheck().getLocaleID())) { 42 // return this; // must be same file 43 // } 44 // if (!status.pathWhereFound.equals(path)) return this; // must be unaliased 45 46 // if (fullPath.contains("x999")) { 47 // result.add(new CheckStatus().setCause(this).setType(CheckStatus.warningType) 48 // .setMessage("There was a conflict introduced as a result of fixing default contents: please pick among the values or add a corrected value.", 49 // new Object[]{})); 50 // } 51 52 // String strippedPath = removeProposed(path); 53 // if (strippedPath.equals(path)) return this; // happened to match "proposed" but wasn't in 'alt'; 54 // 55 // localeID = getCldrFileToCheck().getSourceLocaleID(strippedPath, null); 56 // // if localeID is null, or if it is CODE_FALLBACK_ID or root, we have a potential problem. 57 // if (localeID == null || localeID.equals(XMLSource.CODE_FALLBACK_ID)) { // || localeID.equals("root") 58 // String message = strippedPath; 59 // boolean checkOnSubmit = true; 60 61 // if (seenSoFar.contains(strippedPath)) { 62 // message += "MULTIPLE! "; 63 // checkOnSubmit = false; 64 // } 65 result.add(new CheckStatus().setCause(this).setMainType(CheckStatus.warningType) 66 .setSubtype(Subtype.noUnproposedVariant) 67 .setCheckOnSubmit(false) 68 .setMessage("Proposed item but no unproposed variant", new Object[] {})); 69 seenSoFar.add(strippedPath); 70 71 return this; 72 } 73 74 // private String removeProposed(String path) { 75 // parts.set(path); 76 // for (int i = 0; i < parts.size(); ++i) { 77 // Map attributes = parts.getAttributes(i); 78 // for (Iterator it = attributes.keySet().iterator(); it.hasNext();) { 79 // String attribute = (String) it.next(); 80 // if (!attribute.equals("alt")) continue; 81 // String attributeValue = (String) attributes.get(attribute); 82 // int pos = attributeValue.indexOf("proposed"); 83 // if (pos < 0) continue; 84 // if (pos > 0 && attributeValue.charAt(pos-1) == '-') --pos; // backup for "...-proposed" 85 // if (pos == 0) { 86 // attributes.remove(attribute); 87 // continue; 88 // } 89 // attributeValue = attributeValue.substring(0,pos); // strip it off 90 // attributes.put(attribute, attributeValue); 91 // } 92 // } 93 // String strippedPath = parts.toString(); 94 // return strippedPath; 95 // } 96 97 @Override setCldrFileToCheck(CLDRFile cldrFileToCheck, Options options, List<CheckStatus> possibleErrors)98 public CheckCLDR setCldrFileToCheck(CLDRFile cldrFileToCheck, Options options, 99 List<CheckStatus> possibleErrors) { 100 if (cldrFileToCheck == null) return this; 101 // Skip if the phase is not final testing 102 if (Phase.FINAL_TESTING == getPhase() || Phase.BUILD == getPhase()) { 103 setSkipTest(false); // ok 104 } else { 105 setSkipTest(true); 106 return this; 107 } 108 109 super.setCldrFileToCheck(cldrFileToCheck, options, possibleErrors); 110 seenSoFar.clear(); 111 return this; 112 } 113 // Matcher myLocalePlus = PatternCache.get(cldrFileToCheck.getLocaleID() + "_[^_]*").matcher(""); 114 // Set children = cldrFileToCheck.getAvailableLocales(); 115 // List iChildren = new ArrayList(); 116 // for (Iterator it = children.iterator(); it.hasNext();) { 117 // String locale = (String)it.next(); 118 // if (!myLocalePlus.reset(locale).matches()) continue; 119 // CLDRFile child = cldrFileToCheck.make(locale, true); 120 // if (child == null) { 121 // CheckStatus item = new CheckStatus().setCause(this).setType(CheckStatus.errorType) 122 // .setMessage("Null file from: {0}", new Object[]{locale}); 123 // possibleErrors.add(item); 124 // } else { 125 // iChildren.add(child); 126 // } 127 // } 128 // if (iChildren.size() == 0) immediateChildren = null; 129 // else { 130 // immediateChildren = new CLDRFile[iChildren.size()]; 131 // immediateChildren = (CLDRFile[]) iChildren.toArray(immediateChildren); 132 // } 133 // return this; 134 // } 135 136 } 137