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