Changeset 25378


Ignore:
Timestamp:
04/12/12 15:47:24 (9 years ago)
Author:
ak19
Message:

Java method getInterfaceStringsAsJavascript outputs more of the javascript so that the XSLT has to output less of it.

Location:
main/trunk/greenstone3
Files:
3 edited

Legend:

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

    r25353 r25378  
    513513    }
    514514
    515     public static String getInterfaceStringsAsJavascript(String interface_name, String lang, String prefix, String prependToPrefix) {   
     515    public static String getInterfaceStringsAsJavascript(String interface_name, String lang, String prefix) {   
     516    String prependToPrefix = "gs.text";
     517    return XSLTUtil.getInterfaceStringsAsJavascript(interface_name, lang, prefix, prependToPrefix);
     518    }
     519
     520    // generates javascript: 2 arrays are declared and populated with strings that declare variables and assign their values
     521    // to be strings loaded from the interface_name.properties file for the language.   
     522    public static String getInterfaceStringsAsJavascript(String interface_name, String lang, String prefix, String prependToPrefix) {
     523    // 1. Generating Javascript of the form:
     524    // if(!gs.text) { gs.text = new Array(); }
     525    // if(!gs.text.dse) { gs.text.dse = new Array(); }
    516526    StringBuffer outputStr = new StringBuffer();
     527    outputStr.append("if(!gs.text) { ");
     528    outputStr.append(prependToPrefix + " = new Array(); ");
     529    outputStr.append("}\n");
     530    outputStr.append("if(!gs.text." + prefix + ") { ");
     531    outputStr.append(prependToPrefix + "." + prefix + " = new Array(); ");
     532    outputStr.append("}\n");
    517533   
    518534    Dictionary dict = new Dictionary("interface_" + interface_name, lang);
    519535    Enumeration keys = dict.getKeys(); 
    520536    if(keys == null) { // try default interface
    521         logger.error("****** Interface name: " + interface_name + " does not have any keys. Trying interface_default.");
     537        //logger.debug("****** Interface name: " + interface_name + " does not have any keys. Trying interface_default.");
    522538        dict = new Dictionary("interface_default", lang);
    523539        keys = dict.getKeys();
    524540    }
    525541   
    526     // get all properties in the language-specific dictionary with the given key prefix
    527     // Create a string of prependToPrefix.key= "value";\n
    528 
     542    // Get all properties in the language-specific dictionary with the given key prefix
     543    // Create Javascript strings of the form:
     544    // prependToPrefix.key= "value";\n
    529545    while(keys.hasMoreElements()) {     
    530546        String key = (String)keys.nextElement();
     
    545561    }
    546562
    547 
     563    // Test from cmdline with:
     564    // java -classpath /research/ak19/gs3-svn/web/WEB-INF/lib/gsdl3.jar:/research/ak19/gs3-svn/web/WEB-INF/lib/log4j-1.2.8.jar:/research/ak19/gs3-svn/web/WEB-INF/classes/ org.greenstone.gsdl3.util.XSLTUtil
    548565    public static void main(String args[]) {
    549566    System.out.println("\n@@@@@\n" + XSLTUtil.getInterfaceStringsAsJavascript("default", "en", "dse", "gs.text") + "@@@@@\n");
  • main/trunk/greenstone3/web/interfaces/oran/transform/layouts/header.xsl

    r25360 r25378  
    407407    <xsl:template name="document-editor-language-fragments">
    408408      <!--<gslib:langfrag name="dse"/>-->
    409 
     409     
    410410      <script type="text/javascript">
    411       gs.text = new Array();
    412       gs.text.dse = new Array();
    413       <xsl:value-of disable-output-escaping="yes" select="util:getInterfaceStringsAsJavascript($interface_name, /page/@lang, 'dse', 'gs.text')"/>
     411        <xsl:value-of disable-output-escaping="yes" select="util:getInterfaceStringsAsJavascript($interface_name, /page/@lang, 'dse')"/>       
    414412      </script>
    415413    </xsl:template>
  • main/trunk/greenstone3/web/interfaces/oran/transform/util.xsl

    r25347 r25378  
    678678  </xsl:template>
    679679
    680   <!-- needs to be name=attrvalue else xsl:param -->
    681   <!-- call function with the name prefix (e.g. dse) and the file -->
     680  <!-- call function with the name prefix (e.g. dse) -->
    682681  <xsl:template name="langfrag">
    683682    <script type="text/javascript">     
    684       gs.text = new Array();
    685       gs.text.<xsl:value-of select="@name"/> = new Array();
    686       <xsl:value-of disable-output-escaping="yes" select="util:getInterfaceStringsAsJavascript($interface_name, /page/@lang, @name, 'gs.text')"/>
     683      <xsl:value-of disable-output-escaping="yes" select="util:getInterfaceStringsAsJavascript($interface_name, /page/@lang, @name)"/>
    687684    </script>
    688685  </xsl:template>
Note: See TracChangeset for help on using the changeset viewer.