1 package org.unicode.cldr.test; 2 3 import java.util.List; 4 import org.unicode.cldr.util.CLDRConfig; 5 import org.unicode.cldr.util.CLDRFile; 6 import org.unicode.cldr.util.Factory; 7 import org.unicode.cldr.util.PathHeader; 8 9 /** 10 * Subclass of CheckCLDR that requires a factory during checking. 11 * 12 * @author jchye 13 */ 14 abstract class FactoryCheckCLDR extends CheckCLDR { 15 private Factory factory; 16 private CLDRFile resolvedCldrFileToCheck; 17 private PathHeader.Factory pathHeaderFactory; 18 19 @Override getEnglishFile()20 public synchronized CLDRFile getEnglishFile() { 21 if (super.getEnglishFile() != null) { 22 return super.getEnglishFile(); 23 } 24 try { 25 return getFactory().make("en", true); 26 } catch (Exception e) { 27 return CLDRConfig.getInstance().getEnglish(); 28 } 29 } 30 getPathHeaderFactory()31 public synchronized PathHeader.Factory getPathHeaderFactory() { 32 if (pathHeaderFactory == null) { 33 pathHeaderFactory = 34 PathHeader.getFactory( 35 getEnglishFile() != null 36 ? getEnglishFile() 37 : getFactory().make("en", true)); 38 } 39 return pathHeaderFactory; 40 } 41 FactoryCheckCLDR(Factory factory)42 public FactoryCheckCLDR(Factory factory) { 43 super(); 44 this.factory = factory; 45 } 46 getResolvedCldrFileToCheck()47 public CLDRFile getResolvedCldrFileToCheck() { 48 if (resolvedCldrFileToCheck == null) { 49 resolvedCldrFileToCheck = factory.make(getCldrFileToCheck().getLocaleID(), true); 50 } 51 return resolvedCldrFileToCheck; 52 } 53 54 @Override handleSetCldrFileToCheck( CLDRFile cldrFileToCheck, Options options, List<CheckStatus> possibleErrors)55 public CheckCLDR handleSetCldrFileToCheck( 56 CLDRFile cldrFileToCheck, Options options, List<CheckStatus> possibleErrors) { 57 super.handleSetCldrFileToCheck(cldrFileToCheck, options, possibleErrors); 58 resolvedCldrFileToCheck = null; 59 return this; 60 } 61 getFactory()62 public Factory getFactory() { 63 return factory; 64 } 65 getPathReferenceForMessage(String path, boolean codeOnly)66 public String getPathReferenceForMessage(String path, boolean codeOnly) { 67 PathHeader pathHeader = getPathHeaderFactory().fromPath(path); 68 String referenceToOther; 69 String code = codeOnly ? pathHeader.getCode() : pathHeader.getHeaderCode(); 70 if (getPhase() == Phase.FINAL_TESTING) { 71 referenceToOther = code; // later make this more readable. 72 } else { 73 referenceToOther = 74 "<a href=\"" 75 + CLDRConfig.getInstance() 76 .urls() 77 .forPathHeader(getCldrFileToCheck().getLocaleID(), pathHeader) 78 + "\">" 79 + code 80 + "</a>"; 81 } 82 return referenceToOther; 83 } 84 } 85