Ignore:
Timestamp:
2005-04-27T11:17:29+12:00 (19 years ago)
Author:
mdewsnip
Message:

Replaced all the nonsense where string arrays were created for running perl scripts with array lists. This removes a lot of duplicated code where the same things were added in different cases, and the silly (and error-prone) "new String[11]"s.

File:
1 edited

Legend:

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

    r9704 r9755  
    278278    cd_title = title_field.getText();
    279279    cd_title = cd_title.trim();
    280     cd_title = cd_title.replaceAll("\"","");
    281     int num_args = num_collections + 9;
    282     boolean has_title = false;
    283     if (!cd_title.equals("")) {
    284         has_title = true;
    285     }
    286     String args[];
    287     int next_arg = 0;
    288     if(Utility.isWindows()) {
    289         args = new String[num_args+2];
    290         args[0] = Configuration.perl_path;
    291         args[1] = "-S";
    292         next_arg = 2;
    293     } else {
    294         args = new String[num_args];
     280    cd_title = cd_title.replaceAll("\"", "");
     281
     282    String export_type = (String) saveas_combobox.getSelectedItem();
     283
     284    // Generate the export.pl command
     285    ArrayList command_parts_list = new ArrayList();
     286    if (Utility.isWindows() && (!Gatherer.isGsdlRemote)) {
     287        command_parts_list.add(Configuration.perl_path);
     288        command_parts_list.add("-S");
     289    }
     290    command_parts_list.add(Configuration.getScriptPath() + "export.pl");
     291    command_parts_list.add("-gli");
     292    command_parts_list.add("-language");
     293    command_parts_list.add(Configuration.getLanguage());
     294    command_parts_list.add("-removeold");
     295    command_parts_list.add("-saveas");
     296    command_parts_list.add(export_type);
     297    command_parts_list.add("-exportdir");
     298    command_parts_list.add(Configuration.gsdl_path + "tmp" + File.separator);
     299
     300    if (cd_title.equals("")) {
     301        command_parts_list.add("exported_" + export_type);
     302    }
     303    else {
     304        command_parts_list.add("exported_" + cd_title.replaceAll("\\s", ""));
    295305    }
    296306   
    297     String export_type = (String)saveas_combobox.getSelectedItem();
    298 
    299     args[next_arg] = Configuration.getScriptPath() + "export.pl";
    300     next_arg++;
    301     args[next_arg] = "-gli"; next_arg++;
    302     args[next_arg] = "-language"; next_arg++;
    303     args[next_arg] = Configuration.getLanguage(); next_arg++;
    304     args[next_arg] = "-removeold"; next_arg++;
    305     args[next_arg] = "-saveas"; next_arg++;
    306     args[next_arg] = export_type; next_arg++;   
    307 
    308     args[next_arg] = "-exportdir"; next_arg++;
    309     args[next_arg] = Configuration.gsdl_path+"tmp"+File.separator;
    310     if(!has_title) {
    311         args[next_arg] += "exported_" + export_type;
    312     } else {
    313         args[next_arg] += "exported_"+cd_title.replaceAll("\\s","");
    314     }
    315     next_arg++;
    316 
    317    
    318     for (int i=0; i<num_collections;i++,next_arg++) {
    319         args[next_arg] = ((BasicCollectionConfiguration)selected_collections.get(i)).getShortName();
     307    for (int i = 0; i < num_collections; i++) {
     308        command_parts_list.add(((BasicCollectionConfiguration) selected_collections.get(i)).getShortName());
    320309    }
    321310
    322311    DebugStream.print("export command = ");
    323     for (int i=0; i<args.length; i++) {
    324         DebugStream.print(args[i]+" ");
    325         System.err.print(args[i]+" ");
     312    for (int i = 0; i < command_parts_list.size(); i++) {
     313        DebugStream.print(command_parts_list.get(i) + " ");
     314        System.err.print(command_parts_list.get(i) + " ");
    326315    }
    327316    DebugStream.println("");
    328317    System.err.println("");
    329318
    330     GShell process = new GShell(args, GShell.EXPORTAS, 3, this, null, GShell.GSHELL_EXPORTAS);
     319    // Run the export.pl command
     320    String[] command_parts = (String[]) command_parts_list.toArray(new String[0]);
     321    GShell process = new GShell(command_parts, GShell.EXPORTAS, 3, this, null, GShell.GSHELL_EXPORTAS);
    331322    process.start();
    332323    //process.run();
Note: See TracChangeset for help on using the changeset viewer.