- Timestamp:
- 2021-10-26T12:21:07+13:00 (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/XSLTUtil.java
r35394 r35707 29 29 import java.util.Enumeration; 30 30 import java.util.HashMap; 31 import java.util.HashSet; 31 32 import java.util.Locale; 32 33 … … 831 832 public static String getInterfaceStringsAsJavascript(String interface_name, String lang, String prefix, String prependToPrefix) 832 833 { 833 // now we allow looking for files in the interface's resources folder 834 CustomClassLoader my_loader = new CustomClassLoader(XSLTUtil.class.getClassLoader(), GSFile.interfaceResourceDir(GlobalProperties.getGSDL3Home(), interface_name)); 835 String prefixwithdot = prefix+"."; 834 // now we allow looking for files in the interface's resources folder 835 CustomClassLoader my_loader = new CustomClassLoader(XSLTUtil.class.getClassLoader(), GSFile.interfaceResourceDir(GlobalProperties.getGSDL3Home(), interface_name)); 836 String prefixwithdot = prefix + "."; 837 836 838 // 1. Generating Javascript of the form: 837 839 // if(!gs.text) { gs.text = new Array(); } 838 840 // if(!gs.text.dse) { gs.text.dse = new Array(); } 841 839 842 StringBuffer outputStr = new StringBuffer(); 843 HashSet<String> initialisedDepths = new HashSet<>(); 844 840 845 outputStr.append("if(!" + prependToPrefix + ") { "); 841 846 outputStr.append(prependToPrefix + " = new Array(); "); 842 847 outputStr.append("}\n"); 843 outputStr.append("if(!" + prependToPrefix + "." + prefix + ") { "); 844 outputStr.append(prependToPrefix + "." + prefix + " = new Array(); "); 845 outputStr.append("}\n"); 848 initialisedDepths.add(prependToPrefix); 849 850 // Handle '.' characters in the prefix. JS identifies these as object accessors, hence requiring a new array for each 'level'. 851 String currentDepth = prependToPrefix; 852 String[] prefixComponents = prefix.split("\\."); 853 854 for (String element : prefixComponents) { 855 currentDepth += "." + element; 856 857 outputStr.append("if(!" + currentDepth + ") { "); 858 outputStr.append(currentDepth + " = new Array(); "); 859 outputStr.append("}\n"); 860 861 initialisedDepths.add(currentDepth); 862 } 846 863 847 864 int foundCount = 0; … … 849 866 for (String dictName : new String[] { "interface_" + interface_name, "interface_default", "interface_default2" }) 850 867 { 851 // get all the keys from the english dictionary as this is a complete set852 868 // get all the keys from the english dictionary as this is a complete set 869 Dictionary dict = new Dictionary(dictName, "en", my_loader); 853 870 Enumeration keys = dict.getKeys(); 854 871 if (keys == null) … … 865 882 if (key.startsWith(prefixwithdot)) 866 883 { 884 String[] keyComponents = key.split("\\."); 885 currentDepth = prependToPrefix + "." + prefix; 886 887 for (int i = prefixComponents.length; i < keyComponents.length - 1; i++) { 888 currentDepth += "." + keyComponents[i]; 889 890 if (initialisedDepths.contains(currentDepth)) { 891 continue; 892 } 893 894 outputStr.append("if(!" + currentDepth + ") { "); 895 outputStr.append(currentDepth + " = new Array(); "); 896 outputStr.append("}\n"); 897 898 initialisedDepths.add(currentDepth); 899 } 900 867 901 // get the language dependent value for the key. This will return the english if no value found for the given lang 868 902 String value = getInterfaceText(interface_name, dictName, lang, key, null);
Note:
See TracChangeset
for help on using the changeset viewer.