Changeset 25347

Show
Ignore:
Timestamp:
11.04.2012 20:08:17 (8 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.

Location:
main/trunk/greenstone3
Files:
3 modified

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} 
  • main/trunk/greenstone3/web/interfaces/oran/transform/layouts/header.xsl

    r25294 r25347  
    391391        </xsl:if> 
    392392    </xsl:template> 
    393      
     393 
     394    <!-- gslib:langfrag should get expanded in ../util.xsl --> 
    394395    <xsl:template name="document-editor-language-fragments"> 
    395         <script type="text/javascript"> 
    396             <xsl:text disable-output-escaping="yes"> 
    397                 gs.text = new Array(); 
    398                 gs.text.dse = new Array(); 
    399                 gs.text.dse.no_docs="</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'dse.no_docs')"/><xsl:text disable-output-escaping="yes">"; 
    400                 gs.text.dse.untitled="</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'dse.untitled')"/><xsl:text disable-output-escaping="yes">"; 
    401                 gs.text.dse.delete_section="</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'dse.delete_section')"/><xsl:text disable-output-escaping="yes">"; 
    402                 gs.text.dse.edit="</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'dse.edit')"/><xsl:text disable-output-escaping="yes">"; 
    403                 gs.text.dse.hide="</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'dse.hide')"/><xsl:text disable-output-escaping="yes">"; 
    404                 gs.text.dse.add_sub_section="</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'dse.add_sub_section')"/><xsl:text disable-output-escaping="yes">"; 
    405                 gs.text.dse.duplicate="</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'dse.duplicate')"/><xsl:text disable-output-escaping="yes">"; 
    406                 gs.text.dse.error_saving="</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'dse.error_saving')"/><xsl:text disable-output-escaping="yes">"; 
    407                 gs.text.dse.save_changes="</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'dse.save_changes')"/><xsl:text disable-output-escaping="yes">"; 
    408                 gs.text.dse.saving="</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'dse.saving')"/><xsl:text disable-output-escaping="yes">"; 
    409                 gs.text.dse.modifying_archives="</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'dse.modifying_archives')"/><xsl:text disable-output-escaping="yes">"; 
    410                 gs.text.dse.empty_collection_list="</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'dse.empty_collection_list')"/><xsl:text disable-output-escaping="yes">"; 
    411                 gs.text.dse.could_not_build_p1="</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'dse.could_not_build_p1')"/><xsl:text disable-output-escaping="yes">"; 
    412                 gs.text.dse.could_not_build_p2="</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'dse.could_not_build_p2')"/><xsl:text disable-output-escaping="yes">"; 
    413                 gs.text.dse.could_not_activate_p1="</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'dse.could_not_activate_p1')"/><xsl:text disable-output-escaping="yes">"; 
    414                 gs.text.dse.could_not_activate_p2="</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'dse.could_not_activate_p2')"/><xsl:text disable-output-escaping="yes">"; 
    415                 gs.text.dse.activating="</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'dse.activating')"/><xsl:text disable-output-escaping="yes">"; 
    416                 gs.text.dse.building="</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'dse.building')"/><xsl:text disable-output-escaping="yes">"; 
    417                 gs.text.dse.could_not_check_status_p1="</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'dse.could_not_check_status_p1')"/><xsl:text disable-output-escaping="yes">"; 
    418                 gs.text.dse.could_not_check_status_p2a="</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'dse.could_not_check_status_p2a')"/><xsl:text disable-output-escaping="yes">"; 
    419                 gs.text.dse.could_not_check_status_p2b="</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'dse.could_not_check_status_p2b')"/><xsl:text disable-output-escaping="yes">"; 
    420                 gs.text.dse.error_saving_changes="</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'dse.error_saving_changes')"/><xsl:text disable-output-escaping="yes">"; 
    421                 gs.text.dse.error_code="</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'dse.error_code')"/><xsl:text disable-output-escaping="yes">"; 
    422                 gs.text.dse.error_reason="</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'dse.error_reason')"/><xsl:text disable-output-escaping="yes">"; 
    423                 gs.text.dse.error_line="</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'dse.error_line')"/><xsl:text disable-output-escaping="yes">"; 
    424                 gs.text.dse.xml_error="</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'dse.xml_error')"/><xsl:text disable-output-escaping="yes">"; 
    425                 gs.text.dse.browse_cannot_validate_xml="</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'dse.browse_cannot_validate_xml')"/><xsl:text disable-output-escaping="yes">"; 
    426                 gs.text.dse.add_new_metadata="</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'dse.add_new_metadata')"/><xsl:text disable-output-escaping="yes">"; 
    427                 gs.text.dse.no_value_given="</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'dse.no_value_given')"/><xsl:text disable-output-escaping="yes">"; 
    428                 gs.text.dse.create_new_document="</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'dse.create_new_document')"/><xsl:text disable-output-escaping="yes">"; 
    429                 gs.text.dse.untitled_section="</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'dse.untitled_section')"/><xsl:text disable-output-escaping="yes">"; 
    430                 gs.text.dse.insert_new_section="</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'dse.insert_new_section')"/><xsl:text disable-output-escaping="yes">"; 
    431             </xsl:text> 
    432         </script> 
     396      <!--<gslib:langfrag name="dse"/>--> 
     397 
     398      <script type="text/javascript"> 
     399      gs.text = new Array(); 
     400      gs.text.dse = new Array(); 
     401      <xsl:value-of disable-output-escaping="yes" select="util:getInterfaceStringsAsJavascript($interface_name, /page/@lang, 'dse', 'gs.text')"/> 
     402      </script> 
    433403    </xsl:template> 
    434404     
  • main/trunk/greenstone3/web/interfaces/oran/transform/util.xsl

    r25280 r25347  
    677677    </a> 
    678678  </xsl:template> 
    679    
     679 
     680  <!-- needs to be name=attrvalue else xsl:param --> 
     681  <!-- call function with the name prefix (e.g. dse) and the file --> 
     682  <xsl:template name="langfrag"> 
     683    <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')"/> 
     687    </script> 
     688  </xsl:template> 
     689 
    680690</xsl:stylesheet>