Changeset 9095


Ignore:
Timestamp:
2005-02-18T12:31:54+13:00 (19 years ago)
Author:
mdewsnip
Message:

GLI applet: collection building is now much happier about being cancelled. By Matthew Whyte.

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

Legend:

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

    r9092 r9095  
    4242import org.greenstone.gatherer.gui.GUIManager;
    4343import org.greenstone.gatherer.util.Utility;
     44import org.greenstone.gatherer.shell.GShell;
    4445
    4546
     
    208209
    209210
    210     static public void download_url_zip(String col_name, String dir)
     211    static public void download_url_zip(String col_name, String dir, GShell source)
    211212    {
    212213    try {
     
    247248        int len;
    248249
    249         while ((len = dl_dbis.read(buf)) >= 0) {
     250        while ((len = dl_dbis.read(buf)) >= 0 && !source.hasSignalledStop()) {
    250251        zip_bfos.write(buf,0,len);
    251252        }
     
    261262
    262263
    263     static public void upload_url_zip(String col_name, String dir)
     264    static public void upload_url_zip(String col_name, String dir, GShell source)
    264265    {
    265266    final String lineEnd = "\r\n";
     
    320321        // read file and write it into form...
    321322        int bytesRead = fileInputStream.read(buffer, 0, bufferSize);
    322        
     323
    323324        while (bytesRead > 0) {
     325        // Check to see if action has been cancelled.
     326        if (source != null && source.hasSignalledStop()) {
     327            break;
     328        }
    324329        dos.write(buffer, 0, bufferSize);
    325330        bytesAvailable = fileInputStream.available();
  • trunk/gli/src/org/greenstone/gatherer/cdm/CollectionDesignManager.java

    r9045 r9095  
    216216        if (formats_changed && Gatherer.c_man.built()) {
    217217        // upload etc/collect.cfg to server to reflect changes
    218         Utility.zipup(Gatherer.getCollectDirectoryPath(), collection_name, Utility.CONFIG_FILE);
    219         GathererApplet.upload_url_zip(collection_name, "etc");
     218        Utility.zipup(Gatherer.getCollectDirectoryPath(), collection_name, Utility.CONFIG_FILE, null);
     219        GathererApplet.upload_url_zip(collection_name, "etc", null);
    220220        }
    221221    }
  • trunk/gli/src/org/greenstone/gatherer/collection/CollectionManager.java

    r9052 r9095  
    10661066        }
    10671067    }
    1068     else if(event.getStatus() == GShell.ERROR || event.getStatus() == GShell.CANCELLED) {
     1068    else if (event.getStatus() == GShell.CANCELLED) {
     1069        JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("CollectionManager.Build_Cancelled"), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
     1070        Gatherer.g_man.repaint();
     1071    }
     1072    else if (event.getStatus() == GShell.ERROR) {
    10691073        DebugStream.println("There was an error in the gshell:"+ event.getMessage());
    10701074        if (event.getType() == GShell.NEW) {
  • trunk/gli/src/org/greenstone/gatherer/shell/GShell.java

    r9049 r9095  
    227227    protected void runRemote(String[] args, BufferedOutputStream bos)
    228228    {
     229    if(hasSignalledStop()) { return; }
     230    int error_count = 0;
     231    StringBuffer error_list = new StringBuffer();
    229232    try {
    230 
     233        if (type == IMPORT) {
     234        String col_name = args[args.length-1];
     235        if (progress!=null) {
     236            progress.messageOnProgressBar("Uploading data to server");
     237        }
     238
     239        String collect_directory_path = Gatherer.getCollectDirectoryPath();
     240       
     241        // zip up import folder
     242        Utility.zipup(collect_directory_path, col_name, "import", this);
     243
     244        if(hasSignalledStop()) { return; }
     245        // upload it to gsdl server
     246        GathererApplet.upload_url_zip(col_name, "import", this);
     247
     248        if(hasSignalledStop()) { return; }
     249        // upload etc folder to server (need collect.cfg and any hfiles)
     250        Utility.zipup(collect_directory_path, col_name, "etc", this);
     251
     252        if(hasSignalledStop()) { return; }
     253        GathererApplet.upload_url_zip(col_name, "etc", this);
     254
     255        String collection_directory_path = Gatherer.c_man.getCollectionDirectoryPath(col_name);
     256        File img_dir = new File(Gatherer.c_man.getCollectionImagesDirectoryPath());
     257        if (img_dir.exists() && img_dir.list().length > 0) {
     258            // upload images/ directory to server
     259            if(hasSignalledStop()) { return; }
     260            Utility.zipup(collect_directory_path, col_name, "images", this);
     261
     262            if(hasSignalledStop()) { return; }
     263            GathererApplet.upload_url_zip(col_name, "images", this);           
     264        }
     265
     266        if(hasSignalledStop()) { return; }
     267        // see if collection specific image needs uploading
     268        CollectionMetaManager cmm
     269            = CollectionDesignManager.collectionmeta_manager;
     270       
     271        CollectionMeta icon_collection_collectionmeta
     272            = cmm.getMetadatum(CollectionConfiguration.COLLECTIONMETADATA_ICONCOLLECTION_STR);
     273        CollectionMeta icon_collection_small_collectionmeta
     274            = cmm.getMetadatum(CollectionConfiguration.COLLECTIONMETADATA_ICONCOLLECTIONSMALL_STR);
     275       
     276        String ics_text = icon_collection_collectionmeta.getValue(CollectionMeta.TEXT);
     277        String icsc_text = icon_collection_small_collectionmeta.getValue(CollectionMeta.TEXT);
     278        if ((ics_text != null) && (ics_text != "")) {
     279            // Stub code for detecting when collectoin image changed
     280            // => need to upload images
     281            // System.err.println("**** ics_text = " + ics_text);
     282        }
     283       
     284        if (progress!=null) {
     285            progress.messageOnProgressBar("");
     286        }
     287        }
     288       
     289        if(hasSignalledStop()) { return; }
    231290        String perl_cmd = args[0];
    232291        int perl_cmd_root = perl_cmd.lastIndexOf(File.separator);
    233        
     292       
    234293        if (perl_cmd_root > 0) {
    235294        String perl_cmd_cut = perl_cmd.substring(perl_cmd_root+1);
    236295        perl_cmd = perl_cmd_cut;
    237296        }
    238 
     297       
    239298        String launch  = Gatherer.cgiBase + "launch";
    240299        launch = launch + "?cmd=" + perl_cmd;
    241 
     300       
    242301        for(int i = 1; i<args.length; i++) {
    243            
     302       
    244303        String arg = args[i];
    245 
     304       
    246305        if (arg.equals("-collectdir") || arg.equals("-importdir")
    247306            || arg.equals("-builddir")) {
     
    250309            continue;
    251310        }
    252        
     311       
    253312        launch += "&";
    254        
     313       
    255314        if(arg.startsWith(StaticStrings.MINUS_CHARACTER)) {
    256315            String name = arg.substring(1);
     
    268327        }
    269328        }
    270 
     329       
    271330        System.err.println("**** launch url = " + launch);
    272331        // fireMessage(type, Dictionary.get("GShell.Command") + ": " + launch, status, null); // ****
    273 
     332       
    274333        URL launch_url = new URL(launch);
    275334        URLConnection launch_connection = launch_url.openConnection();
    276335        InputStream stdis = launch_connection.getInputStream();
    277336        InputStreamReader stdisr = new InputStreamReader(stdis, "UTF-8");
    278    
     337       
    279338        BufferedReader stdbr = new BufferedReader(stdisr);
    280    
    281         StringBuffer error_list = new StringBuffer();
    282         int error_count = 0;
    283 
     339       
    284340        if (type == GShell.NEW) {
    285341        while(true) {
     
    295351            error_count = check_for_error(line,error_list,error_count);
    296352            fireMessage(type, typeAsString(type) + "> " + line, status, bos);
    297         }       
     353        }
     354        System.err.println("Wants to stop (1).");
    298355        }
    299356        stdbr.close();
    300    
     357       
    301358        if (error_count>0) {
    302359        status = ERROR;
     
    305362            fireMessage(type, typeAsString(type) + "> " + error_list, status, null);
    306363        }
     364        }
     365        else if(hasSignalledStop()) {
     366        //User pressed the cancel button.
     367        //Status already set in hasSignalledStop method.
    307368        }
    308369        else {
     
    458519    }
    459520
    460     if (Gatherer.isGsdlRemote) {
    461         if (type == IMPORT) {
    462         if (progress!=null) {
    463             progress.messageOnProgressBar("Uploading data to server");
    464         }
    465 
    466         String collect_directory_path = Gatherer.getCollectDirectoryPath();
    467 
    468         // zip up import folder
    469         Utility.zipup(collect_directory_path, col_name, "import");
    470         // upload it to gsdl server
    471         GathererApplet.upload_url_zip(col_name, "import");
    472 
    473         // upload etc folder to server (need collect.cfg and any hfiles)
    474         Utility.zipup(collect_directory_path, col_name, "etc");
    475         GathererApplet.upload_url_zip(col_name, "etc");
    476 
    477         String collection_directory_path = Gatherer.c_man.getCollectionDirectoryPath(col_name);
    478         File img_dir = new File(Gatherer.c_man.getCollectionImagesDirectoryPath());
    479         if (img_dir.exists() && img_dir.list().length > 0) {
    480             // upload images/ directory to server
    481             Utility.zipup(collect_directory_path, col_name, "images");
    482             GathererApplet.upload_url_zip(col_name, "images");
    483         }
    484 
    485         // see if collection specific image needs uploading
    486         CollectionMetaManager cmm
    487             = CollectionDesignManager.collectionmeta_manager;
    488 
    489         CollectionMeta icon_collection_collectionmeta
    490             = cmm.getMetadatum(CollectionConfiguration.COLLECTIONMETADATA_ICONCOLLECTION_STR);
    491         CollectionMeta icon_collection_small_collectionmeta
    492             = cmm.getMetadatum(CollectionConfiguration.COLLECTIONMETADATA_ICONCOLLECTIONSMALL_STR);
    493 
    494         String ics_text = icon_collection_collectionmeta.getValue(CollectionMeta.TEXT);
    495         String icsc_text = icon_collection_small_collectionmeta.getValue(CollectionMeta.TEXT);
    496         if ((ics_text != null) && (ics_text != "")) {
    497             // Stub code for detecting when collectoin image changed
    498             // => need to upload images
    499             // System.err.println("**** ics_text = " + ics_text);
    500         }
    501 
    502 
    503         if (progress!=null) {
    504             progress.messageOnProgressBar("");
    505         }
    506 
    507         }
    508     }
    509 
    510 
    511521    // Issue a processBegun event
    512522    fireProcessBegun(type, status);
     
    521531        if (type == NEW) {
    522532        if (Gatherer.isGsdlRemote) {
    523             GathererApplet.download_url_zip(col_name,".");
    524             Utility.unzip(Gatherer.getCollectDirectoryPath(), col_name);
     533            GathererApplet.download_url_zip(col_name, ".", this);
     534            if (!hasSignalledStop()) {
     535            Utility.unzip(Gatherer.getCollectDirectoryPath(), col_name);
     536            }
    525537        }
    526538        }
     
    535547
    536548            Utility.delete(Gatherer.c_man.getCollectionArchivesDirectoryPath()); // remove current archives
    537             GathererApplet.download_url_zip(col_name,"archives");
    538             Utility.unzip(Gatherer.getCollectDirectoryPath(), col_name);
    539 
    540             if (progress!=null) {
    541             progress.messageOnProgressBar("");
    542             }
     549            GathererApplet.download_url_zip(col_name, "archives", this);
     550               if (!hasSignalledStop()) {
     551               Utility.unzip(Gatherer.getCollectDirectoryPath(), col_name);
     552               }
     553               if (progress!=null) {
     554               progress.messageOnProgressBar("");
     555               }     
    543556        }
    544557
     
    560573            Utility.delete(buildDir); // remove current build dir
    561574            buildDir.mkdir(); //Make a clean dir
    562             GathererApplet.download_url_zip(col_name,"building/build.cfg"); //Only need build.cfg
    563             Utility.unzip(Gatherer.getCollectDirectoryPath(), col_name);
    564 
     575            GathererApplet.download_url_zip(col_name, "building/build.cfg", this); //Only need build.cfg
     576            if (!hasSignalledStop()) {
     577            Utility.unzip(Gatherer.getCollectDirectoryPath(), col_name);
     578            }
     579           
    565580            if (progress!=null) {
    566581            progress.messageOnProgressBar("");
     
    570585    }
    571586
    572     if(hasSignalledStop()) {
    573         status = CANCELLED;
    574     }
    575587    // We're done.
    576588    fireProcessComplete(type, status);
     
    678690     * @return A <strong>boolean</strong> indicating if the user wanted to stop.
    679691     */
    680     private boolean hasSignalledStop() {
     692    public boolean hasSignalledStop() {
    681693    boolean has_signalled_stop = false;
    682694    if(progress != null) {
    683695        has_signalled_stop = progress.hasSignalledStop();
     696    }
     697    if(has_signalled_stop) {
     698        status = CANCELLED;
    684699    }
    685700    return has_signalled_stop;
  • trunk/gli/src/org/greenstone/gatherer/util/Utility.java

    r9045 r9095  
    4949import org.greenstone.gatherer.DebugStream;
    5050import org.greenstone.gatherer.Dictionary;
     51import org.greenstone.gatherer.shell.GShell;
    5152// Don't even think about adding import org.greenstone.gatherer.Gatherer in here!
    5253// The functions in this class should be independent of the Gatherer class. Put your function somewhere else buster!
     
    601602    }
    602603
    603     static protected void zipFunc (ZipOutputStream zos, String file_path, int prefix_strip)
     604    static protected void zipFunc (ZipOutputStream zos, String file_path, int prefix_strip, GShell source)
    604605    {
    605606    // Using try is required because of file io.
    606607    try {
     608        // Exit if pressed cancel.
     609        if (source != null && source.hasSignalledStop()) {
     610        return;
     611        }
    607612        // Create a Zip Entry and put it into the archive (no data yet).
    608613
     
    624629        // to the zip output stream until the bis has been entirely read.
    625630        while ((byteCount = bis.read(data, 0, 1024)) > -1) {
     631        //Check for cancell
     632        if(source != null) {
     633            if(source.hasSignalledStop()) {
     634            break;
     635            }
     636        }
    626637        zos.write(data, 0, byteCount);
    627638        }
     
    634645    }
    635646
    636     static protected void dirFunc (ZipOutputStream zos, String dir_name, int prefix_strip)
     647    static protected void dirFunc (ZipOutputStream zos, String dir_name, int prefix_strip, GShell source)
    637648    {
    638649    File dirObj = new File(dir_name);
     
    645656        // Loop through File array and display.
    646657        for (int i = 0; i < fileList.length; i++) {
     658            if(source != null) {
     659            if(source.hasSignalledStop()) {
     660                break;
     661            }
     662            }
    647663            File file = fileList[i];
    648664            if (file.isDirectory()) {
     
    661677            }
    662678
    663             dirFunc(zos,dir_path,prefix_strip);
     679            dirFunc(zos,dir_path,prefix_strip, source);
    664680            } else if (file.isFile()) {
    665681            // Call the zipFunc function
    666682            String file_path = fileList[i].getPath();
    667             zipFunc(zos,file_path,prefix_strip);
     683            zipFunc(zos,file_path,prefix_strip, source);
    668684            }
    669685        }
     
    680696
    681697
    682     static public void zipup(String col_dir, String col_name, String dir_or_file)
     698    static public void zipup(String col_dir, String col_name, String dir_or_file, GShell source)
    683699    {
    684700    int prefix_strip = col_dir.length();
     
    695711        if (zip_dof.isDirectory()) {
    696712            String zip_dir = zip_dir_or_file;
    697             dirFunc(zos,zip_dir,prefix_strip);
     713            dirFunc(zos,zip_dir,prefix_strip, source);
    698714        }
    699715        else {
     
    714730            }
    715731            }
    716             zipFunc(zos,zip_full_file,prefix_strip);
     732            zipFunc(zos,zip_full_file,prefix_strip, source);
    717733        }
    718734        }
     
    728744    catch (IOException exception) {
    729745        DebugStream.printStackTrace(exception);
    730     } 
     746    }
    731747    }
    732748   
Note: See TracChangeset for help on using the changeset viewer.