Ignore:
Timestamp:
2012-04-11T20:08:17+12:00 (12 years ago)
Author:
ak19
Message:

Array of strings to be initialised for Javascript now done by Java code instead of XSLT. Intermediate step completed where header.xsl calls the Java code. The call to Java will still need to be moved into util.xsl from header.xsl. header.xsl should use a gslib:langfrag and so invoke util.xsl, but that doesn't work yet at present.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/XSLTUtil.java

    r25312 r25347  
    2121import java.util.ArrayList;
    2222import java.util.Date;
     23import java.util.Enumeration;
    2324import java.util.HashMap;
    2425import java.util.Locale;
     
    485486        return c.createRecaptchaHtml(null, null);
    486487    }
     488
     489    public static String getInterfaceStringsAsJavascript(String interface_name, String lang, String prefix, String prependToPrefix) {   
     490    StringBuffer outputStr = new StringBuffer();
     491   
     492    Dictionary dict = new Dictionary("interface_" + interface_name, lang);
     493    Enumeration keys = dict.getKeys(); 
     494    if(keys == null) { // try default interface
     495        logger.error("****** Interface name: " + interface_name + " does not have any keys. Trying interface_default.");
     496        dict = new Dictionary("interface_default", lang);
     497        keys = dict.getKeys();
     498    }
     499   
     500    // get all properties in the language-specific dictionary with the given key prefix
     501    // Create a string of prependToPrefix.key= "value";\n
     502
     503    while(keys.hasMoreElements()) {     
     504        String key = (String)keys.nextElement();
     505        if(key.startsWith(prefix)) {
     506        String value = getInterfaceText(interface_name, lang, key);
     507
     508        outputStr.append(prependToPrefix);
     509        outputStr.append(".");
     510        outputStr.append(key);
     511        outputStr.append("=\"");
     512        outputStr.append(value);
     513        outputStr.append("\";\n");
     514        }
     515    }   
     516   
     517    return outputStr.toString();
     518   
     519    }
     520
     521
     522    public static void main(String args[]) {
     523    System.out.println("\n@@@@@\n" + XSLTUtil.getInterfaceStringsAsJavascript("default", "en", "dse", "gs.text") + "@@@@@\n");
     524    }
    487525}
Note: See TracChangeset for help on using the changeset viewer.