Changeset 17612 for gli

Show
Ignore:
Timestamp:
24.10.2008 17:45:51 (11 years ago)
Author:
ak19
Message:

Turned class RemoteGreenstoneServer?.java from an all-static class into a regular OOP class. It is now also split into three files (the other two being ActionQueue?.java and RemoteGreenstoneServerAction?.java).

Location:
gli/trunk/src/org/greenstone/gatherer
Files:
2 added
19 modified

Legend:

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

    r17121 r17612  
    8585 
    8686    static private Dimension size = new Dimension(800, 540); 
     87    static public RemoteGreenstoneServer remoteGreenstoneServer = null; 
    8788 
    8889    /** Has the exit flag been set? */ 
     
    299300        // Finally, we're ready to find out the version of the remote Greenstone server  
    300301        if(isGsdlRemote) { 
     302        // instantiate the RemoteGreenstoneServer object first 
     303        remoteGreenstoneServer = new RemoteGreenstoneServer(); 
     304 
    301305        int greenstoneVersion = 2; 
    302306        requestGLIServerURL(); 
    303307        gliserver_url_string = Configuration.gliserver_url.toString(); 
    304308         
    305         greenstoneVersion = RemoteGreenstoneServer.getGreenstoneVersion(); 
     309        greenstoneVersion = remoteGreenstoneServer.getGreenstoneVersion(); 
    306310        // Display the version to make error reports a lot more useful 
    307311        System.err.println("Remote Greenstone server version: " + greenstoneVersion); 
     
    316320            library_url_string = fedora_info.getLibraryURL(); 
    317321        } else { 
    318             library_url_string = RemoteGreenstoneServer.getLibraryURL(Configuration.gliserver_url.toString()); 
     322            library_url_string = remoteGreenstoneServer.getLibraryURL(Configuration.gliserver_url.toString()); 
    319323        } 
    320324        } 
     
    472476    // If using a remote Greenstone we need to download the collection configurations now 
    473477    if (Gatherer.isGsdlRemote) { 
    474         if (RemoteGreenstoneServer.downloadCollectionConfigurations().equals("")) { 
     478        if (remoteGreenstoneServer.downloadCollectionConfigurations().equals("")) { 
    475479        // !! Something went wrong downloading the collection configurations 
    476480        System.err.println("Error: Could not download collection configurations."); 
     
    551555    // If using a remote Greenstone we need to download the collection configurations now 
    552556    if (Gatherer.isGsdlRemote) { 
    553         if (RemoteGreenstoneServer.downloadCollectionConfigurations().equals("")) { 
     557        if (remoteGreenstoneServer.downloadCollectionConfigurations().equals("")) { 
    554558        // !! Something went wrong downloading the collection configurations 
    555559        System.err.println("Error: Could not download collection configurations."); 
     
    616620    // If we're using a remote Greenstone server we need to make sure that all jobs have completed first 
    617621    if (isGsdlRemote) { 
    618         RemoteGreenstoneServer.exit(); 
     622        remoteGreenstoneServer.exit(); 
    619623    } 
    620624 
  • gli/trunk/src/org/greenstone/gatherer/cdm/CollectionConfiguration.java

    r17031 r17612  
    37073707        // If we're using a remote Greenstone server, upload the new 'collectionConfig.xml' file 
    37083708        if (Gatherer.isGsdlRemote) { 
    3709             RemoteGreenstoneServer.uploadCollectionFile (collection_name, collect_cfg_file); 
     3709            Gatherer.remoteGreenstoneServer.uploadCollectionFile (collection_name, collect_cfg_file); 
    37103710        } 
    37113711         
     
    37993799            // If we're using a remote Greenstone server, upload the new collect.cfg file 
    38003800            if (Gatherer.isGsdlRemote) { 
    3801                 RemoteGreenstoneServer.uploadCollectionFile (collection_name, collect_cfg_file); 
     3801                Gatherer.remoteGreenstoneServer.uploadCollectionFile (collection_name, collect_cfg_file); 
    38023802            } 
    38033803        } 
  • gli/trunk/src/org/greenstone/gatherer/cdm/GeneralManager.java

    r17211 r17612  
    344344                // If we're using a remote Greenstone server, upload the image 
    345345                if (Gatherer.isGsdlRemote) { 
    346                 RemoteGreenstoneServer.uploadCollectionFile(CollectionManager.getLoadedCollectionName(), collection_image_file); 
     346                Gatherer.remoteGreenstoneServer.uploadCollectionFile( 
     347                                   CollectionManager.getLoadedCollectionName(), collection_image_file); 
    347348                } 
    348349            } 
  • gli/trunk/src/org/greenstone/gatherer/cdm/MacrosManager.java

    r13591 r17612  
    217217        // Users need to wait until the upload has finished before pressing Preview Collection! 
    218218        if (Gatherer.isGsdlRemote) { 
    219             RemoteGreenstoneServer.uploadCollectionFile(CollectionManager.getLoadedCollectionName(), extra_dm_file); 
     219            Gatherer.remoteGreenstoneServer.uploadCollectionFile(CollectionManager.getLoadedCollectionName(), extra_dm_file); 
    220220        } 
    221221        } 
  • gli/trunk/src/org/greenstone/gatherer/collection/CollectionManager.java

    r17012 r17612  
    379379    // Remove the lock file on the server 
    380380    if (Gatherer.isGsdlRemote) { 
    381         RemoteGreenstoneServer.deleteCollectionFile(collection.getName(), lock_file); 
     381        Gatherer.remoteGreenstoneServer.deleteCollectionFile(collection.getName(), lock_file); 
    382382    } 
    383383 
     
    547547        collection_import_directory.mkdirs(); 
    548548        if (Gatherer.isGsdlRemote) { 
    549             RemoteGreenstoneServer.newCollectionDirectory(name, collection_import_directory); 
     549            Gatherer.remoteGreenstoneServer.newCollectionDirectory(name, collection_import_directory); 
    550550        } 
    551551        } 
     
    581581        if (Gatherer.isGsdlRemote) { 
    582582            String base_collection_name = base_collection_directory.getName(); 
    583             RemoteGreenstoneServer.downloadCollection(base_collection_name); 
     583            Gatherer.remoteGreenstoneServer.downloadCollection(base_collection_name); 
    584584        } 
    585585 
     
    765765    // Delete the collection on the server if we're using a remote Greenstone 
    766766    if (Gatherer.isGsdlRemote) { 
    767         RemoteGreenstoneServer.deleteCollection(collection_name); 
     767        Gatherer.remoteGreenstoneServer.deleteCollection(collection_name); 
    768768    } 
    769769 
     
    10561056        // If we're using a remote Greenstone server, upload the metadata file 
    10571057        if (Gatherer.isGsdlRemote) { 
    1058             RemoteGreenstoneServer.uploadCollectionFile(collection.getName(), metadata_set_file); 
     1058            Gatherer.remoteGreenstoneServer.uploadCollectionFile(collection.getName(), metadata_set_file); 
    10591059        } 
    10601060        } 
     
    11221122    if (Gatherer.isGsdlRemote) { 
    11231123        String collection_name = location.substring(location.lastIndexOf(File.separator) + 1, location.length() - ".col".length()); 
    1124         if (RemoteGreenstoneServer.downloadCollection(collection_name).equals("")) { 
     1124        if (Gatherer.remoteGreenstoneServer.downloadCollection(collection_name).equals("")) { 
    11251125        return; 
    11261126        } 
     
    16181618        // If we're using a remote Greenstone server, delete the metadata file on the server 
    16191619        if (Gatherer.isGsdlRemote) { 
    1620         RemoteGreenstoneServer.deleteCollectionFile(collection.getName(), metadata_set_file); 
     1620        Gatherer.remoteGreenstoneServer.deleteCollectionFile(collection.getName(), metadata_set_file); 
    16211621        } 
    16221622    } 
     
    17501750 
    17511751        if (Gatherer.isGsdlRemote) { 
    1752             RemoteGreenstoneServer.deleteCollectionFile(collection.getName(), new File(getLoadedCollectionIndexDirectoryPath())); 
    1753             RemoteGreenstoneServer.moveCollectionFile(collection.getName(), new File(getLoadedCollectionBuildingDirectoryPath()), new File(getLoadedCollectionIndexDirectoryPath())); 
     1752            Gatherer.remoteGreenstoneServer.deleteCollectionFile( 
     1753                             collection.getName(), new File(getLoadedCollectionIndexDirectoryPath())); 
     1754            Gatherer.remoteGreenstoneServer.moveCollectionFile(collection.getName(),  
     1755                    new File(getLoadedCollectionBuildingDirectoryPath()), new File(getLoadedCollectionIndexDirectoryPath())); 
    17541756        } 
    17551757 
  • gli/trunk/src/org/greenstone/gatherer/collection/ScriptOptions.java

    r16267 r17612  
    225225 
    226226        if (Gatherer.isGsdlRemote) { 
    227         String script_output = RemoteGreenstoneServer.getScriptOptions(filename, ""); 
     227        String script_output = Gatherer.remoteGreenstoneServer.getScriptOptions(filename, ""); 
    228228        document = XMLTools.parseXML(new StringReader(script_output)); 
    229229        } 
  • gli/trunk/src/org/greenstone/gatherer/file/FileManager.java

    r15105 r17612  
    180180                source_files[i] = source_nodes[i].getFile(); 
    181181            } 
    182             RemoteGreenstoneServer.uploadFilesIntoCollection(collection_name, source_files, target_node.getFile()); 
     182            Gatherer.remoteGreenstoneServer.uploadFilesIntoCollection(collection_name, source_files, target_node.getFile()); 
    183183            } 
    184184            else if (type == FileJob.DELETE) { 
    185185            // Deletes: delete each top-level file/directory one at a time 
    186186            for (int i = 0; i < source_nodes.length; i++) { 
    187                 RemoteGreenstoneServer.deleteCollectionFile(collection_name, source_nodes[i].getFile()); 
     187                Gatherer.remoteGreenstoneServer.deleteCollectionFile(collection_name, source_nodes[i].getFile()); 
    188188            } 
    189189            } 
     
    191191            // Moves: move each top-level file/directory one at a time 
    192192            for (int i = 0; i < source_nodes.length; i++) { 
    193                 RemoteGreenstoneServer.moveCollectionFile(collection_name, source_nodes[i].getFile(), target_node.getFile()); 
     193                Gatherer.remoteGreenstoneServer.moveCollectionFile( 
     194                                     collection_name, source_nodes[i].getFile(), target_node.getFile()); 
    194195            } 
    195196            } 
     
    272273        // ... but only if it is inside the collection and we haven't already downloaded it 
    273274        if (file.getAbsolutePath().startsWith(Gatherer.getCollectDirectoryPath()) && file.length() == 0) { 
    274             if (RemoteGreenstoneServer.downloadCollectionFile(CollectionManager.getLoadedCollectionName(), file).equals("")) { 
     275            if (Gatherer.remoteGreenstoneServer.downloadCollectionFile( 
     276                                 CollectionManager.getLoadedCollectionName(), file).equals("")) { 
    275277            // Something has gone wrong downloading the file 
    276278            return; 
     
    347349                folder_file.createNewFile(); 
    348350                if (Gatherer.isGsdlRemote) { 
    349                 RemoteGreenstoneServer.uploadCollectionFile(CollectionManager.getLoadedCollectionName(), folder_file); 
     351                Gatherer.remoteGreenstoneServer.uploadCollectionFile( 
     352                                         CollectionManager.getLoadedCollectionName(), folder_file); 
    350353                } 
    351354            } 
     
    353356                folder_file.mkdirs(); 
    354357                if (Gatherer.isGsdlRemote) { 
    355                 RemoteGreenstoneServer.newCollectionDirectory(CollectionManager.getLoadedCollectionName(), folder_file); 
     358                Gatherer.remoteGreenstoneServer.newCollectionDirectory( 
     359                                         CollectionManager.getLoadedCollectionName(), folder_file); 
    356360                } 
    357361            } 
     
    413417        file_queue.addJob(System.currentTimeMillis(), collection_tree, new FileNode[] { collection_tree_node }, collection_tree, new_collection_tree_node, FileJob.RENAME); 
    414418        if (Gatherer.isGsdlRemote) { 
    415             RemoteGreenstoneServer.moveCollectionFile(CollectionManager.getLoadedCollectionName(), collection_file, new_collection_file); 
     419            Gatherer.remoteGreenstoneServer.moveCollectionFile( 
     420                             CollectionManager.getLoadedCollectionName(), collection_file, new_collection_file); 
    416421        } 
    417422        } 
     
    462467        file_queue.addJob(System.currentTimeMillis(), Gatherer.g_man.gather_pane.workspace_tree, new FileNode[] { source_node }, collection_tree, (FileNode)collection_tree_node.getParent(),  FileJob.COPY_FILE_ONLY); 
    463468        if (Gatherer.isGsdlRemote) { 
    464         RemoteGreenstoneServer.uploadFilesIntoCollection(CollectionManager.getLoadedCollectionName(), new File[] { new_file }, target_directory); 
     469        Gatherer.remoteGreenstoneServer.uploadFilesIntoCollection( 
     470                         CollectionManager.getLoadedCollectionName(), new File[] { new_file }, target_directory); 
    465471        } 
    466472        // do a replace of old file with new file 
  • gli/trunk/src/org/greenstone/gatherer/greenstone/Classifiers.java

    r13594 r17612  
    134134            classinfo_options += "&collection=" + collection_name; 
    135135        } 
    136         classinfo_xml = RemoteGreenstoneServer.getScriptOptions("classinfo.pl", classinfo_options); 
     136        classinfo_xml = Gatherer.remoteGreenstoneServer.getScriptOptions("classinfo.pl", classinfo_options); 
    137137        } 
    138138        else { 
     
    195195            classinfo_options += "&collection=" + collection_name; 
    196196        } 
    197         String classinfo_output = RemoteGreenstoneServer.getScriptOptions("classinfo.pl", classinfo_options); 
     197        String classinfo_output = Gatherer.remoteGreenstoneServer.getScriptOptions("classinfo.pl", classinfo_options); 
    198198        xml = new StringBuffer(classinfo_output); 
    199199        } 
  • gli/trunk/src/org/greenstone/gatherer/greenstone/Plugins.java

    r16295 r17612  
    135135            pluginfo_options += "&collection=" + collection_name; 
    136136        } 
    137         pluginfo_xml = RemoteGreenstoneServer.getScriptOptions("pluginfo.pl", pluginfo_options); 
     137        pluginfo_xml = Gatherer.remoteGreenstoneServer.getScriptOptions("pluginfo.pl", pluginfo_options); 
    138138        } 
    139139        else { 
     
    198198            pluginfo_options += "&collection=" + collection_name; 
    199199        } 
    200         String pluginfo_output = RemoteGreenstoneServer.getScriptOptions("pluginfo.pl", pluginfo_options); 
     200        String pluginfo_output = Gatherer.remoteGreenstoneServer.getScriptOptions("pluginfo.pl", pluginfo_options); 
    201201        xml = new StringBuffer(pluginfo_output); 
    202202        } 
  • gli/trunk/src/org/greenstone/gatherer/greenstone3/ServletConfiguration.java

    r14592 r17612  
    7070 
    7171    if (Gatherer.isGsdlRemote){ 
    72         if (RemoteGreenstoneServer.downloadWebXMLFile().equals("")) { 
     72        if (Gatherer.remoteGreenstoneServer.downloadWebXMLFile().equals("")) { 
    7373        System.err.println("Error: Could not download web.xml."); 
    7474        System.exit(0); 
     
    8989    this.sites = new ArrayList(); 
    9090    if (Gatherer.isGsdlRemote){ 
    91         String sites_on_server = RemoteGreenstoneServer.getSiteNames(); 
     91        String sites_on_server = Gatherer.remoteGreenstoneServer.getSiteNames(); 
    9292        if (sites_on_server.equals("")) { 
    9393        // !! Something went wrong : could not get names of the sites 
  • gli/trunk/src/org/greenstone/gatherer/gui/ExplodeMetadataDatabasePrompt.java

    r13820 r17612  
    274274        String collection_name = CollectionManager.getLoadedCollectionName(); 
    275275        String collection_directory_path = CollectionManager.getCollectionDirectoryPath(collection_name); 
    276         String metadata_file_relative_path = RemoteGreenstoneServer.getPathRelativeToDirectory(metadata_file, collection_directory_path); 
     276        String metadata_file_relative_path = Gatherer.remoteGreenstoneServer.getPathRelativeToDirectory( 
     277                                                          metadata_file, collection_directory_path); 
    277278        command_parts_list.add("-file"); 
    278279        command_parts_list.add(metadata_file_relative_path); 
     
    345346        if (Gatherer.isGsdlRemote) { 
    346347            Utility.delete(metadata_file.getParentFile()); 
    347             RemoteGreenstoneServer.downloadCollectionFile(CollectionManager.getLoadedCollectionName(), metadata_file.getParentFile()); 
     348            Gatherer.remoteGreenstoneServer.downloadCollectionFile( 
     349                             CollectionManager.getLoadedCollectionName(), metadata_file.getParentFile()); 
    348350        } 
    349351 
  • gli/trunk/src/org/greenstone/gatherer/gui/GUIManager.java

    r16884 r17612  
    438438        remote_greenstone_server_progress_panel.setLayout(new BorderLayout()); 
    439439        remote_greenstone_server_progress_panel.add(remote_greenstone_server_progress_label, BorderLayout.WEST); 
    440         remote_greenstone_server_progress_panel.add(RemoteGreenstoneServer.getProgressBar(), BorderLayout.CENTER); 
     440        remote_greenstone_server_progress_panel.add(Gatherer.remoteGreenstoneServer.getProgressBar(), BorderLayout.CENTER); 
    441441        content_pane.add(remote_greenstone_server_progress_panel, BorderLayout.SOUTH); 
    442442        } 
  • gli/trunk/src/org/greenstone/gatherer/gui/NewCollectionDetailsPrompt.java

    r14563 r17612  
    259259    // Remote collections that aren't shared have the user's username prefixed to the collection name 
    260260    if (Gatherer.isGsdlRemote && personal_collection_button.isSelected()) { 
    261         name_buffer = new StringBuffer(RemoteGreenstoneServer.getUsername() + "-" + name_buffer.toString()); 
     261        name_buffer = new StringBuffer(Gatherer.remoteGreenstoneServer.getUsername() + "-" + name_buffer.toString()); 
    262262    } 
    263263 
  • gli/trunk/src/org/greenstone/gatherer/gui/Preferences.java

    r17353 r17612  
    826826        Configuration.save(); 
    827827        if (Gatherer.isGsdlRemote && Gatherer.GS3 && site_changed ){ 
    828         RemoteGreenstoneServer.downloadCollectionConfigurations(); 
     828        Gatherer.remoteGreenstoneServer.downloadCollectionConfigurations(); 
    829829        } 
    830830        // Refresh the GLI to account for the configuration changes 
     
    956956            if (Gatherer.c_man.getCollection()!=null){ 
    957957            File lock_file = new File(Gatherer.c_man.getLoadedCollectionDirectoryPath() + "gli.lck"); 
    958             RemoteGreenstoneServer.deleteCollectionFile(Gatherer.c_man.getLoadedCollectionName(),lock_file); 
     958            Gatherer.remoteGreenstoneServer.deleteCollectionFile(Gatherer.c_man.getLoadedCollectionName(),lock_file); 
    959959            Gatherer.g_man.closeCurrentCollection(); 
    960960            } 
    961961            Configuration.site_name=site; 
    962             RemoteGreenstoneServer.set_remote_greenstone_server_authentication_to_null(); 
    963             RemoteGreenstoneServer.downloadCollectionConfigurations(); 
     962            Gatherer.remoteGreenstoneServer.set_remote_greenstone_server_authentication_to_null(); 
     963            Gatherer.remoteGreenstoneServer.downloadCollectionConfigurations(); 
    964964        } 
    965965        } 
  • gli/trunk/src/org/greenstone/gatherer/gui/ReplaceSrcDocWithHtmlPrompt.java

    r15163 r17612  
    272272        String collection_name = CollectionManager.getLoadedCollectionName(); 
    273273        String collection_directory_path = CollectionManager.getCollectionDirectoryPath(collection_name); 
    274         String srcdoc_file_relative_path = RemoteGreenstoneServer.getPathRelativeToDirectory( 
     274        String srcdoc_file_relative_path = Gatherer.remoteGreenstoneServer.getPathRelativeToDirectory( 
    275275        this.srcdoc_files[fileNum], collection_directory_path); // preserves spaces in filename 
    276276        command_parts_list.add("-file"); 
     
    382382            // download the generated html file from the server side to put it  
    383383            // into the import directory on the client side 
    384             RemoteGreenstoneServer.downloadCollectionFile( 
     384            Gatherer.remoteGreenstoneServer.downloadCollectionFile( 
    385385                          CollectionManager.getLoadedCollectionName(), 
    386386                          new File(srcdoc_files[i].getParentFile(), htmlFile)); 
     
    389389            File assoc_folder = new File(srcdoc_files[i].getParentFile(), suffixlessFilename+"_files"); 
    390390            // If an associated_folder by such a name exists, download it 
    391             if(RemoteGreenstoneServer.exists(CollectionManager.getLoadedCollectionName(), assoc_folder)) { 
    392               RemoteGreenstoneServer.downloadCollectionFile( 
     391            if(Gatherer.remoteGreenstoneServer.exists(CollectionManager.getLoadedCollectionName(), assoc_folder)) { 
     392              Gatherer.remoteGreenstoneServer.downloadCollectionFile( 
    393393                                    CollectionManager.getLoadedCollectionName(), assoc_folder); 
    394394            } 
  • gli/trunk/src/org/greenstone/gatherer/metadata/MetadataXMLFileManager.java

    r13818 r17612  
    368368 
    369369        // Upload the files modified since last time, then reset the list 
    370         RemoteGreenstoneServer.uploadCollectionFiles(CollectionManager.getLoadedCollectionName(), (File[]) modified_metadata_xml_files.toArray(new File[0])); 
     370        Gatherer.remoteGreenstoneServer.uploadCollectionFiles( 
     371                  CollectionManager.getLoadedCollectionName(), (File[]) modified_metadata_xml_files.toArray(new File[0])); 
    371372        modified_metadata_xml_files.clear(); 
    372373    } 
  • gli/trunk/src/org/greenstone/gatherer/metadata/ProfileXMLFile.java

    r13808 r17612  
    110110    // This is inefficient but for simplicity we'll just upload the file every time it is changed 
    111111    if (Gatherer.isGsdlRemote) { 
    112         RemoteGreenstoneServer.uploadCollectionFile(CollectionManager.getLoadedCollectionName(), this); 
     112        Gatherer.remoteGreenstoneServer.uploadCollectionFile(CollectionManager.getLoadedCollectionName(), this); 
    113113    } 
    114114 
  • gli/trunk/src/org/greenstone/gatherer/remote/RemoteGreenstoneServer.java

    r16471 r17612  
    5858public class RemoteGreenstoneServer 
    5959{ 
     60    // A PasswordAuthentication object is created whenever it is required 
     61    static private PasswordAuthentication remote_greenstone_server_authentication = null; 
     62    // static private PasswordAuthentication remote_greenstone_server_authentication = new PasswordAuthentication(System.getProperty("user.name"), new char[] { }); 
     63 
     64    private ActionQueue remote_greenstone_server_action_queue; 
     65    private RemoteGreenstoneServer.ProgressBar progress_bar; 
     66 
     67    public RemoteGreenstoneServer() { 
     68    remote_greenstone_server_action_queue = new ActionQueue(); 
     69    progress_bar = new RemoteGreenstoneServer.ProgressBar(); 
     70    } 
     71 
    6072    // ---------------------------------------------------------------------------------------------------- 
    6173    //   PUBLIC LAYER 
    6274    // ---------------------------------------------------------------------------------------------------- 
    63  
    64  
    65     static public String deleteCollection(String collection_name) 
    66     { 
    67     return performAction(new RemoteGreenstoneServerDeleteCollectionAction(collection_name)); 
    68     } 
    69  
    70  
    71     static public String deleteCollectionFile(String collection_name, File collection_file) 
    72     { 
    73     return performAction(new RemoteGreenstoneServerDeleteCollectionFileAction(collection_name, collection_file)); 
    74     } 
    75  
    76  
    77     static public String downloadCollection(String collection_name) 
    78     { 
    79     return performAction(new RemoteGreenstoneServerDownloadCollectionAction(collection_name)); 
    80     } 
    81  
    82  
    83     static public String downloadCollectionArchives(String collection_name) 
    84     { 
    85     return performAction(new RemoteGreenstoneServerDownloadCollectionArchivesAction(collection_name)); 
    86     } 
    87  
    88  
    89     static public String downloadCollectionConfigurations() 
    90     { 
    91     return performAction(new RemoteGreenstoneServerDownloadCollectionConfigurationsAction()); 
    92     } 
    93  
    94  
    95     static public String downloadCollectionFile(String collection_name, File collection_file) 
    96     { 
    97     return performAction(new RemoteGreenstoneServerDownloadCollectionFileAction(collection_name, collection_file)); 
     75    public String deleteCollection(String collection_name) 
     76    { 
     77    return performAction(new RemoteGreenstoneServerAction.DeleteCollectionAction(collection_name)); 
     78    } 
     79 
     80 
     81    public String deleteCollectionFile(String collection_name, File collection_file) 
     82    { 
     83    return performAction(new RemoteGreenstoneServerAction.DeleteCollectionFileAction(collection_name, collection_file)); 
     84    } 
     85 
     86 
     87    public String downloadCollection(String collection_name) 
     88    { 
     89    return performAction(new RemoteGreenstoneServerAction.DownloadCollectionAction(collection_name)); 
     90    } 
     91 
     92 
     93    public String downloadCollectionArchives(String collection_name) 
     94    { 
     95    return performAction(new RemoteGreenstoneServerAction.DownloadCollectionArchivesAction(collection_name)); 
     96    } 
     97 
     98 
     99    public String downloadCollectionConfigurations() 
     100    { 
     101    return performAction(new RemoteGreenstoneServerAction.DownloadCollectionConfigurationsAction()); 
     102    } 
     103 
     104 
     105    public String downloadCollectionFile(String collection_name, File collection_file) 
     106    { 
     107    return performAction(new RemoteGreenstoneServerAction.DownloadCollectionFileAction(collection_name, collection_file)); 
    98108    } 
    99109     
    100110    // get web.xml from the server -- for a remote gli of GS3 
    101     static public String downloadWebXMLFile() 
    102     { 
    103     return performAction(new RemoteGreenstoneServerDownloadWebXMLFileAction()); 
    104     } 
    105  
    106     static public String getScriptOptions(String script_name, String script_arguments) 
    107     { 
    108     return performAction(new RemoteGreenstoneServerGetScriptOptionsAction(script_name, script_arguments)); 
     111    public String downloadWebXMLFile() 
     112    { 
     113    return performAction(new RemoteGreenstoneServerAction.DownloadWebXMLFileAction()); 
     114    } 
     115 
     116    public String getScriptOptions(String script_name, String script_arguments) 
     117    { 
     118    return performAction(new RemoteGreenstoneServerAction.GetScriptOptionsAction(script_name, script_arguments)); 
    109119    } 
    110120     
    111121    //get all available site names from the server -- for a remote gli of GS3 
    112     static public String getSiteNames() 
    113     { 
    114     return performAction(new RemoteGreenstoneServerGetSiteNamesAction()); 
    115     } 
    116  
    117     static public String moveCollectionFile(String collection_name, File source_collection_file, File target_collection_file) 
    118     { 
    119     return performAction(new RemoteGreenstoneServerMoveCollectionFileAction(collection_name, source_collection_file, target_collection_file)); 
    120     } 
    121  
    122  
    123     static public String newCollectionDirectory(String collection_name, File new_collection_directory) 
    124     { 
    125     return performAction(new RemoteGreenstoneServerNewCollectionDirectoryAction(collection_name, new_collection_directory)); 
    126     } 
    127  
    128  
    129     static public String runScript(String collection_name, String script_name, String script_arguments, GShell shell) 
    130     { 
    131     return performAction(new RemoteGreenstoneServerRunScriptAction(collection_name, script_name, script_arguments, shell)); 
    132     } 
    133  
    134  
    135     static public String uploadCollectionFile(String collection_name, File collection_file) 
    136     { 
    137     return performAction(new RemoteGreenstoneServerUploadCollectionFilesAction(collection_name, new File[] { collection_file })); 
    138     } 
    139  
    140  
    141     static public String uploadCollectionFiles(String collection_name, File[] collection_files) 
    142     { 
    143     return performAction(new RemoteGreenstoneServerUploadCollectionFilesAction(collection_name, collection_files)); 
    144     } 
    145  
    146  
    147     static public String uploadFilesIntoCollection(String collection_name, File[] source_files, File target_collection_directory) 
    148     { 
    149     return performAction(new RemoteGreenstoneServerUploadFilesIntoCollectionAction(collection_name, source_files, target_collection_directory)); 
    150     } 
    151  
    152     static public boolean exists(String collection_name, File collection_file) 
    153     { 
    154     String result = performAction(new RemoteGreenstoneServerExistsAction(collection_name, collection_file)); 
     122    public String getSiteNames() 
     123    { 
     124    return performAction(new RemoteGreenstoneServerAction.GetSiteNamesAction()); 
     125    } 
     126 
     127    public String moveCollectionFile(String collection_name, File source_collection_file, File target_collection_file) 
     128    { 
     129    return performAction(new RemoteGreenstoneServerAction.MoveCollectionFileAction( 
     130                             collection_name, source_collection_file, target_collection_file)); 
     131    } 
     132 
     133 
     134    public String newCollectionDirectory(String collection_name, File new_collection_directory) 
     135    { 
     136    return performAction(new RemoteGreenstoneServerAction.NewCollectionDirectoryAction( 
     137                             collection_name, new_collection_directory)); 
     138    } 
     139 
     140 
     141    public String runScript(String collection_name, String script_name, String script_arguments, GShell shell) 
     142    { 
     143    return performAction(new RemoteGreenstoneServerAction.RunScriptAction( 
     144                             collection_name, script_name, script_arguments, shell)); 
     145    } 
     146 
     147 
     148    public String uploadCollectionFile(String collection_name, File collection_file) 
     149    { 
     150    return performAction(new RemoteGreenstoneServerAction.UploadCollectionFilesAction( 
     151                             collection_name, new File[] { collection_file })); 
     152    } 
     153 
     154 
     155    public String uploadCollectionFiles(String collection_name, File[] collection_files) 
     156    { 
     157    return performAction(new RemoteGreenstoneServerAction.UploadCollectionFilesAction(collection_name, collection_files)); 
     158    } 
     159 
     160 
     161    public String uploadFilesIntoCollection(String collection_name, File[] source_files, File target_collection_directory) 
     162    { 
     163    return performAction(new RemoteGreenstoneServerAction.UploadFilesIntoCollectionAction( 
     164                             collection_name, source_files, target_collection_directory)); 
     165    } 
     166 
     167    public boolean exists(String collection_name, File collection_file) 
     168    { 
     169    String result = performAction(new RemoteGreenstoneServerAction.ExistsAction(collection_name, collection_file)); 
    155170    if(result.indexOf("exists") != -1) { 
    156171        return true; 
     
    162177    } 
    163178 
    164     static public int getGreenstoneVersion() 
     179    public int getGreenstoneVersion() 
    165180    { 
    166181    // returns message "Greenstone version is: <version number of the Greenstone remote server>" 
    167     String result = performAction(new RemoteGreenstoneServerVersionAction()); 
     182    String result = performAction(new RemoteGreenstoneServerAction.VersionAction()); 
    168183    int index = result.indexOf(":");  
    169184    if(index != -1) { 
     
    175190 
    176191    /** For constructing the preview command (the library URL) with */ 
    177     static public String getLibraryURL(String serverHomeURL) 
     192    public String getLibraryURL(String serverHomeURL) 
    178193    { 
    179194    // returns message "Greenstone library URL suffix is: <e.g. /greenstone3/library or /gsdl/cgi-bin/library>" 
    180     String libSuffix = performAction(new RemoteGreenstoneServerLibraryURLSuffixAction()); 
     195    String libSuffix = performAction(new RemoteGreenstoneServerAction.LibraryURLSuffixAction()); 
    181196    int index = libSuffix.indexOf(":");  
    182197    if(index != -1) { 
     
    200215 
    201216 
    202     static public void exit() 
     217    public void exit() 
    203218    { 
    204219    System.err.println("Exiting, number of jobs on queue: " + remote_greenstone_server_action_queue.size()); 
     
    223238 
    224239    /** Returns null if we cannot wait for the action to finish, "" if the action failed, or the action output. */ 
    225     static private String performAction(RemoteGreenstoneServerAction remote_greenstone_server_action) 
     240    private String performAction(RemoteGreenstoneServerAction remote_greenstone_server_action) 
    226241    { 
    227242    // Add the action to the queue 
     
    255270 
    256271 
    257     static private RemoteGreenstoneServerActionQueue remote_greenstone_server_action_queue = new RemoteGreenstoneServerActionQueue(); 
    258  
    259  
    260     static private class RemoteGreenstoneServerActionQueue 
    261     extends Thread 
    262     { 
    263     /** The queue of waiting jobs. */ 
    264     private ArrayList queue = null; 
    265  
    266  
    267     public RemoteGreenstoneServerActionQueue() 
    268     { 
    269         if (Gatherer.isGsdlRemote) { 
    270         queue = new ArrayList(); 
    271         start(); 
    272         } 
    273     } 
    274  
    275  
    276     synchronized public void addAction(RemoteGreenstoneServerAction remote_greenstone_server_action) 
    277     { 
    278         queue.add(remote_greenstone_server_action); 
    279         notifyAll(); 
    280     } 
    281  
    282  
    283     public int size() 
    284     { 
    285         return queue.size(); 
    286     } 
    287  
    288  
    289     public void run() 
    290     { 
    291         boolean exit = false; 
    292         while (true) { 
    293         // If there are jobs on the queue, get the next in line and process it 
    294         if (queue.size() > 0) { 
    295             RemoteGreenstoneServerAction remote_greenstone_server_action = (RemoteGreenstoneServerAction) queue.get(0); 
    296  
    297             try { 
    298             remote_greenstone_server_action.perform(); 
    299              
    300             // No exceptions were thrown, so the action was successful 
    301             remote_greenstone_server_action.processed_successfully = true; 
    302             } 
    303             catch (RemoteGreenstoneServerActionCancelledException exception) { 
    304             remote_greenstone_server_action.processed_successfully = false; 
    305             exit = true; 
    306             }  
    307             catch(java.net.ConnectException exception) { 
    308             if(exception.getMessage().trim().startsWith("Connection refused")) { 
    309                 exit = true; 
    310             } else { 
    311                 DebugStream.printStackTrace(exception); 
    312             } 
    313             JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("RemoteGreenstoneServer.Error", exception.getMessage()), Dictionary.get("RemoteGreenstoneServer.Error_Title"), JOptionPane.ERROR_MESSAGE); 
    314             remote_greenstone_server_action.processed_successfully = false;          
    315             } 
    316             catch (FileNotFoundException exception) { 
    317             // FileNotFoundException happens when there's no GS server at the user-provided 
    318             // url (the address of gliserver.pl is wrong). 
    319             exit = true; 
    320             DebugStream.printStackTrace(exception); 
    321             JOptionPane.showMessageDialog(Gatherer.g_man,  
    322                               Dictionary.get("RemoteGreenstoneServer.Error",  
    323                                      "No gliserver.pl found. " + exception.getMessage()),  
    324                               Dictionary.get("RemoteGreenstoneServer.Error_Title"),  
    325                               JOptionPane.ERROR_MESSAGE); 
    326             remote_greenstone_server_action.processed_successfully = false; 
    327             } 
    328             catch (Exception exception) { 
    329             DebugStream.printStackTrace(exception); 
    330             JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("RemoteGreenstoneServer.Error", exception.getMessage()), Dictionary.get("RemoteGreenstoneServer.Error_Title"), JOptionPane.ERROR_MESSAGE); 
    331             remote_greenstone_server_action.processed_successfully = false; 
    332             } 
    333  
    334             // We're done with this action, for better or worse 
    335             remote_greenstone_server_action.processed = true; 
    336             queue.remove(0); 
    337         } 
    338  
    339         // Otherwise the queue is empty 
    340         else { 
    341             progress_bar.setAction(null); 
    342  
    343             // Wait until we are notify()ed by addAction that there is a new job on the queue 
    344             synchronized (this) { 
    345             try { 
    346                 wait(); 
    347             } 
    348             catch (InterruptedException exception) { } 
    349             } 
    350         } 
    351          
    352         // stop the gazillion annoying error messages when the connection was simply 
    353         // refused or when the user pressed Cancel in the opening dialog, by exitting 
    354         // cleanly in one go. 
    355         if(exit == true) { 
    356             Gatherer.exit(); 
    357         } 
    358         } 
    359     } 
    360     } 
    361  
    362  
    363272    // ---------------------------------------------------------------------------------------------------- 
    364273    //   PROGRESS BAR 
    365274    // ---------------------------------------------------------------------------------------------------- 
    366275 
    367  
    368     static private RemoteGreenstoneServerProgressBar progress_bar = new RemoteGreenstoneServerProgressBar(); 
    369  
    370  
    371     static private class RemoteGreenstoneServerProgressBar 
     276    static class ProgressBar 
    372277    extends JProgressBar 
    373278    { 
    374     public RemoteGreenstoneServerProgressBar() 
     279    public ProgressBar() 
    375280    { 
    376281        setBackground(Configuration.getColor("coloring.collection_tree_background", false)); 
     
    404309    } 
    405310    } 
    406  
    407  
    408     static public RemoteGreenstoneServerProgressBar getProgressBar() 
     311     
     312    public RemoteGreenstoneServer.ProgressBar getProgressBar() 
    409313    { 
    410314    return progress_bar; 
     
    413317 
    414318    // ---------------------------------------------------------------------------------------------------- 
    415     //   ACTIONS 
    416     // ---------------------------------------------------------------------------------------------------- 
    417  
    418  
    419     static private abstract class RemoteGreenstoneServerAction 
    420     { 
    421     public String action_output = null; 
    422     public boolean processed = false; 
    423     public boolean processed_successfully; 
    424  
    425     abstract public void perform() 
    426         throws Exception; 
    427     } 
    428  
    429  
    430     static private class RemoteGreenstoneServerActionCancelledException 
    431     extends Exception 
    432     { 
    433     } 
    434  
    435  
    436     /** 
    437      * -------------------------------------------------------------------------------------------- 
    438      *    DELETE COLLECTION 
    439      * -------------------------------------------------------------------------------------------- 
    440      */ 
    441     static private class RemoteGreenstoneServerDeleteCollectionAction 
    442     extends RemoteGreenstoneServerAction 
    443     { 
    444     private String collection_name; 
    445  
    446     public RemoteGreenstoneServerDeleteCollectionAction(String collection_name) 
    447     { 
    448         this.collection_name = collection_name; 
    449     } 
    450  
    451     public void perform() 
    452         throws Exception 
    453     { 
    454         progress_bar.setAction("Deleting collection " + collection_name + "..."); 
    455  
    456         String delete_collection_command = "cmd=delete-collection"; 
    457         delete_collection_command += "&c=" + URLEncoder.encode(collection_name, "UTF-8"); 
    458         action_output = sendCommandToServer(delete_collection_command, null); 
    459     } 
    460     } 
    461  
    462  
    463     /** 
    464      * -------------------------------------------------------------------------------------------- 
    465      *    DELETE COLLECTION FILE 
    466      * -------------------------------------------------------------------------------------------- 
    467      */ 
    468     static private class RemoteGreenstoneServerDeleteCollectionFileAction 
    469     extends RemoteGreenstoneServerAction 
    470     { 
    471     private String collection_name; 
    472     private File collection_file; 
    473  
    474     public RemoteGreenstoneServerDeleteCollectionFileAction(String collection_name, File collection_file) 
    475     { 
    476         this.collection_name = collection_name; 
    477         this.collection_file = collection_file; 
    478     } 
    479  
    480     public void perform() 
    481         throws Exception 
    482     { 
    483         String collection_directory_path = CollectionManager.getCollectionDirectoryPath(collection_name); 
    484         String collection_file_relative_path = getPathRelativeToDirectory(collection_file, collection_directory_path); 
    485         collection_file_relative_path = collection_file_relative_path.replaceAll((Utility.isWindows() ? "\\\\" : "\\/"), "|"); 
    486         progress_bar.setAction("Deleting collection file " + collection_file_relative_path + "..."); 
    487  
    488         String delete_collection_file_command = "cmd=delete-collection-file"; 
    489         delete_collection_file_command += "&c=" + URLEncoder.encode(collection_name, "UTF-8"); 
    490         delete_collection_file_command += "&file=" + URLEncoder.encode(collection_file_relative_path, "UTF-8"); 
    491         action_output = sendCommandToServer(delete_collection_file_command, null); 
    492     } 
    493     } 
    494  
    495  
    496     /** 
    497      * -------------------------------------------------------------------------------------------- 
    498      *    DOWNLOAD COLLECTION 
    499      * -------------------------------------------------------------------------------------------- 
    500      */ 
    501     static private class RemoteGreenstoneServerDownloadCollectionAction 
    502     extends RemoteGreenstoneServerAction 
    503     { 
    504     private String collection_name; 
    505  
    506     public RemoteGreenstoneServerDownloadCollectionAction(String collection_name) 
    507     { 
    508         this.collection_name = collection_name; 
    509     } 
    510  
    511     public void perform() 
    512         throws Exception 
    513     { 
    514         progress_bar.setAction("Downloading remote collection " + collection_name + "..."); 
    515  
    516         String download_collection_command = "cmd=download-collection"; 
    517         download_collection_command += "&c=" + URLEncoder.encode(collection_name, "UTF-8"); 
    518         String zip_file_path = Gatherer.getCollectDirectoryPath() + collection_name + ".zip"; 
    519         action_output = downloadFile(download_collection_command, zip_file_path); 
    520  
    521         // Delete the existing (local) collection directory 
    522         Utility.delete(new File(CollectionManager.getCollectionDirectoryPath(collection_name))); 
    523  
    524         // Unzip the collection just downloaded 
    525         UnzipTools.unzipFile(zip_file_path, Gatherer.getCollectDirectoryPath()); 
    526     } 
    527     } 
    528  
    529  
    530     /** 
    531      * -------------------------------------------------------------------------------------------- 
    532      *    DOWNLOAD COLLECTION ARCHIVES 
    533      * -------------------------------------------------------------------------------------------- 
    534      */ 
    535     static private class RemoteGreenstoneServerDownloadCollectionArchivesAction 
    536     extends RemoteGreenstoneServerAction 
    537     { 
    538     private String collection_name; 
    539  
    540     public RemoteGreenstoneServerDownloadCollectionArchivesAction(String collection_name) 
    541     { 
    542         this.collection_name = collection_name; 
    543     } 
    544  
    545     public void perform() 
    546         throws Exception 
    547     { 
    548         progress_bar.setAction("Downloading collection archives for " + collection_name + "..."); 
    549  
    550         String download_collection_archives_command = "cmd=download-collection-archives"; 
    551         download_collection_archives_command += "&c=" + URLEncoder.encode(collection_name, "UTF-8"); 
    552         String zip_file_path = Gatherer.getCollectDirectoryPath() + collection_name + "-archives.zip"; 
    553         action_output = downloadFile(download_collection_archives_command, zip_file_path); 
    554  
    555         // Delete the existing (local) collection archives 
    556         Utility.delete(new File(CollectionManager.getLoadedCollectionArchivesDirectoryPath())); 
    557  
    558         // Unzip the collection archives just downloaded 
    559         UnzipTools.unzipFile(zip_file_path, Gatherer.getCollectDirectoryPath()); 
    560     } 
    561     } 
    562  
    563  
    564     /** 
    565      * -------------------------------------------------------------------------------------------- 
    566      *    DOWNLOAD COLLECTION CONFIGURATIONS 
    567      * -------------------------------------------------------------------------------------------- 
    568      */ 
    569     static private class RemoteGreenstoneServerDownloadCollectionConfigurationsAction 
    570     extends RemoteGreenstoneServerAction 
    571     { 
    572     public RemoteGreenstoneServerDownloadCollectionConfigurationsAction() 
    573     { 
    574     } 
    575  
    576     public void perform() 
    577         throws Exception 
    578     { 
    579         progress_bar.setAction("Downloading collection configurations..."); 
    580  
    581         // Delete the existing (local) collect directory 
    582         Utility.delete(new File(Gatherer.getCollectDirectoryPath())); 
    583         new File(Gatherer.getCollectDirectoryPath()).mkdirs(); 
    584  
    585         String download_collection_configurations_command = "cmd=download-collection-configurations"; 
    586         String zip_file_path = Gatherer.getCollectDirectoryPath() + "collections.zip"; 
    587         action_output = downloadFile(download_collection_configurations_command, zip_file_path); 
    588  
    589         // Unzip the collection configurations just downloaded 
    590         UnzipTools.unzipFile(zip_file_path, Gatherer.getCollectDirectoryPath()); 
    591     } 
    592     } 
    593  
    594      /** 
    595      * -------------------------------------------------------------------------------------------- 
    596      *    DISCOVERING WHAT VERSION THE REMOTE GREENSTONE SERVER IS (2 or 3) 
    597      * -------------------------------------------------------------------------------------------- 
    598      */ 
    599  
    600     static private class RemoteGreenstoneServerVersionAction 
    601     extends RemoteGreenstoneServerAction 
    602     { 
    603     public void perform() 
    604         throws Exception 
    605     { 
    606         action_output = sendCommandToServer("cmd=greenstone-server-version", null); 
    607     }    
    608     } 
    609  
    610     static private class RemoteGreenstoneServerLibraryURLSuffixAction 
    611     extends RemoteGreenstoneServerAction 
    612     { 
    613     public void perform() 
    614         throws Exception 
    615     { 
    616         action_output = sendCommandToServer("cmd=get-library-url-suffix", null); 
    617     }    
    618     } 
    619      
    620     /** 
    621      * -------------------------------------------------------------------------------------------- 
    622      *    CHECKING IF A FILE/FOLDER EXISTS ON SERVER SIDE 
    623      * -------------------------------------------------------------------------------------------- 
    624      */ 
    625     static private class RemoteGreenstoneServerExistsAction  
    626     extends RemoteGreenstoneServerAction 
    627     { 
    628     private String collection_name; 
    629     private File collection_file; 
    630      
    631     public RemoteGreenstoneServerExistsAction(String collection_name, File collection_file) 
    632     { 
    633         this.collection_name = collection_name; 
    634         this.collection_file = collection_file; 
    635     } 
    636      
    637     public void perform() 
    638         throws Exception 
    639     { 
    640         String collection_directory_path = CollectionManager.getCollectionDirectoryPath(collection_name); 
    641         String collection_file_relative_path = getPathRelativeToDirectory(collection_file, collection_directory_path); 
    642         collection_file_relative_path = collection_file_relative_path.replaceAll((Utility.isWindows() ? "\\\\" : "\\/"), "|"); 
    643         File file = new File(collection_directory_path, collection_file_relative_path); 
    644  
    645         String file_exists_command = "cmd=file-exists"; 
    646         file_exists_command += "&c=" + URLEncoder.encode(collection_name, "UTF-8"); 
    647         file_exists_command += "&file=" + URLEncoder.encode(collection_file_relative_path, "UTF-8"); 
    648         // returns either "File <filename> exists" or "File <filename> does not exist" 
    649         // for the file/folder collection_file 
    650         action_output = sendCommandToServer(file_exists_command, null); 
    651     }    
    652     } 
    653      
    654  
    655     /** 
    656      * -------------------------------------------------------------------------------------------- 
    657      *    DOWNLOAD COLLECTION FILE 
    658      * -------------------------------------------------------------------------------------------- 
    659      */ 
    660     static private class RemoteGreenstoneServerDownloadCollectionFileAction 
    661     extends RemoteGreenstoneServerAction 
    662     { 
    663     private String collection_name; 
    664     private File collection_file; 
    665  
    666     public RemoteGreenstoneServerDownloadCollectionFileAction(String collection_name, File collection_file) 
    667     { 
    668         this.collection_name = collection_name; 
    669         this.collection_file = collection_file; 
    670     } 
    671  
    672     public void perform() 
    673         throws Exception 
    674     { 
    675         String collection_directory_path = CollectionManager.getCollectionDirectoryPath(collection_name); 
    676         String collection_file_relative_path = getPathRelativeToDirectory(collection_file, collection_directory_path); 
    677         collection_file_relative_path = collection_file_relative_path.replaceAll((Utility.isWindows() ? "\\\\" : "\\/"), "|"); 
    678         progress_bar.setAction("Downloading collection file " + collection_file_relative_path + "..."); 
    679  
    680         String download_collection_file_command = "cmd=download-collection-file"; 
    681         download_collection_file_command += "&c=" + URLEncoder.encode(collection_name, "UTF-8"); 
    682         download_collection_file_command += "&file=" + URLEncoder.encode(collection_file_relative_path, "UTF-8"); 
    683         String zip_file_name = collection_name + "-" + collection_file.getName() + ".zip"; 
    684         String zip_file_path = collection_directory_path + zip_file_name; 
    685         action_output = downloadFile(download_collection_file_command, zip_file_path); 
    686  
    687         // Unzip the collection file just downloaded 
    688         UnzipTools.unzipFile(zip_file_path, collection_directory_path); 
    689     } 
    690     } 
    691  
    692     /** 
    693      * -------------------------------------------------------------------------------------------- 
    694      *    DOWNLOAD web.xml FILE --for a remote GS3 
    695      * -------------------------------------------------------------------------------------------- 
    696      */ 
    697     static private class RemoteGreenstoneServerDownloadWebXMLFileAction 
    698     extends RemoteGreenstoneServerAction 
    699     { 
    700     public RemoteGreenstoneServerDownloadWebXMLFileAction() 
    701     {} 
    702  
    703     public void perform() 
    704         throws Exception 
    705     { 
    706         String web_xml_directory_path=(Configuration.gli_user_directory_path); 
    707         String download_web_xml_file_command = "cmd=download-web-xml-file"; 
    708         download_web_xml_file_command += "&file=" + URLEncoder.encode("web.xml", "UTF-8"); 
    709         String zip_file_name = "web-xml.zip"; 
    710         String zip_file_path = web_xml_directory_path + zip_file_name; 
    711         action_output = downloadFile(download_web_xml_file_command, zip_file_path); 
    712  
    713         // Unzip the web.xml file just downloaded 
    714         UnzipTools.unzipFile(zip_file_path,web_xml_directory_path); 
    715     } 
    716     } 
    717  
    718     /** 
    719      * -------------------------------------------------------------------------------------------- 
    720      *    GET SCRIPT OPTIONS 
    721      * -------------------------------------------------------------------------------------------- 
    722      */ 
    723     static private class RemoteGreenstoneServerGetScriptOptionsAction 
    724     extends RemoteGreenstoneServerAction 
    725     { 
    726     private String script_name; 
    727     private String script_arguments; 
    728  
    729     public RemoteGreenstoneServerGetScriptOptionsAction(String script_name, String script_arguments) 
    730     { 
    731         this.script_name = script_name; 
    732         this.script_arguments = script_arguments; 
    733     } 
    734  
    735     public void perform() 
    736         throws Exception 
    737     { 
    738         progress_bar.setAction("Getting options for " + script_name + "..."); 
    739  
    740         String get_script_options_command = "cmd=get-script-options"; 
    741         get_script_options_command += "&script=" + script_name; 
    742         get_script_options_command += "&xml="; 
    743         get_script_options_command += "&language=" + Configuration.getLanguage(); 
    744         get_script_options_command += script_arguments; 
    745         action_output = sendCommandToServer(get_script_options_command, null); 
    746     } 
    747     } 
    748  
    749     /** 
    750      * -------------------------------------------------------------------------------------------- 
    751      *    GET ALL NAMES OF SITES // for a remote GS3  
    752      * -------------------------------------------------------------------------------------------- 
    753      */ 
    754     static private class RemoteGreenstoneServerGetSiteNamesAction 
    755     extends RemoteGreenstoneServerAction 
    756     { 
    757     public RemoteGreenstoneServerGetSiteNamesAction() 
    758     {} 
    759  
    760     public void perform() 
    761         throws Exception 
    762     { 
    763         progress_bar.setAction("Getting names of sites ..."); 
    764  
    765         String get_script_options_command = "cmd=get-site-names"; 
    766         action_output = sendCommandToServer(get_script_options_command, null); 
    767     } 
    768     } 
    769  
    770     /** 
    771      * -------------------------------------------------------------------------------------------- 
    772      *    MOVE COLLECTION FILE 
    773      * -------------------------------------------------------------------------------------------- 
    774      */ 
    775     static private class RemoteGreenstoneServerMoveCollectionFileAction 
    776     extends RemoteGreenstoneServerAction 
    777     { 
    778     private String collection_name; 
    779     private File source_collection_file; 
    780     private File target_collection_file; 
    781  
    782     public RemoteGreenstoneServerMoveCollectionFileAction(String collection_name, File source_collection_file, File target_collection_file) 
    783     { 
    784         this.collection_name = collection_name; 
    785         this.source_collection_file = source_collection_file; 
    786         this.target_collection_file = target_collection_file; 
    787     } 
    788  
    789     public void perform() 
    790         throws Exception 
    791     { 
    792         String collection_directory_path = CollectionManager.getCollectionDirectoryPath(collection_name); 
    793         String source_collection_file_relative_path = getPathRelativeToDirectory(source_collection_file, collection_directory_path); 
    794         source_collection_file_relative_path = source_collection_file_relative_path.replaceAll((Utility.isWindows() ? "\\\\" : "\\/"), "|"); 
    795         String target_collection_file_relative_path = getPathRelativeToDirectory(target_collection_file, collection_directory_path); 
    796         target_collection_file_relative_path = target_collection_file_relative_path.replaceAll((Utility.isWindows() ? "\\\\" : "\\/"), "|"); 
    797         progress_bar.setAction("Moving file " + source_collection_file_relative_path + " -> " + target_collection_file_relative_path + "..."); 
    798  
    799         String move_collection_file_command = "cmd=move-collection-file"; 
    800         move_collection_file_command += "&c=" + URLEncoder.encode(collection_name, "UTF-8"); 
    801         move_collection_file_command += "&source=" + URLEncoder.encode(source_collection_file_relative_path, "UTF-8"); 
    802         move_collection_file_command += "&target=" + URLEncoder.encode(target_collection_file_relative_path, "UTF-8"); 
    803         action_output = sendCommandToServer(move_collection_file_command, null); 
    804     } 
    805     } 
    806  
    807  
    808     /** 
    809      * -------------------------------------------------------------------------------------------- 
    810      *    NEW COLLECTION DIRECTORY 
    811      * -------------------------------------------------------------------------------------------- 
    812      */ 
    813     static private class RemoteGreenstoneServerNewCollectionDirectoryAction 
    814     extends RemoteGreenstoneServerAction 
    815     { 
    816     private String collection_name; 
    817     private File new_collection_directory; 
    818  
    819     public RemoteGreenstoneServerNewCollectionDirectoryAction(String collection_name, File new_collection_directory) 
    820     { 
    821         this.collection_name = collection_name; 
    822         this.new_collection_directory = new_collection_directory; 
    823     } 
    824  
    825     public void perform() 
    826         throws Exception 
    827     { 
    828         String collection_directory_path = CollectionManager.getCollectionDirectoryPath(collection_name); 
    829         String new_collection_directory_relative_path = getPathRelativeToDirectory(new_collection_directory, collection_directory_path); 
    830         new_collection_directory_relative_path = new_collection_directory_relative_path.replaceAll((Utility.isWindows() ? "\\\\" : "\\/"), "|"); 
    831         progress_bar.setAction("Creating new directory " + new_collection_directory_relative_path + "..."); 
    832  
    833         String new_collection_directory_command = "cmd=new-collection-directory"; 
    834         new_collection_directory_command += "&c=" + URLEncoder.encode(collection_name, "UTF-8"); 
    835         new_collection_directory_command += "&directory=" + URLEncoder.encode(new_collection_directory_relative_path, "UTF-8"); 
    836         action_output = sendCommandToServer(new_collection_directory_command, null); 
    837     } 
    838     } 
    839  
    840  
    841     /** 
    842      * -------------------------------------------------------------------------------------------- 
    843      *    RUN SCRIPT 
    844      * -------------------------------------------------------------------------------------------- 
    845      */ 
    846     static private class RemoteGreenstoneServerRunScriptAction 
    847     extends RemoteGreenstoneServerAction 
    848     { 
    849     private String collection_name; 
    850     private String script_name; 
    851     private String script_arguments; 
    852     private GShell shell; 
    853  
    854     public RemoteGreenstoneServerRunScriptAction(String collection_name, String script_name, String script_arguments, GShell shell) 
    855     { 
    856         this.collection_name = collection_name; 
    857         this.script_name = script_name; 
    858         this.script_arguments = script_arguments; 
    859         this.shell = shell; 
    860     } 
    861  
    862     public void perform() 
    863         throws Exception 
    864     { 
    865         progress_bar.setAction("Running " + script_name + "..."); 
    866  
    867         String run_script_command = "cmd=run-script"; 
    868         run_script_command += "&c=" + URLEncoder.encode(collection_name, "UTF-8"); 
    869         run_script_command += "&script=" + script_name; 
    870         run_script_command += "&language=" + Configuration.getLanguage(); 
    871         run_script_command += script_arguments; 
    872         action_output = sendCommandToServer(run_script_command, shell); 
    873     } 
    874     } 
    875  
    876  
    877     /** 
    878      * -------------------------------------------------------------------------------------------- 
    879      *    UPLOAD COLLECTION FILE 
    880      * -------------------------------------------------------------------------------------------- 
    881      */ 
    882     static private class RemoteGreenstoneServerUploadCollectionFilesAction 
    883     extends RemoteGreenstoneServerAction 
    884     { 
    885     private String collection_name; 
    886     private File[] collection_files; 
    887  
    888  
    889     public RemoteGreenstoneServerUploadCollectionFilesAction(String collection_name, File[] collection_files) 
    890     { 
    891         this.collection_name = collection_name; 
    892         this.collection_files = collection_files; 
    893     } 
    894  
    895  
    896     public void perform() 
    897         throws Exception 
    898     { 
    899         progress_bar.setAction("Uploading collection files..."); 
    900  
    901         // Determine the file paths relative to the collection directory 
    902         String collection_directory_path = CollectionManager.getCollectionDirectoryPath(collection_name); 
    903         String[] collection_file_relative_paths = new String[collection_files.length]; 
    904         for (int i = 0; i < collection_files.length; i++) { 
    905         collection_file_relative_paths[i] = getPathRelativeToDirectory(collection_files[i], collection_directory_path); 
    906         } 
    907  
    908         // Zip up the files to send to the server 
    909         String zip_file_name = collection_name + "-" + System.currentTimeMillis() + ".zip"; 
    910         String zip_file_path = collection_directory_path + zip_file_name; 
    911         ZipTools.zipFiles(zip_file_path, collection_directory_path, collection_file_relative_paths); 
    912          
    913         // Upload the zip file 
    914         String upload_collection_file_command = "cmd=upload-collection-file"; 
    915         upload_collection_file_command += "&c=" + URLEncoder.encode(collection_name, "UTF-8"); 
    916         upload_collection_file_command += "&file=" + URLEncoder.encode(zip_file_name, "UTF-8"); 
    917         upload_collection_file_command += "&directory="; 
    918         upload_collection_file_command += "&zip=true"; 
    919         action_output = uploadFile(upload_collection_file_command, zip_file_path); 
    920     } 
    921     } 
    922  
    923  
    924     /** 
    925      * -------------------------------------------------------------------------------------------- 
    926      *    UPLOAD FILES INTO COLLECTION 
    927      * -------------------------------------------------------------------------------------------- 
    928      */ 
    929     static private class RemoteGreenstoneServerUploadFilesIntoCollectionAction 
    930     extends RemoteGreenstoneServerAction 
    931     { 
    932     private String collection_name; 
    933     private File[] source_files; 
    934     private File target_collection_directory; 
    935  
    936  
    937     public RemoteGreenstoneServerUploadFilesIntoCollectionAction(String collection_name, File[] source_files, File target_collection_directory) 
    938     { 
    939         this.collection_name = collection_name; 
    940         this.source_files = source_files; 
    941         this.target_collection_directory = target_collection_directory; 
    942     } 
    943  
    944  
    945     public void perform() 
    946         throws Exception 
    947     { 
    948         String collection_directory_path = CollectionManager.getCollectionDirectoryPath(collection_name); 
    949         String target_collection_directory_relative_path = getPathRelativeToDirectory(target_collection_directory, collection_directory_path); 
    950         target_collection_directory_relative_path = target_collection_directory_relative_path.replaceAll((Utility.isWindows() ? "\\\\" : "\\/"), "|"); 
    951         progress_bar.setAction("Uploading files into collection..."); 
    952         
    953         String zip_file_name = collection_name + "-" + System.currentTimeMillis() + ".zip"; 
    954         String zip_file_path = Gatherer.getCollectDirectoryPath() + zip_file_name; 
    955         DebugStream.println("Zip file path: " + zip_file_path); 
    956  
    957         String base_directory_path = source_files[0].getParentFile().getAbsolutePath(); 
    958         DebugStream.println("Base directory path: " + base_directory_path); 
    959         String[] source_file_relative_paths = new String[source_files.length]; 
    960         for (int i = 0; i < source_files.length; i++) { 
    961         DebugStream.println("Source file path: " + source_files[i]); 
    962         source_file_relative_paths[i] = getPathRelativeToDirectory(source_files[i], base_directory_path); 
    963         } 
    964          
    965         ZipTools.zipFiles(zip_file_path, base_directory_path, source_file_relative_paths); 
    966  
    967         String upload_collection_file_command = "cmd=upload-collection-file"; 
    968         upload_collection_file_command += "&c=" + URLEncoder.encode(collection_name, "UTF-8"); 
    969         upload_collection_file_command += "&file=" + URLEncoder.encode(zip_file_name, "UTF-8"); 
    970         upload_collection_file_command += "&directory=" + URLEncoder.encode(target_collection_directory_relative_path, "UTF-8"); 
    971         upload_collection_file_command += "&zip=true"; 
    972         action_output = uploadFile(upload_collection_file_command, zip_file_path); 
    973     } 
    974     } 
    975  
    976  
    977     // ---------------------------------------------------------------------------------------------------- 
    978319    //   AUTHENTICATION LAYER 
    979320    // ---------------------------------------------------------------------------------------------------- 
    980  
    981  
    982     static private PasswordAuthentication remote_greenstone_server_authentication = null; 
    983     // static private PasswordAuthentication remote_greenstone_server_authentication = new PasswordAuthentication(System.getProperty("user.name"), new char[] { }); 
    984  
    985     static public void set_remote_greenstone_server_authentication_to_null(){ 
    986     remote_greenstone_server_authentication = null; 
    987     } 
    988321 
    989322    static private class RemoteGreenstoneServerAuthenticateTask 
     
    1018351    } 
    1019352    } 
    1020  
    1021  
    1022     static private void authenticateUser() 
    1023     throws RemoteGreenstoneServerActionCancelledException 
     353     
     354    public void set_remote_greenstone_server_authentication_to_null() { 
     355    remote_greenstone_server_authentication = null; 
     356    } 
     357 
     358    private void authenticateUser() 
     359    throws RemoteGreenstoneServerAction.ActionCancelledException 
    1024360    { 
    1025361    // If we don't have any authentication information then ask for it now 
     
    1035371        // If it is still null then the user has cancelled the authentication, so the action is cancelled 
    1036372        if (remote_greenstone_server_authentication == null) { 
    1037         throw new RemoteGreenstoneServerActionCancelledException(); 
    1038         } 
    1039     } 
    1040     } 
    1041  
    1042  
    1043     static public String getUsername() 
     373        throw new RemoteGreenstoneServerAction.ActionCancelledException(); 
     374        } 
     375    } 
     376    } 
     377 
     378 
     379    public String getUsername() 
    1044380    { 
    1045381    if (remote_greenstone_server_authentication != null) { 
     
    1057393 
    1058394    /** Returns the command output if the action completed, throws some kind of exception otherwise. */ 
    1059     static private String downloadFile(String gliserver_args, String file_path) 
     395    String downloadFile(String gliserver_args, String file_path) 
    1060396    throws Exception 
    1061397    { 
     
    1081417        if (JOptionPane.showConfirmDialog(Gatherer.g_man, Dictionary.get("RemoteGreenstoneServer.Steal_Lock_Message", command_output.substring("ERROR: Collection is locked by: ".length())), Dictionary.get("RemoteGreenstoneServer.Error_Title"), JOptionPane.YES_NO_OPTION) == JOptionPane.NO_OPTION) { 
    1082418            // The user has decided to cancel the action 
    1083             throw new RemoteGreenstoneServerActionCancelledException(); 
     419            throw new RemoteGreenstoneServerAction.ActionCancelledException(); 
    1084420        } 
    1085421 
     
    1101437     * string embedded in the given gliserver_args. No authentication is required for either  
    1102438     * of the commands greenstone-server-version and get-library-url-suffix. */ 
    1103     static private boolean isAuthenticationRequired(String gliserver_args) { 
     439    private boolean isAuthenticationRequired(String gliserver_args) { 
    1104440    return ((gliserver_args.indexOf("greenstone-server-version") == -1)  
    1105441        && (gliserver_args.indexOf("get-library-url-suffix") == -1)); 
     
    1107443 
    1108444 
    1109     /** Returns the command output if the action completed, throws some kind of exception otherwise. */ 
    1110     static private String sendCommandToServer(String gliserver_args, GShell shell) 
     445    /** Returns the command output if the action completed, throws some kind of exception otherwise.  
     446     *  Package access, so that RemoteGreenstoneServerAction.java can call this. 
     447     */ 
     448    String sendCommandToServer(String gliserver_args, GShell shell) 
    1111449    throws Exception 
    1112450    { 
     
    1135473        if (JOptionPane.showConfirmDialog(Gatherer.g_man, Dictionary.get("RemoteGreenstoneServer.Steal_Lock_Message", command_output.substring("ERROR: Collection is locked by: ".length())), Dictionary.get("RemoteGreenstoneServer.Error_Title"), JOptionPane.YES_NO_OPTION) == JOptionPane.NO_OPTION) { 
    1136474            // The user has decided to cancel the action 
    1137             throw new RemoteGreenstoneServerActionCancelledException(); 
     475            throw new RemoteGreenstoneServerAction.ActionCancelledException(); 
    1138476        } 
    1139477 
     
    1157495 
    1158496    /** Returns the command output if the action completed, throws some kind of exception otherwise. */ 
    1159     static private String uploadFile(String gliserver_args, String file_path) 
     497    String uploadFile(String gliserver_args, String file_path) 
    1160498    throws Exception 
    1161499    { 
     
    1182520        if (JOptionPane.showConfirmDialog(Gatherer.g_man, Dictionary.get("RemoteGreenstoneServer.Steal_Lock_Message", command_output.substring("ERROR: Collection is locked by: ".length())), Dictionary.get("RemoteGreenstoneServer.Error_Title"), JOptionPane.YES_NO_OPTION) == JOptionPane.NO_OPTION) { 
    1183521            // The user has decided to cancel the action 
    1184             throw new RemoteGreenstoneServerActionCancelledException(); 
     522            throw new RemoteGreenstoneServerAction.ActionCancelledException(); 
    1185523        } 
    1186524 
     
    1206544 
    1207545    /** Returns the command output if the action completed, throws some kind of exception otherwise. */ 
    1208     static private String downloadFileInternal(String download_cgi, String cgi_args, String file_path) 
     546    private String downloadFileInternal(String download_cgi, String cgi_args, String file_path) 
    1209547    throws Exception 
    1210548    { 
     
    1262600 
    1263601    /** Returns the command output if the action completed, throws some kind of exception otherwise. */ 
    1264     static private String sendCommandToServerInternal(String gliserver_url_string, String cgi_args, GShell shell) 
     602    private String sendCommandToServerInternal(String gliserver_url_string, String cgi_args, GShell shell) 
    1265603    throws Exception 
    1266604    { 
     
    1290628        shell.fireMessage(gliserver_output_line); 
    1291629        if (shell.hasSignalledStop()) { 
    1292             throw new RemoteGreenstoneServerActionCancelledException(); 
     630            throw new RemoteGreenstoneServerAction.ActionCancelledException(); 
    1293631        } 
    1294632        } 
     
    1303641            
    1304642    /** Returns the command output if the action completed, throws some kind of exception otherwise. */ 
    1305     static private String uploadFileInternal(String upload_cgi, String cgi_args, String file_path) 
     643    private String uploadFileInternal(String upload_cgi, String cgi_args, String file_path) 
    1306644    throws Exception 
    1307645    { 
     
    1433771 
    1434772 
    1435     static public String getPathRelativeToDirectory(File file, String directory_path) 
     773    public String getPathRelativeToDirectory(File file, String directory_path) 
    1436774    { 
    1437775    String file_path = file.getAbsolutePath(); 
  • gli/trunk/src/org/greenstone/gatherer/shell/GShell.java

    r17009 r17612  
    217217        System.err.println("Script args: " + script_args); 
    218218        buffered_output_stream = bos; 
    219         String command_output = RemoteGreenstoneServer.runScript(collection_name, script_name, script_args, this); 
     219        String command_output = Gatherer.remoteGreenstoneServer.runScript(collection_name, script_name, script_args, this); 
    220220        status = (command_output.equals("") ? CANCELLED : OK); 
    221221    } 
     
    383383        if (type == NEW) { 
    384384        if (Gatherer.isGsdlRemote) { 
    385             RemoteGreenstoneServer.downloadCollection(col_name); 
     385            Gatherer.remoteGreenstoneServer.downloadCollection(col_name); 
    386386        } 
    387387        } 
     
    395395            } 
    396396 
    397             RemoteGreenstoneServer.downloadCollectionArchives(col_name); 
     397            Gatherer.remoteGreenstoneServer.downloadCollectionArchives(col_name); 
    398398 
    399399            if (progress!=null) { 
     
    428428            // Only need to download build.cfg file 
    429429            File build_cfg_file = new File(CollectionManager.getLoadedCollectionBuildingDirectoryPath(), "build.cfg"); 
    430             RemoteGreenstoneServer.downloadCollectionFile(col_name, build_cfg_file); 
     430            Gatherer.remoteGreenstoneServer.downloadCollectionFile(col_name, build_cfg_file); 
    431431            }else{ 
    432432            // Only need to download buildConfig.xml file 
    433433            File buildConfig_xml_file = new File(CollectionManager.getLoadedCollectionBuildingDirectoryPath(), "buildConfig.xml"); 
    434             RemoteGreenstoneServer.downloadCollectionFile(col_name, buildConfig_xml_file); 
     434            Gatherer.remoteGreenstoneServer.downloadCollectionFile(col_name, buildConfig_xml_file); 
    435435            } 
    436436