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.

Location:
trunk/gli/src/org/greenstone/gatherer/gui
Files:
4 edited

Legend:

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

    r9677 r9755  
    5353import org.greenstone.gatherer.shell.GShellEvent;
    5454import org.greenstone.gatherer.shell.GShellListener;
    55 import org.greenstone.gatherer.util.ArrayTools;
    5655import org.greenstone.gatherer.util.Utility;
    5756import org.greenstone.gatherer.util.XMLTools;
     
    226225    }
    227226
    228     private int explodeMetadata() {
    229 
    230     String [] args;
     227    private int explodeMetadata()
     228    {
    231229    if (Gatherer.isGsdlRemote) {
    232230        // what here??
    233231        return -1;
    234232    }
    235     if(Utility.isWindows()){
    236         args = new String[5];
    237         args[0] = Configuration.perl_path;
    238         args[1] = "-S";
    239         args[2] = Configuration.getScriptPath() + "explode_metadata_database.pl";
    240         args[3] = "-plugin";
    241         args[4] = plugin_name;
    242     } else {
    243         args = new String[3];
    244         args[0] = Configuration.getScriptPath() + "explode_metadata_database.pl";
    245         args[1] = "-plugin";
    246         args[2] = plugin_name;
    247 
    248     }
    249     // add in all the options from the user
    250     args = ArrayTools.add(args, options.getValues());
    251     // add in the filename
    252     args = ArrayTools.add(args, metadata_file.getPath());
    253 
     233
     234    // Generate the explode_metadata_database.pl command
     235    ArrayList command_parts_list = new ArrayList();
     236    if (Utility.isWindows() && (!Gatherer.isGsdlRemote)) {
     237        command_parts_list.add(Configuration.perl_path);
     238        command_parts_list.add("-S");
     239    }
     240    command_parts_list.add(Configuration.getScriptPath() + "explode_metadata_database.pl");
     241    command_parts_list.add("-plugin");
     242    command_parts_list.add(plugin_name);
     243
     244    // Add in all the options from the user
     245    String[] explode_options = options.getValues();
     246    for (int i = 0; i < explode_options.length; i++) {
     247        command_parts_list.add(explode_options[i]);
     248    }
     249
     250    // Add in the filename
     251    command_parts_list.add(metadata_file.getPath());
     252
     253    // Run the explode_metadata_database.pl command
     254    String[] command_parts = (String[]) command_parts_list.toArray(new String[0]);
    254255    this.error_message = new StringBuffer();
    255     GShell process = new GShell(args, GShell.EXPLODE, 3, this, null, GShell.GSHELL_EXPLODE);
     256    GShell process = new GShell(command_parts, GShell.EXPLODE, 3, this, null, GShell.GSHELL_EXPLODE);
    256257    //process.start();
    257258    process.run();
  • 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();
  • trunk/gli/src/org/greenstone/gatherer/gui/WriteCDImagePrompt.java

    r9249 r9755  
    240240     * @see org.greenstone.gatherer.util.Utility
    241241     */
    242     public void writeCDImageCollections() {
     242    public void writeCDImageCollections()
     243    {
    243244    DebugStream.println("WriteCDImagePrompt.writeCDImageCollections()");
    244245
     
    248249    cd_title = cd_title.trim();
    249250    cd_title = cd_title.replaceAll("\"","");
    250     int num_args = num_collections + 4;
    251     boolean has_title = false;
     251
     252    // Generate the exportcol.pl command
     253    ArrayList command_parts_list = new ArrayList();
     254    if (Utility.isWindows() && (!Gatherer.isGsdlRemote)) {
     255        command_parts_list.add(Configuration.perl_path);
     256        command_parts_list.add("-S");
     257    }
     258    command_parts_list.add(Configuration.getScriptPath() + "exportcol.pl");
     259    command_parts_list.add("-gli");
     260    command_parts_list.add("-language");
     261    command_parts_list.add(Configuration.getLanguage());
     262
    252263    if (!cd_title.equals("")) {
    253         num_args += 2;
    254         has_title = true;
    255     }
    256     String args[];
    257     int next_arg = 0;
    258     if(Utility.isWindows()) {
    259         args = new String[num_args+2];
    260         args[0] = Configuration.perl_path;
    261         args[1] = "-S";
    262         next_arg = 2;
    263     } else {
    264         args = new String[num_args];
    265     }
    266    
    267     args[next_arg] = Configuration.getScriptPath() + "exportcol.pl";
    268     next_arg++;
    269     args[next_arg] = "-gli"; next_arg++;
    270     args[next_arg] = "-language"; next_arg++;
    271     args[next_arg] = Configuration.getLanguage(); next_arg++;
    272 
    273     if (has_title) {
    274         args[next_arg] = "-cdname"; next_arg++;
    275         args[next_arg] = cd_title; next_arg++;
    276     }
    277     for (int i=0; i<num_collections;i++,next_arg++) {
    278         args[next_arg] = ((BasicCollectionConfiguration)selected_collections.get(i)).getShortName();
    279     }
    280    
     264        command_parts_list.add("-cdname");
     265        command_parts_list.add(cd_title);
     266    }
     267
     268    for (int i = 0; i < num_collections; i++) {
     269        command_parts_list.add(((BasicCollectionConfiguration) selected_collections.get(i)).getShortName());
     270    }
     271
    281272    DebugStream.print("export command = ");
    282     for (int i=0; i<args.length; i++) {
    283         DebugStream.print(args[i]+" ");
     273    for (int i = 0; i < command_parts_list.size(); i++) {
     274        DebugStream.print(command_parts_list.get(i) + " ");
    284275    }
    285276    DebugStream.println("");
    286     GShell process = new GShell(args, GShell.CDIMAGE, 3, this, null, GShell.GSHELL_CDIMAGE);
     277
     278    // Run the exportcol.pl command
     279    String[] command_parts = (String[]) command_parts_list.toArray(new String[0]);
     280    GShell process = new GShell(command_parts, GShell.CDIMAGE, 3, this, null, GShell.GSHELL_CDIMAGE);
    287281    process.start();
    288282    //process.run();
  • trunk/gli/src/org/greenstone/gatherer/gui/tree/DragTree.java

    r9464 r9755  
    1616import org.greenstone.gatherer.file.FileNode;
    1717import org.greenstone.gatherer.file.FileSystemModel;
    18 import org.greenstone.gatherer.util.ArrayTools;
    1918import org.greenstone.gatherer.util.DragComponent;
    2019import org.greenstone.gatherer.util.DragGroup;
Note: See TracChangeset for help on using the changeset viewer.