Changeset 7022


Ignore:
Timestamp:
2004-03-12T10:07:13+13:00 (20 years ago)
Author:
kjdon
Message:

now reads in build options in the right language, and doesn't use the ones saved in config.xml unless the language is the same

Location:
trunk/gli/src/org/greenstone/gatherer
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/Configuration.java

    r6655 r7022  
    7676
    7777    static final private String GENERAL_EMAIL_SETTING = "general.email";
     78    /** the lang attribute of the other element */
     79    static final private String LANGUAGE = "lang";
    7880    /** The name of a Name Element. */
    7981    static final private String NAME = "Name";
     
    332334    Element argument_element = null;
    333335    try {
    334                 // Retrieve the other information subtree.
     336        // Retrieve the other information subtree.
    335337        Element document_element = general_config.getDocumentElement();
    336338        Element other_element = (Element) MSMUtils.getNodeFromNamed(document_element, OTHER);
     
    355357    }
    356358    return argument_element;
     359    }
     360
     361    /** Gets the language for the other arguments subtree
     362     @return empty string if no language specified */
     363    public String getArgumentsLanguage() {
     364    Element document_element = general_config.getDocumentElement();
     365    Element other_element = (Element) MSMUtils.getNodeFromNamed(document_element, OTHER);
     366    String lang = other_element.getAttribute(LANGUAGE);
     367    if (lang == null) {
     368        lang = "en";
     369    }
     370    return lang;
    357371    }
    358372
     
    683697        Element document_element = general_config.getDocumentElement();
    684698        Element other_element = (Element) MSMUtils.getNodeFromNamed(document_element, OTHER);
    685                 // Retrieve the name of the information
     699        // Retrieve the name of the information
    686700        Element arguments_name_element = (Element)MSMUtils.getNodeFromNamed(arguments_element, NAME);
    687701        String filename = MSMUtils.getValue(arguments_element);
    688                 // Find any argument information subtree starting with the same name
     702        // Find any argument information subtree starting with the same name
    689703        Element obsolete_arguments_element = getArguments(filename);
    690                 // Create a copy of the arguments_element within our tree (import).
     704        // Create a copy of the arguments_element within our tree (import).
    691705        Element our_arguments_element = (Element) general_config.importNode(arguments_element, true);
    692                 // Now we insert this new node into the tree. If a previous node exists we replace it instead.
     706        // Now we insert this new node into the tree. If a previous node exists we replace it instead.
    693707        if(obsolete_arguments_element == null) {
    694708        other_element.appendChild(our_arguments_element);
     
    710724    }
    711725
     726    /** Sets the language for the other arguments subtree */
     727    public void setArgumentsLanguage(String lang) {
     728    Element document_element = general_config.getDocumentElement();
     729    Element other_element = (Element) MSMUtils.getNodeFromNamed(document_element, OTHER);
     730    other_element.setAttribute(LANGUAGE, lang);
     731    }
     732
     733   
    712734    /** Set the collection configuration. */
    713735    public void setCollectionConfiguration(Document collection_config) {
  • trunk/gli/src/org/greenstone/gatherer/collection/BuildOptions.java

    r6384 r7022  
    4343    /** When constructing a BuildOptions object we first try to retrieve the valid arguments from config.xml. If that fails we then try to parse the arguments noticed when calling import.pl -xml and buildcol.pl -xml. If that also fails, we load the default arguments from the xml template library. */
    4444    public BuildOptions(Element build_values_element, Element import_values_element) {
    45     // Try to retrieve the arguments for import and build.
    46     build_arguments_element = Gatherer.config.getArguments("buildcol.pl");
    47     import_arguments_element = Gatherer.config.getArguments("import.pl");
     45    // first check the saved arguments language
     46    String interface_lang = Gatherer.config.getLanguage();
     47    String args_lang = Gatherer.config.getArgumentsLanguage();
     48    if (interface_lang.equals(args_lang)) {
     49        // Try to retrieve the arguments for import and build.
     50        build_arguments_element = Gatherer.config.getArguments("buildcol.pl");
     51        import_arguments_element = Gatherer.config.getArguments("import.pl");
     52    }
    4853    // If that fails try to reconstruct the arguments
    4954    if(build_arguments_element == null || import_arguments_element == null) {
    50         build_arguments_element = loadArguments("buildcol.pl");
    51         import_arguments_element = loadArguments("import.pl");
     55        boolean used_defaults = false;
     56        build_arguments_element = loadArguments("buildcol.pl", interface_lang);
     57        import_arguments_element = loadArguments("import.pl", interface_lang);
    5258        // And if that too fails, load the default argument templates
    5359        if(build_arguments_element == null || import_arguments_element == null) {
     
    5864        import_arguments_element = import_document.getDocumentElement();
    5965        import_document = null;
     66        used_defaults = true;
    6067        ///atherer.println("Loaded default BO arguments from templates.");
    6168        }
     
    6471        }
    6572        // By now we should definately have the arguments. However the reason we are here is because they are not stored in the config.xml file, to make sure they are stored now.
     73        if (used_defaults) {
     74        Gatherer.config.setArgumentsLanguage("en");
     75        } else {
     76        Gatherer.config.setArgumentsLanguage(interface_lang);
     77        }
    6678        Gatherer.config.setArguments(build_arguments_element);
    6779        Gatherer.config.setArguments(import_arguments_element);
     
    363375    }
    364376
    365     private Element loadArguments(String filename) {
     377    private Element loadArguments(String filename, String lang) {
    366378    Element arguments_element = null;
    367379    // Run the required program.
     
    369381        String args[];
    370382        if(Utility.isWindows()) {
    371         args = new String[4];
     383        args = new String[6];
    372384        args[0] = Gatherer.config.perl_path;
    373385        args[1] = "-S";
    374386        args[2] = Gatherer.config.getScriptPath() + filename;
    375387        args[3] = "-xml";
     388        args[4] = "-language";
     389        args[5] = lang;
    376390        }
    377391        else {
    378         args = new String[2];
     392        args = new String[4];
    379393        args[0] = Gatherer.config.getScriptPath() + filename;
    380394        args[1] = "-xml";
     395        args[2] = "-language";
     396        args[3] = lang;
    381397        }
    382398        // Create the process.
     
    384400        Process process = runtime.exec(args);
    385401        //InputStream input_stream = process.getErrorStream();
    386         InputSource source = new InputSource(new InputStreamReader(process.getErrorStream()));
     402        InputSource source = new InputSource(new InputStreamReader(process.getErrorStream(), "UTF-8"));
    387403        DOMParser parser = new DOMParser();
    388404        parser.parse(source);
Note: See TracChangeset for help on using the changeset viewer.