Changeset 9755


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
Files:
6 edited

Legend:

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

    r9671 r9755  
    6767import org.greenstone.gatherer.shell.GShellListener;
    6868import org.greenstone.gatherer.shell.GShellProgressMonitor;
    69 import org.greenstone.gatherer.util.ArrayTools;
    7069import org.greenstone.gatherer.util.Codec;
    7170import org.greenstone.gatherer.util.StaticStrings;
     
    134133    DebugStream.println("CollectionManager.buildCollection()");
    135134    building = true;
    136     String lang = Configuration.getLanguage();
    137     String collect_dir = getCollectDirectory();
    138 
    139     String args[];
    140     if((Utility.isWindows()) && (!Gatherer.isGsdlRemote)) {
    141         args = new String[8];
    142         args[0] = Configuration.perl_path;
    143         args[1] = "-S";
    144         args[2] = Configuration.getScriptPath() + "buildcol.pl";
    145         args[3] = "-gli";
    146         args[4] = "-language";
    147         args[5] = lang;
    148         args[6] = "-collectdir";
    149         args[7] = collect_dir;
    150     }
    151     else {
    152         args = new String[6];
    153         args[0] = Configuration.getScriptPath() + "buildcol.pl";
    154         args[1] = "-gli";
    155         args[2] = "-language";
    156         args[3] = lang;
    157         args[4] = "-collectdir";
    158         args[5] = collect_dir;
    159     }
    160     args = ArrayTools.add(args, collection.build_options.getValues());
    161     args = ArrayTools.add(args, collection.getName());
    162     GShell shell = new GShell(args, GShell.BUILD, BUILDING, this, build_monitor, GShell.GSHELL_BUILD);
     135
     136    // Generate the buildcol.pl command
     137    ArrayList command_parts_list = new ArrayList();
     138    if ((Utility.isWindows()) && (!Gatherer.isGsdlRemote)) {
     139        command_parts_list.add(Configuration.perl_path);
     140        command_parts_list.add("-S");
     141    }
     142    command_parts_list.add(Configuration.getScriptPath() + "buildcol.pl");
     143    command_parts_list.add("-gli");
     144    command_parts_list.add("-language");
     145    command_parts_list.add(Configuration.getLanguage());
     146    command_parts_list.add("-collectdir");
     147    command_parts_list.add(getCollectDirectory());
     148
     149    String[] build_options = collection.build_options.getValues();
     150    for (int i = 0; i < build_options.length; i++) {
     151        command_parts_list.add(build_options[i]);
     152    }
     153
     154    command_parts_list.add(collection.getName());
     155
     156    // Run the buildcol.pl command
     157    String[] command_parts = (String[]) command_parts_list.toArray(new String[0]);
     158    GShell shell = new GShell(command_parts, GShell.BUILD, BUILDING, this, build_monitor, GShell.GSHELL_BUILD);
    163159    shell.addGShellListener(Gatherer.g_man.create_pane);
    164160    shell.start();
    165161    DebugStream.println("CollectionManager.buildCollection().return");
    166162    }
     163
    167164
    168165    /** Used to determine whether the currently active collection has been built.
     
    229226
    230227    public void convertToGS3Collection() {
    231     // Run the mkcol command.
    232     String command[];
    233     String collect_dir = getCollectDirectory();
    234    
    235     if((Utility.isWindows()) && (!Gatherer.isGsdlRemote)) {
    236         command = new String[6];
    237         command[0] = Configuration.perl_path;
    238         command[1] = "-S";
    239         command[2] = Configuration.getGS3ScriptPath() + "convert_coll_from_gs2.pl";
    240         command[3] = "-collectdir";
    241         command[4] = collect_dir;
    242         command[5] = collection.getName();
    243     } else {
    244         command = new String[4];
    245         command[0] = Configuration.getGS3ScriptPath() + "convert_coll_from_gs2.pl";
    246         command[1] = "-collectdir";
    247         command[2] = collect_dir;
    248         command[3] = collection.getName();
    249     }
    250     DebugStream.println("running command "+command);
    251     GShell process = new GShell(command, GShell.CONVERT, COLLECT, this, null, GShell.GSHELL_CONVERT);
     228    // Generate the convert_coll_from_gs2.pl command
     229    ArrayList command_parts_list = new ArrayList();
     230    if ((Utility.isWindows()) && (!Gatherer.isGsdlRemote)) {
     231        command_parts_list.add(Configuration.perl_path);
     232        command_parts_list.add("-S");
     233    }
     234    command_parts_list.add(Configuration.getGS3ScriptPath() + "convert_coll_from_gs2.pl");
     235    command_parts_list.add("-collectdir");
     236    command_parts_list.add(getCollectDirectory());
     237        command_parts_list.add(collection.getName());
     238
     239    // Run the convert_coll_from_gs2.pl command
     240    String[] command_parts = (String[]) command_parts_list.toArray(new String[0]);
     241    GShell process = new GShell(command_parts, GShell.CONVERT, COLLECT, this, null, GShell.GSHELL_CONVERT);
    252242    process.addGShellListener(this);
    253243    process.run(); // Don't bother threading this... yet
     
    658648    }
    659649
    660     String collect_dir = getCollectDirectory();
    661 
    662     String args[];
    663     String lang = Configuration.getLanguage();
    664     if((Utility.isWindows()) && (!Gatherer.isGsdlRemote)) {
    665         args = new String[8];
    666         args[0] = Configuration.perl_path;
    667         args[1] = "-S";
    668         args[2] = Configuration.getScriptPath() + "import.pl";
    669         args[3] = "-gli";
    670         args[4] = "-language";
    671         args[5] = lang;
    672         args[6] = "-collectdir";
    673         args[7] = collect_dir;
    674     }
    675     else {
    676         args = new String[6];
    677         args[0] = Configuration.getScriptPath() + "import.pl";
    678         args[1] = "-gli";
    679         args[2] = "-language";
    680         args[3] = lang;
    681         args[4] = "-collectdir";
    682         args[5] = collect_dir;
    683     }
    684     collect_dir = null;
    685     args = ArrayTools.add(args, collection.import_options.getValues());
    686     args = ArrayTools.add(args, collection.getName());
    687 
    688     GShell shell = new GShell(args, GShell.IMPORT, BUILDING, this, import_monitor, GShell.GSHELL_IMPORT);
     650    // Generate the import.pl command
     651    ArrayList command_parts_list = new ArrayList();
     652    if ((Utility.isWindows()) && (!Gatherer.isGsdlRemote)) {
     653        command_parts_list.add(Configuration.perl_path);
     654        command_parts_list.add("-S");
     655    }
     656    command_parts_list.add(Configuration.getScriptPath() + "import.pl");
     657    command_parts_list.add("-gli");
     658    command_parts_list.add("-language");
     659    command_parts_list.add(Configuration.getLanguage());
     660    command_parts_list.add("-collectdir");
     661    command_parts_list.add(getCollectDirectory());
     662
     663    String[] import_options = collection.import_options.getValues();
     664    for (int i = 0; i < import_options.length; i++) {
     665        command_parts_list.add(import_options[i]);
     666    }
     667
     668    command_parts_list.add(collection.getName());
     669
     670    // Run the buildcol.pl command
     671    String[] command_parts = (String[]) command_parts_list.toArray(new String[0]);
     672    GShell shell = new GShell(command_parts, GShell.IMPORT, BUILDING, this, import_monitor, GShell.GSHELL_IMPORT);
    689673    shell.addGShellListener(Gatherer.g_man.create_pane);
    690674    shell.start();
     
    922906        description = Codec.transform(description, Codec.TEXT_TO_SHELL_UNIX);
    923907    }
    924     String collect_dir = getCollectDirectory();
    925     // Run the mkcol command.
    926     String command[];
    927     if((Utility.isWindows()) && (!Gatherer.isGsdlRemote)) {
    928         if(description == null || title == null) {
    929         command = new String[8];
    930         command[0] = Configuration.perl_path;
    931         command[1] = "-S";
    932         command[2] = Configuration.getScriptPath() + "mkcol.pl";
    933         command[3] = "-collectdir";
    934         command[4] = collect_dir;
    935         command[5] = "-win31compat";
    936         command[6] = (Gatherer.isGsdlRemote) ? "false" : "true";
    937         command[7] = name;
    938         }
    939         // Users are no longer required to supply an email
    940         else if(email == null) {
    941         command = new String[12];
    942         command[0] = Configuration.perl_path;
    943         command[1] = "-S";
    944         command[2] = Configuration.getScriptPath() + "mkcol.pl";
    945         command[3] = "-collectdir";
    946         command[4] = collect_dir;
    947         command[5] = "-win31compat";
    948         command[6] = (Gatherer.isGsdlRemote) ? "false" : "true";
    949         command[7] = "-title";
    950         command[8] = title;
    951         command[9] = "-about";
    952         command[10] = description;
    953         command[11] = name;
    954         }
    955         else {
    956         command = new String[14];
    957         command[0] = Configuration.perl_path;
    958         command[1] = "-S";
    959         command[2] = Configuration.getScriptPath() + "mkcol.pl";
    960         command[3] = "-collectdir";
    961         command[4] = collect_dir;
    962         command[5] = "-win31compat";
    963         command[6] = (Gatherer.isGsdlRemote) ? "false" : "true";
    964         command[7] = "-title";
    965         command[8] = title;
    966         command[9] = "-creator";
    967         command[10] = email;
    968         command[11] = "-about";
    969         command[12] = description;
    970         command[13] = name;
    971         }
    972     }
    973     else {
    974         if(description == null || title == null) {
    975         command = new String[6];
    976         command[0] = "mkcol.pl";
    977         command[1] = "-collectdir";
    978         command[2] = collect_dir;
    979         command[3] = "-win31compat";
    980         command[4] = (Gatherer.isGsdlRemote) ? "false" : "true";
    981         command[5] = name;
    982         }
    983         else if(email == null) {
    984         command = new String[10];
    985         command[0] = "mkcol.pl";
    986         command[1] = "-collectdir";
    987         command[2] = collect_dir;
    988         command[3] = "-win31compat";
    989         command[4] = (Gatherer.isGsdlRemote) ? "false" : "true";
    990         command[5] = "-title";
    991         command[6] = title;
    992         command[7] = "-about";
    993         command[8] = description;
    994         command[9] = name;
    995         }
    996         else {
    997         command = new String[12];
    998         command[0] = "mkcol.pl";
    999         command[1] = "-collectdir";
    1000         command[2] = collect_dir;
    1001         command[3] = "-win31compat";
    1002         command[4] = (Gatherer.isGsdlRemote) ? "false" : "true";
    1003         command[5] = "-title";
    1004         command[6] = title;
    1005         command[7] = "-creator";
    1006         command[8] = email;
    1007         command[9] = "-about";
    1008         command[10] = description;
    1009         command[11] = name;
    1010         }
    1011     }
    1012     GShell process = new GShell(command, GShell.NEW, COLLECT, this, null, GShell.GSHELL_NEW);
     908
     909    // Generate the mkcol.pl command
     910    ArrayList command_parts_list = new ArrayList();
     911    if (Utility.isWindows() && (!Gatherer.isGsdlRemote)) {
     912        command_parts_list.add(Configuration.perl_path);
     913        command_parts_list.add("-S");
     914    }
     915    command_parts_list.add(Configuration.getScriptPath() + "mkcol.pl");
     916
     917    command_parts_list.add("-collectdir");
     918    command_parts_list.add(getCollectDirectory());
     919    command_parts_list.add("-win31compat");
     920    command_parts_list.add((Gatherer.isGsdlRemote) ? "false" : "true");
     921
     922    if (title != null && !title.equals("")) {
     923        command_parts_list.add("-title");
     924        command_parts_list.add(title);
     925    }
     926    if (email != null && !email.equals("")) {
     927        command_parts_list.add("-creator");
     928        command_parts_list.add(email);
     929    }
     930    if (description != null && !description.equals("")) {
     931        command_parts_list.add("-about");
     932        command_parts_list.add(description);
     933    }
     934
     935    command_parts_list.add(name);
     936
     937    // Run the mkcol.pl command
     938    String[] command_parts = (String[]) command_parts_list.toArray(new String[0]);
     939    GShell process = new GShell(command_parts, GShell.NEW, COLLECT, this, null, GShell.GSHELL_NEW);
    1013940    process.run(); // Don't bother threading this... yet
    1014941    }
     942
    1015943
    1016944    /** Any implementation of GShellListener must include this method to allow the GShell to send messages to listeners. However in this case the CollectionManager is in no way interested in what the messages are, just the import events which have a specific type and are handled elsewhere. Thus we can safely ignore this event.
  • trunk/gli/src/org/greenstone/gatherer/file/FileSystem.java

    r8787 r9755  
    44import org.greenstone.gatherer.DebugStream;
    55import org.greenstone.gatherer.Dictionary;
    6 import org.greenstone.gatherer.util.ArrayTools;
    76import org.greenstone.gatherer.util.Utility;
    87
  • 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.