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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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;
Note: See TracChangeset for help on using the changeset viewer.