Changeset 15163

Show
Ignore:
Timestamp:
02.04.2008 18:02:16 (11 years ago)
Author:
ak19
Message:

method run() modified to work properly in those cases where GSDL is remote

Files:
1 modified

Legend:

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

    r15122 r15163  
    273273        String collection_directory_path = CollectionManager.getCollectionDirectoryPath(collection_name); 
    274274        String srcdoc_file_relative_path = RemoteGreenstoneServer.getPathRelativeToDirectory( 
    275            this.srcdoc_files[fileNum], collection_directory_path); 
     275        this.srcdoc_files[fileNum], collection_directory_path); // preserves spaces in filename 
    276276        command_parts_list.add("-file"); 
    277277        command_parts_list.add(srcdoc_file_relative_path); 
     
    348348    { 
    349349        int exit_value = 0; 
     350        String errMsg = ""; 
     351 
     352        // We're going to try replacing all selected documents and then  
     353        // display errormessages 
    350354        // first run the replace process for all src files, and accumulate error exit values (0 means it's fine) 
    351355        for(int i = 0; i < srcdoc_files.length; i++) { 
    352356        int exit_value_this_time =  replaceSrcDoc(i); 
    353         exit_value += exit_value_this_time; // should remain at 0 if this file successfully replaced 
     357        exit_value += exit_value_this_time; // if all files successfully replaced, exit_value will stay at 0 
     358 
     359        // accumulate all error and success msgs to display after processing all the files 
     360        // that are to be replaced 
     361        errMsg += error_message.toString(); 
     362        error_message = null; 
     363 
    354364        if(exit_value_this_time != 0) { 
    355365            failedFiles.add(srcdoc_files[i].getName()); // add this file to list of failures 
     366        } else { 
     367            if (Gatherer.isGsdlRemote) { 
     368            // Delete the local copy of the old source document file on the client side  
     369            // (it's already been replaced on the server side), and download the updated  
     370            // (html) file and any directory containing associated files 
     371            System.err.println("*****ReplaceSrcDocWithHtmlPrompt.java - run() - gsdl remote case"); 
     372            // not sure what the new file is renamed to, so at present still delete entire 
     373            // containing directory and get the updated copy of this directory from remote server 
     374            Utility.delete(srcdoc_files[i]); // remove the local copy of src doc 
     375 
     376            // let's get just the filename without the suffix 
     377            String htmlFile = srcdoc_files[i].getName(); 
     378            int lastperiod = htmlFile.lastIndexOf('.'); 
     379            String suffixlessFilename = htmlFile.substring(0, lastperiod); // cut off suffix 
     380            htmlFile = suffixlessFilename+".html"; // html filename 
     381 
     382            // download the generated html file from the server side to put it  
     383            // into the import directory on the client side 
     384            RemoteGreenstoneServer.downloadCollectionFile( 
     385                          CollectionManager.getLoadedCollectionName(), 
     386                          new File(srcdoc_files[i].getParentFile(), htmlFile)); 
     387             
     388            // download any assoc folder which is srcfilename+"_files" 
     389            File assoc_folder = new File(srcdoc_files[i].getParentFile(), suffixlessFilename+"_files"); 
     390            // If an associated_folder by such a name exists, download it 
     391            if(RemoteGreenstoneServer.exists(CollectionManager.getLoadedCollectionName(), assoc_folder)) { 
     392              RemoteGreenstoneServer.downloadCollectionFile( 
     393                                    CollectionManager.getLoadedCollectionName(), assoc_folder); 
     394            } 
     395            } 
     396            // Whether remote or local case, need to refressh the GLI filemanager system to show 
     397            // what files are in the current collection space 
     398            Gatherer.g_man.refreshCollectionTree(DragTree.COLLECTION_CONTENTS_CHANGED); // refreshes coll's content view 
     399            Gatherer.g_man.wait(false); 
    356400        } 
     401        } // end for loop 
     402         
     403        // Display error messages now that we finished processing the multiple files 
     404        if(exit_value != 0) { 
     405        resultPrompt(false, errMsg); 
     406        } else { 
     407        resultPrompt(true, errMsg); 
    357408        } 
    358  
    359         if (exit_value == 0) { // success on all files 
    360         // Clear out the old source document file and download the updated (collect?) directory 
    361         if (Gatherer.isGsdlRemote) { 
    362             System.err.println("*****ReplaceSrcDocWithHtmlPrompt.java - ReplaceSrcDocWithHtmlTask.run() - gsdl remote case"); 
    363             // not sure what the new file is renamed to, so at present still delete entire 
    364             // containing directory and get the updated copy of this directory from remote server 
    365             Utility.delete(srcdoc_files[0].getParentFile()); // remove the local copy of containing dir 
    366             RemoteGreenstoneServer.downloadCollectionFile( 
    367                  CollectionManager.getLoadedCollectionName(), srcdoc_files[0].getParentFile());  
    368             //downloads the same folder from remote server - which should include  
    369             // the replaced srcdoc file's html and any associated img _files folder 
    370         } 
    371  
    372         // Replace the srcdoc file in the GLI filemanager system with its html equivalent 
    373                 Collection collection = Gatherer.c_man.getCollection(); 
    374         // this works: refreshes content view to what's in the collection 
    375         Gatherer.g_man.refreshCollectionTree(DragTree.COLLECTION_CONTENTS_CHANGED); 
    376         resultPrompt(true, error_message.toString()); 
    377         } else { // failure 
    378         resultPrompt(false, error_message.toString()); 
    379         } 
    380         error_message = null; 
    381         Gatherer.g_man.wait(false); 
    382     } 
    383     }     
     409    } // end run method 
     410 
     411    }    //end Task class 
    384412}