Ignore:
Timestamp:
2003-12-02T17:18:37+13:00 (20 years ago)
Author:
jmt12
Message:

Extended arguments so they could be given a minimum and maximum range. Then if they are INTEGER type controls, the spinner control generated will honour any range information. Range information is supplied via the perl -xml type mechanism, using the tag form <Range>0,3</Range>

File:
1 edited

Legend:

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

    r5581 r6087  
    99import org.greenstone.gatherer.msm.MSMUtils;
    1010import org.greenstone.gatherer.util.ArrayTools;
     11import org.greenstone.gatherer.util.Codec;
     12import org.greenstone.gatherer.util.StaticStrings;
    1113import org.greenstone.gatherer.util.Utility;
    1214import org.w3c.dom.*;
     
    4850        build_arguments_element = loadArguments("buildcol.pl");
    4951        import_arguments_element = loadArguments("import.pl");
    50                 // And if that too fails, load the default argument templates
     52        // And if that too fails, load the default argument templates
    5153        if(build_arguments_element == null || import_arguments_element == null) {
    5254        Document build_document = Utility.parse("xml/buildcol.xml", true);
     
    6163        ///atherer.println("Loaded BO arguments from scripts.");
    6264        }
    63                 // 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.
     65        // 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.
    6466        Gatherer.config.setArguments(build_arguments_element);
    6567        Gatherer.config.setArguments(import_arguments_element);
     
    248250            }
    249251            }
     252            else if(node_name.equals(StaticStrings.RANGE_ELEMENT)) {
     253            String range_raw = MSMUtils.getValue(node);
     254            int comma_index = -1;
     255            if((comma_index = range_raw.indexOf(StaticStrings.COMMA_CHARACTER)) != -1) {
     256                if(comma_index > 0) {
     257                try {
     258                    String first_number = range_raw.substring(0, comma_index);
     259                    argument.setMinimum(Integer.parseInt(first_number));
     260                    first_number = null;
     261                }
     262                catch(Exception exception) {
     263                }
     264                }
     265               
     266                if(comma_index + 1 < range_raw.length()) {
     267                try {
     268                    String second_number = range_raw.substring(comma_index + 1);
     269                    argument.setMaximum(Integer.parseInt(second_number));
     270                    second_number = null;   
     271                }
     272                catch(Exception exception) {
     273                }
     274                }
     275            }
     276            // Else it wasn't a valid range anyway, so ignore it
     277            range_raw = null;
     278            }
    250279        }
    251280        }
     
    299328            values.add("-" + argument_element.getAttribute(NAME));
    300329            // Now retrieve the value.
    301             String argument_value = MSMUtils.getValue(argument_element);
     330            String argument_value = Codec.transform(MSMUtils.getValue(argument_element), Codec.DOM_TO_TEXT);
    302331            // If there is a value, tokenize it by commas only.
    303332            if(argument_value != null && argument_value.length() > 0) {
     
    319348    Element arguments_element = null;
    320349    // Run the required program.
    321     /** @todo - I never finished implementing this. Have to test that the perl script handles being loaded in this way.
    322         try {
    323         String args[] = new String[3];
    324         args[0] = Gatherer.config.perl_path;
    325         args[1] = filename;
    326         args[2] = "-xml";
    327                 // Create the process.
    328                 Runtime runtime = Runtime.getRuntime();
    329                 Process process = runtime.exec(args);
    330                 //InputStream input_stream = process.getErrorStream();
    331                 InputSource source = new InputSource(new InputStreamReader(process.getErrorStream()));
    332                 DOMParser parser = new DOMParser();
    333                 parser.parse(source);
    334                 Document document = parser.getDocument();
    335                 arguments_element = document.getDocumentElement();
    336                 }
    337                 catch (Exception error) {
    338                 Gatherer.println("Error in BuildOptions.loadArguments(): " + error);
    339                 Gatherer.printStackTrace(error);
    340                 }
    341     */
     350    try {
     351        String args[];
     352        if(Utility.isWindows()) {
     353        args = new String[4];
     354        args[0] = Gatherer.config.perl_path;
     355        args[1] = "-S";
     356        args[2] = Gatherer.config.getScriptPath() + filename;
     357        args[3] = "-xml";
     358        }
     359        else {
     360        args = new String[2];
     361        args[0] = Gatherer.config.getScriptPath() + filename;
     362        args[1] = "-xml";
     363        }
     364        // Create the process.
     365        Runtime runtime = Runtime.getRuntime();
     366        Process process = runtime.exec(args);
     367        //InputStream input_stream = process.getErrorStream();
     368        InputSource source = new InputSource(new InputStreamReader(process.getErrorStream()));
     369        DOMParser parser = new DOMParser();
     370        parser.parse(source);
     371        Document document = parser.getDocument();
     372        arguments_element = document.getDocumentElement();
     373    }
     374    catch (Exception error) {
     375        Gatherer.println("Error in BuildOptions.loadArguments(): " + error);
     376        Gatherer.printStackTrace(error);
     377    }
    342378    return arguments_element;
    343379    }
Note: See TracChangeset for help on using the changeset viewer.