- Timestamp:
- 2008-10-24T17:45:51+13:00 (16 years ago)
- Location:
- gli/trunk/src/org/greenstone/gatherer
- Files:
-
- 2 added
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
gli/trunk/src/org/greenstone/gatherer/Gatherer.java
r17121 r17612 85 85 86 86 static private Dimension size = new Dimension(800, 540); 87 static public RemoteGreenstoneServer remoteGreenstoneServer = null; 87 88 88 89 /** Has the exit flag been set? */ … … 299 300 // Finally, we're ready to find out the version of the remote Greenstone server 300 301 if(isGsdlRemote) { 302 // instantiate the RemoteGreenstoneServer object first 303 remoteGreenstoneServer = new RemoteGreenstoneServer(); 304 301 305 int greenstoneVersion = 2; 302 306 requestGLIServerURL(); 303 307 gliserver_url_string = Configuration.gliserver_url.toString(); 304 308 305 greenstoneVersion = RemoteGreenstoneServer.getGreenstoneVersion();309 greenstoneVersion = remoteGreenstoneServer.getGreenstoneVersion(); 306 310 // Display the version to make error reports a lot more useful 307 311 System.err.println("Remote Greenstone server version: " + greenstoneVersion); … … 316 320 library_url_string = fedora_info.getLibraryURL(); 317 321 } else { 318 library_url_string = RemoteGreenstoneServer.getLibraryURL(Configuration.gliserver_url.toString());322 library_url_string = remoteGreenstoneServer.getLibraryURL(Configuration.gliserver_url.toString()); 319 323 } 320 324 } … … 472 476 // If using a remote Greenstone we need to download the collection configurations now 473 477 if (Gatherer.isGsdlRemote) { 474 if ( RemoteGreenstoneServer.downloadCollectionConfigurations().equals("")) {478 if (remoteGreenstoneServer.downloadCollectionConfigurations().equals("")) { 475 479 // !! Something went wrong downloading the collection configurations 476 480 System.err.println("Error: Could not download collection configurations."); … … 551 555 // If using a remote Greenstone we need to download the collection configurations now 552 556 if (Gatherer.isGsdlRemote) { 553 if ( RemoteGreenstoneServer.downloadCollectionConfigurations().equals("")) {557 if (remoteGreenstoneServer.downloadCollectionConfigurations().equals("")) { 554 558 // !! Something went wrong downloading the collection configurations 555 559 System.err.println("Error: Could not download collection configurations."); … … 616 620 // If we're using a remote Greenstone server we need to make sure that all jobs have completed first 617 621 if (isGsdlRemote) { 618 RemoteGreenstoneServer.exit();622 remoteGreenstoneServer.exit(); 619 623 } 620 624 -
gli/trunk/src/org/greenstone/gatherer/cdm/CollectionConfiguration.java
r17031 r17612 3707 3707 // If we're using a remote Greenstone server, upload the new 'collectionConfig.xml' file 3708 3708 if (Gatherer.isGsdlRemote) { 3709 RemoteGreenstoneServer.uploadCollectionFile (collection_name, collect_cfg_file);3709 Gatherer.remoteGreenstoneServer.uploadCollectionFile (collection_name, collect_cfg_file); 3710 3710 } 3711 3711 … … 3799 3799 // If we're using a remote Greenstone server, upload the new collect.cfg file 3800 3800 if (Gatherer.isGsdlRemote) { 3801 RemoteGreenstoneServer.uploadCollectionFile (collection_name, collect_cfg_file);3801 Gatherer.remoteGreenstoneServer.uploadCollectionFile (collection_name, collect_cfg_file); 3802 3802 } 3803 3803 } -
gli/trunk/src/org/greenstone/gatherer/cdm/GeneralManager.java
r17211 r17612 344 344 // If we're using a remote Greenstone server, upload the image 345 345 if (Gatherer.isGsdlRemote) { 346 RemoteGreenstoneServer.uploadCollectionFile(CollectionManager.getLoadedCollectionName(), collection_image_file); 346 Gatherer.remoteGreenstoneServer.uploadCollectionFile( 347 CollectionManager.getLoadedCollectionName(), collection_image_file); 347 348 } 348 349 } -
gli/trunk/src/org/greenstone/gatherer/cdm/MacrosManager.java
r13591 r17612 217 217 // Users need to wait until the upload has finished before pressing Preview Collection! 218 218 if (Gatherer.isGsdlRemote) { 219 RemoteGreenstoneServer.uploadCollectionFile(CollectionManager.getLoadedCollectionName(), extra_dm_file);219 Gatherer.remoteGreenstoneServer.uploadCollectionFile(CollectionManager.getLoadedCollectionName(), extra_dm_file); 220 220 } 221 221 } -
gli/trunk/src/org/greenstone/gatherer/collection/CollectionManager.java
r17012 r17612 379 379 // Remove the lock file on the server 380 380 if (Gatherer.isGsdlRemote) { 381 RemoteGreenstoneServer.deleteCollectionFile(collection.getName(), lock_file);381 Gatherer.remoteGreenstoneServer.deleteCollectionFile(collection.getName(), lock_file); 382 382 } 383 383 … … 547 547 collection_import_directory.mkdirs(); 548 548 if (Gatherer.isGsdlRemote) { 549 RemoteGreenstoneServer.newCollectionDirectory(name, collection_import_directory);549 Gatherer.remoteGreenstoneServer.newCollectionDirectory(name, collection_import_directory); 550 550 } 551 551 } … … 581 581 if (Gatherer.isGsdlRemote) { 582 582 String base_collection_name = base_collection_directory.getName(); 583 RemoteGreenstoneServer.downloadCollection(base_collection_name);583 Gatherer.remoteGreenstoneServer.downloadCollection(base_collection_name); 584 584 } 585 585 … … 765 765 // Delete the collection on the server if we're using a remote Greenstone 766 766 if (Gatherer.isGsdlRemote) { 767 RemoteGreenstoneServer.deleteCollection(collection_name);767 Gatherer.remoteGreenstoneServer.deleteCollection(collection_name); 768 768 } 769 769 … … 1056 1056 // If we're using a remote Greenstone server, upload the metadata file 1057 1057 if (Gatherer.isGsdlRemote) { 1058 RemoteGreenstoneServer.uploadCollectionFile(collection.getName(), metadata_set_file);1058 Gatherer.remoteGreenstoneServer.uploadCollectionFile(collection.getName(), metadata_set_file); 1059 1059 } 1060 1060 } … … 1122 1122 if (Gatherer.isGsdlRemote) { 1123 1123 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("")) { 1125 1125 return; 1126 1126 } … … 1618 1618 // If we're using a remote Greenstone server, delete the metadata file on the server 1619 1619 if (Gatherer.isGsdlRemote) { 1620 RemoteGreenstoneServer.deleteCollectionFile(collection.getName(), metadata_set_file);1620 Gatherer.remoteGreenstoneServer.deleteCollectionFile(collection.getName(), metadata_set_file); 1621 1621 } 1622 1622 } … … 1750 1750 1751 1751 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())); 1754 1756 } 1755 1757 -
gli/trunk/src/org/greenstone/gatherer/collection/ScriptOptions.java
r16267 r17612 225 225 226 226 if (Gatherer.isGsdlRemote) { 227 String script_output = RemoteGreenstoneServer.getScriptOptions(filename, "");227 String script_output = Gatherer.remoteGreenstoneServer.getScriptOptions(filename, ""); 228 228 document = XMLTools.parseXML(new StringReader(script_output)); 229 229 } -
gli/trunk/src/org/greenstone/gatherer/file/FileManager.java
r15105 r17612 180 180 source_files[i] = source_nodes[i].getFile(); 181 181 } 182 RemoteGreenstoneServer.uploadFilesIntoCollection(collection_name, source_files, target_node.getFile());182 Gatherer.remoteGreenstoneServer.uploadFilesIntoCollection(collection_name, source_files, target_node.getFile()); 183 183 } 184 184 else if (type == FileJob.DELETE) { 185 185 // Deletes: delete each top-level file/directory one at a time 186 186 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()); 188 188 } 189 189 } … … 191 191 // Moves: move each top-level file/directory one at a time 192 192 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()); 194 195 } 195 196 } … … 272 273 // ... but only if it is inside the collection and we haven't already downloaded it 273 274 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("")) { 275 277 // Something has gone wrong downloading the file 276 278 return; … … 347 349 folder_file.createNewFile(); 348 350 if (Gatherer.isGsdlRemote) { 349 RemoteGreenstoneServer.uploadCollectionFile(CollectionManager.getLoadedCollectionName(), folder_file); 351 Gatherer.remoteGreenstoneServer.uploadCollectionFile( 352 CollectionManager.getLoadedCollectionName(), folder_file); 350 353 } 351 354 } … … 353 356 folder_file.mkdirs(); 354 357 if (Gatherer.isGsdlRemote) { 355 RemoteGreenstoneServer.newCollectionDirectory(CollectionManager.getLoadedCollectionName(), folder_file); 358 Gatherer.remoteGreenstoneServer.newCollectionDirectory( 359 CollectionManager.getLoadedCollectionName(), folder_file); 356 360 } 357 361 } … … 413 417 file_queue.addJob(System.currentTimeMillis(), collection_tree, new FileNode[] { collection_tree_node }, collection_tree, new_collection_tree_node, FileJob.RENAME); 414 418 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); 416 421 } 417 422 } … … 462 467 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); 463 468 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); 465 471 } 466 472 // do a replace of old file with new file -
gli/trunk/src/org/greenstone/gatherer/greenstone/Classifiers.java
r13594 r17612 134 134 classinfo_options += "&collection=" + collection_name; 135 135 } 136 classinfo_xml = RemoteGreenstoneServer.getScriptOptions("classinfo.pl", classinfo_options);136 classinfo_xml = Gatherer.remoteGreenstoneServer.getScriptOptions("classinfo.pl", classinfo_options); 137 137 } 138 138 else { … … 195 195 classinfo_options += "&collection=" + collection_name; 196 196 } 197 String classinfo_output = RemoteGreenstoneServer.getScriptOptions("classinfo.pl", classinfo_options);197 String classinfo_output = Gatherer.remoteGreenstoneServer.getScriptOptions("classinfo.pl", classinfo_options); 198 198 xml = new StringBuffer(classinfo_output); 199 199 } -
gli/trunk/src/org/greenstone/gatherer/greenstone/Plugins.java
r16295 r17612 135 135 pluginfo_options += "&collection=" + collection_name; 136 136 } 137 pluginfo_xml = RemoteGreenstoneServer.getScriptOptions("pluginfo.pl", pluginfo_options);137 pluginfo_xml = Gatherer.remoteGreenstoneServer.getScriptOptions("pluginfo.pl", pluginfo_options); 138 138 } 139 139 else { … … 198 198 pluginfo_options += "&collection=" + collection_name; 199 199 } 200 String pluginfo_output = RemoteGreenstoneServer.getScriptOptions("pluginfo.pl", pluginfo_options);200 String pluginfo_output = Gatherer.remoteGreenstoneServer.getScriptOptions("pluginfo.pl", pluginfo_options); 201 201 xml = new StringBuffer(pluginfo_output); 202 202 } -
gli/trunk/src/org/greenstone/gatherer/greenstone3/ServletConfiguration.java
r14592 r17612 70 70 71 71 if (Gatherer.isGsdlRemote){ 72 if ( RemoteGreenstoneServer.downloadWebXMLFile().equals("")) {72 if (Gatherer.remoteGreenstoneServer.downloadWebXMLFile().equals("")) { 73 73 System.err.println("Error: Could not download web.xml."); 74 74 System.exit(0); … … 89 89 this.sites = new ArrayList(); 90 90 if (Gatherer.isGsdlRemote){ 91 String sites_on_server = RemoteGreenstoneServer.getSiteNames();91 String sites_on_server = Gatherer.remoteGreenstoneServer.getSiteNames(); 92 92 if (sites_on_server.equals("")) { 93 93 // !! Something went wrong : could not get names of the sites -
gli/trunk/src/org/greenstone/gatherer/gui/ExplodeMetadataDatabasePrompt.java
r13820 r17612 274 274 String collection_name = CollectionManager.getLoadedCollectionName(); 275 275 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); 277 278 command_parts_list.add("-file"); 278 279 command_parts_list.add(metadata_file_relative_path); … … 345 346 if (Gatherer.isGsdlRemote) { 346 347 Utility.delete(metadata_file.getParentFile()); 347 RemoteGreenstoneServer.downloadCollectionFile(CollectionManager.getLoadedCollectionName(), metadata_file.getParentFile()); 348 Gatherer.remoteGreenstoneServer.downloadCollectionFile( 349 CollectionManager.getLoadedCollectionName(), metadata_file.getParentFile()); 348 350 } 349 351 -
gli/trunk/src/org/greenstone/gatherer/gui/GUIManager.java
r16884 r17612 438 438 remote_greenstone_server_progress_panel.setLayout(new BorderLayout()); 439 439 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); 441 441 content_pane.add(remote_greenstone_server_progress_panel, BorderLayout.SOUTH); 442 442 } -
gli/trunk/src/org/greenstone/gatherer/gui/NewCollectionDetailsPrompt.java
r14563 r17612 259 259 // Remote collections that aren't shared have the user's username prefixed to the collection name 260 260 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()); 262 262 } 263 263 -
gli/trunk/src/org/greenstone/gatherer/gui/Preferences.java
r17353 r17612 826 826 Configuration.save(); 827 827 if (Gatherer.isGsdlRemote && Gatherer.GS3 && site_changed ){ 828 RemoteGreenstoneServer.downloadCollectionConfigurations();828 Gatherer.remoteGreenstoneServer.downloadCollectionConfigurations(); 829 829 } 830 830 // Refresh the GLI to account for the configuration changes … … 956 956 if (Gatherer.c_man.getCollection()!=null){ 957 957 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); 959 959 Gatherer.g_man.closeCurrentCollection(); 960 960 } 961 961 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(); 964 964 } 965 965 } -
gli/trunk/src/org/greenstone/gatherer/gui/ReplaceSrcDocWithHtmlPrompt.java
r15163 r17612 272 272 String collection_name = CollectionManager.getLoadedCollectionName(); 273 273 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( 275 275 this.srcdoc_files[fileNum], collection_directory_path); // preserves spaces in filename 276 276 command_parts_list.add("-file"); … … 382 382 // download the generated html file from the server side to put it 383 383 // into the import directory on the client side 384 RemoteGreenstoneServer.downloadCollectionFile(384 Gatherer.remoteGreenstoneServer.downloadCollectionFile( 385 385 CollectionManager.getLoadedCollectionName(), 386 386 new File(srcdoc_files[i].getParentFile(), htmlFile)); … … 389 389 File assoc_folder = new File(srcdoc_files[i].getParentFile(), suffixlessFilename+"_files"); 390 390 // 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( 393 393 CollectionManager.getLoadedCollectionName(), assoc_folder); 394 394 } -
gli/trunk/src/org/greenstone/gatherer/metadata/MetadataXMLFileManager.java
r13818 r17612 368 368 369 369 // 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])); 371 372 modified_metadata_xml_files.clear(); 372 373 } -
gli/trunk/src/org/greenstone/gatherer/metadata/ProfileXMLFile.java
r13808 r17612 110 110 // This is inefficient but for simplicity we'll just upload the file every time it is changed 111 111 if (Gatherer.isGsdlRemote) { 112 RemoteGreenstoneServer.uploadCollectionFile(CollectionManager.getLoadedCollectionName(), this);112 Gatherer.remoteGreenstoneServer.uploadCollectionFile(CollectionManager.getLoadedCollectionName(), this); 113 113 } 114 114 -
gli/trunk/src/org/greenstone/gatherer/remote/RemoteGreenstoneServer.java
r16471 r17612 58 58 public class RemoteGreenstoneServer 59 59 { 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 60 72 // ---------------------------------------------------------------------------------------------------- 61 73 // PUBLIC LAYER 62 74 // ---------------------------------------------------------------------------------------------------- 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)); 98 108 } 99 109 100 110 // get web.xml from the server -- for a remote gli of GS3 101 staticpublic String downloadWebXMLFile()102 { 103 return performAction(new RemoteGreenstoneServer DownloadWebXMLFileAction());104 } 105 106 staticpublic String getScriptOptions(String script_name, String script_arguments)107 { 108 return performAction(new RemoteGreenstoneServer GetScriptOptionsAction(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)); 109 119 } 110 120 111 121 //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)); 155 170 if(result.indexOf("exists") != -1) { 156 171 return true; … … 162 177 } 163 178 164 staticpublic int getGreenstoneVersion()179 public int getGreenstoneVersion() 165 180 { 166 181 // returns message "Greenstone version is: <version number of the Greenstone remote server>" 167 String result = performAction(new RemoteGreenstoneServer VersionAction());182 String result = performAction(new RemoteGreenstoneServerAction.VersionAction()); 168 183 int index = result.indexOf(":"); 169 184 if(index != -1) { … … 175 190 176 191 /** For constructing the preview command (the library URL) with */ 177 staticpublic String getLibraryURL(String serverHomeURL)192 public String getLibraryURL(String serverHomeURL) 178 193 { 179 194 // returns message "Greenstone library URL suffix is: <e.g. /greenstone3/library or /gsdl/cgi-bin/library>" 180 String libSuffix = performAction(new RemoteGreenstoneServer LibraryURLSuffixAction());195 String libSuffix = performAction(new RemoteGreenstoneServerAction.LibraryURLSuffixAction()); 181 196 int index = libSuffix.indexOf(":"); 182 197 if(index != -1) { … … 200 215 201 216 202 staticpublic void exit()217 public void exit() 203 218 { 204 219 System.err.println("Exiting, number of jobs on queue: " + remote_greenstone_server_action_queue.size()); … … 223 238 224 239 /** Returns null if we cannot wait for the action to finish, "" if the action failed, or the action output. */ 225 staticprivate String performAction(RemoteGreenstoneServerAction remote_greenstone_server_action)240 private String performAction(RemoteGreenstoneServerAction remote_greenstone_server_action) 226 241 { 227 242 // Add the action to the queue … … 255 270 256 271 257 static private RemoteGreenstoneServerActionQueue remote_greenstone_server_action_queue = new RemoteGreenstoneServerActionQueue();258 259 260 static private class RemoteGreenstoneServerActionQueue261 extends Thread262 {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 it294 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 successful301 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-provided318 // 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 worse335 remote_greenstone_server_action.processed = true;336 queue.remove(0);337 }338 339 // Otherwise the queue is empty340 else {341 progress_bar.setAction(null);342 343 // Wait until we are notify()ed by addAction that there is a new job on the queue344 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 simply353 // refused or when the user pressed Cancel in the opening dialog, by exitting354 // cleanly in one go.355 if(exit == true) {356 Gatherer.exit();357 }358 }359 }360 }361 362 363 272 // ---------------------------------------------------------------------------------------------------- 364 273 // PROGRESS BAR 365 274 // ---------------------------------------------------------------------------------------------------- 366 275 367 368 static private RemoteGreenstoneServerProgressBar progress_bar = new RemoteGreenstoneServerProgressBar(); 369 370 371 static private class RemoteGreenstoneServerProgressBar 276 static class ProgressBar 372 277 extends JProgressBar 373 278 { 374 public RemoteGreenstoneServerProgressBar()279 public ProgressBar() 375 280 { 376 281 setBackground(Configuration.getColor("coloring.collection_tree_background", false)); … … 404 309 } 405 310 } 406 407 408 static public RemoteGreenstoneServerProgressBar getProgressBar() 311 312 public RemoteGreenstoneServer.ProgressBar getProgressBar() 409 313 { 410 314 return progress_bar; … … 413 317 414 318 // ---------------------------------------------------------------------------------------------------- 415 // ACTIONS416 // ----------------------------------------------------------------------------------------------------417 418 419 static private abstract class RemoteGreenstoneServerAction420 {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 RemoteGreenstoneServerActionCancelledException431 extends Exception432 {433 }434 435 436 /**437 * --------------------------------------------------------------------------------------------438 * DELETE COLLECTION439 * --------------------------------------------------------------------------------------------440 */441 static private class RemoteGreenstoneServerDeleteCollectionAction442 extends RemoteGreenstoneServerAction443 {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 Exception453 {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 FILE466 * --------------------------------------------------------------------------------------------467 */468 static private class RemoteGreenstoneServerDeleteCollectionFileAction469 extends RemoteGreenstoneServerAction470 {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 Exception482 {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 COLLECTION499 * --------------------------------------------------------------------------------------------500 */501 static private class RemoteGreenstoneServerDownloadCollectionAction502 extends RemoteGreenstoneServerAction503 {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 Exception513 {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 directory522 Utility.delete(new File(CollectionManager.getCollectionDirectoryPath(collection_name)));523 524 // Unzip the collection just downloaded525 UnzipTools.unzipFile(zip_file_path, Gatherer.getCollectDirectoryPath());526 }527 }528 529 530 /**531 * --------------------------------------------------------------------------------------------532 * DOWNLOAD COLLECTION ARCHIVES533 * --------------------------------------------------------------------------------------------534 */535 static private class RemoteGreenstoneServerDownloadCollectionArchivesAction536 extends RemoteGreenstoneServerAction537 {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 Exception547 {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 archives556 Utility.delete(new File(CollectionManager.getLoadedCollectionArchivesDirectoryPath()));557 558 // Unzip the collection archives just downloaded559 UnzipTools.unzipFile(zip_file_path, Gatherer.getCollectDirectoryPath());560 }561 }562 563 564 /**565 * --------------------------------------------------------------------------------------------566 * DOWNLOAD COLLECTION CONFIGURATIONS567 * --------------------------------------------------------------------------------------------568 */569 static private class RemoteGreenstoneServerDownloadCollectionConfigurationsAction570 extends RemoteGreenstoneServerAction571 {572 public RemoteGreenstoneServerDownloadCollectionConfigurationsAction()573 {574 }575 576 public void perform()577 throws Exception578 {579 progress_bar.setAction("Downloading collection configurations...");580 581 // Delete the existing (local) collect directory582 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 downloaded590 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 RemoteGreenstoneServerVersionAction601 extends RemoteGreenstoneServerAction602 {603 public void perform()604 throws Exception605 {606 action_output = sendCommandToServer("cmd=greenstone-server-version", null);607 }608 }609 610 static private class RemoteGreenstoneServerLibraryURLSuffixAction611 extends RemoteGreenstoneServerAction612 {613 public void perform()614 throws Exception615 {616 action_output = sendCommandToServer("cmd=get-library-url-suffix", null);617 }618 }619 620 /**621 * --------------------------------------------------------------------------------------------622 * CHECKING IF A FILE/FOLDER EXISTS ON SERVER SIDE623 * --------------------------------------------------------------------------------------------624 */625 static private class RemoteGreenstoneServerExistsAction626 extends RemoteGreenstoneServerAction627 {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 Exception639 {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_file650 action_output = sendCommandToServer(file_exists_command, null);651 }652 }653 654 655 /**656 * --------------------------------------------------------------------------------------------657 * DOWNLOAD COLLECTION FILE658 * --------------------------------------------------------------------------------------------659 */660 static private class RemoteGreenstoneServerDownloadCollectionFileAction661 extends RemoteGreenstoneServerAction662 {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 Exception674 {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 downloaded688 UnzipTools.unzipFile(zip_file_path, collection_directory_path);689 }690 }691 692 /**693 * --------------------------------------------------------------------------------------------694 * DOWNLOAD web.xml FILE --for a remote GS3695 * --------------------------------------------------------------------------------------------696 */697 static private class RemoteGreenstoneServerDownloadWebXMLFileAction698 extends RemoteGreenstoneServerAction699 {700 public RemoteGreenstoneServerDownloadWebXMLFileAction()701 {}702 703 public void perform()704 throws Exception705 {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 downloaded714 UnzipTools.unzipFile(zip_file_path,web_xml_directory_path);715 }716 }717 718 /**719 * --------------------------------------------------------------------------------------------720 * GET SCRIPT OPTIONS721 * --------------------------------------------------------------------------------------------722 */723 static private class RemoteGreenstoneServerGetScriptOptionsAction724 extends RemoteGreenstoneServerAction725 {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 Exception737 {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 GS3752 * --------------------------------------------------------------------------------------------753 */754 static private class RemoteGreenstoneServerGetSiteNamesAction755 extends RemoteGreenstoneServerAction756 {757 public RemoteGreenstoneServerGetSiteNamesAction()758 {}759 760 public void perform()761 throws Exception762 {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 FILE773 * --------------------------------------------------------------------------------------------774 */775 static private class RemoteGreenstoneServerMoveCollectionFileAction776 extends RemoteGreenstoneServerAction777 {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 Exception791 {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 DIRECTORY811 * --------------------------------------------------------------------------------------------812 */813 static private class RemoteGreenstoneServerNewCollectionDirectoryAction814 extends RemoteGreenstoneServerAction815 {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 Exception827 {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 SCRIPT844 * --------------------------------------------------------------------------------------------845 */846 static private class RemoteGreenstoneServerRunScriptAction847 extends RemoteGreenstoneServerAction848 {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 Exception864 {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 FILE880 * --------------------------------------------------------------------------------------------881 */882 static private class RemoteGreenstoneServerUploadCollectionFilesAction883 extends RemoteGreenstoneServerAction884 {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 Exception898 {899 progress_bar.setAction("Uploading collection files...");900 901 // Determine the file paths relative to the collection directory902 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 server909 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 file914 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 COLLECTION927 * --------------------------------------------------------------------------------------------928 */929 static private class RemoteGreenstoneServerUploadFilesIntoCollectionAction930 extends RemoteGreenstoneServerAction931 {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 Exception947 {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 // ----------------------------------------------------------------------------------------------------978 319 // AUTHENTICATION LAYER 979 320 // ---------------------------------------------------------------------------------------------------- 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 }988 321 989 322 static private class RemoteGreenstoneServerAuthenticateTask … … 1018 351 } 1019 352 } 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 1024 360 { 1025 361 // If we don't have any authentication information then ask for it now … … 1035 371 // If it is still null then the user has cancelled the authentication, so the action is cancelled 1036 372 if (remote_greenstone_server_authentication == null) { 1037 throw new RemoteGreenstoneServerAction CancelledException();1038 } 1039 } 1040 } 1041 1042 1043 staticpublic String getUsername()373 throw new RemoteGreenstoneServerAction.ActionCancelledException(); 374 } 375 } 376 } 377 378 379 public String getUsername() 1044 380 { 1045 381 if (remote_greenstone_server_authentication != null) { … … 1057 393 1058 394 /** Returns the command output if the action completed, throws some kind of exception otherwise. */ 1059 static privateString downloadFile(String gliserver_args, String file_path)395 String downloadFile(String gliserver_args, String file_path) 1060 396 throws Exception 1061 397 { … … 1081 417 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) { 1082 418 // The user has decided to cancel the action 1083 throw new RemoteGreenstoneServerAction CancelledException();419 throw new RemoteGreenstoneServerAction.ActionCancelledException(); 1084 420 } 1085 421 … … 1101 437 * string embedded in the given gliserver_args. No authentication is required for either 1102 438 * of the commands greenstone-server-version and get-library-url-suffix. */ 1103 staticprivate boolean isAuthenticationRequired(String gliserver_args) {439 private boolean isAuthenticationRequired(String gliserver_args) { 1104 440 return ((gliserver_args.indexOf("greenstone-server-version") == -1) 1105 441 && (gliserver_args.indexOf("get-library-url-suffix") == -1)); … … 1107 443 1108 444 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) 1111 449 throws Exception 1112 450 { … … 1135 473 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) { 1136 474 // The user has decided to cancel the action 1137 throw new RemoteGreenstoneServerAction CancelledException();475 throw new RemoteGreenstoneServerAction.ActionCancelledException(); 1138 476 } 1139 477 … … 1157 495 1158 496 /** Returns the command output if the action completed, throws some kind of exception otherwise. */ 1159 static privateString uploadFile(String gliserver_args, String file_path)497 String uploadFile(String gliserver_args, String file_path) 1160 498 throws Exception 1161 499 { … … 1182 520 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) { 1183 521 // The user has decided to cancel the action 1184 throw new RemoteGreenstoneServerAction CancelledException();522 throw new RemoteGreenstoneServerAction.ActionCancelledException(); 1185 523 } 1186 524 … … 1206 544 1207 545 /** Returns the command output if the action completed, throws some kind of exception otherwise. */ 1208 staticprivate String downloadFileInternal(String download_cgi, String cgi_args, String file_path)546 private String downloadFileInternal(String download_cgi, String cgi_args, String file_path) 1209 547 throws Exception 1210 548 { … … 1262 600 1263 601 /** Returns the command output if the action completed, throws some kind of exception otherwise. */ 1264 staticprivate String sendCommandToServerInternal(String gliserver_url_string, String cgi_args, GShell shell)602 private String sendCommandToServerInternal(String gliserver_url_string, String cgi_args, GShell shell) 1265 603 throws Exception 1266 604 { … … 1290 628 shell.fireMessage(gliserver_output_line); 1291 629 if (shell.hasSignalledStop()) { 1292 throw new RemoteGreenstoneServerAction CancelledException();630 throw new RemoteGreenstoneServerAction.ActionCancelledException(); 1293 631 } 1294 632 } … … 1303 641 1304 642 /** Returns the command output if the action completed, throws some kind of exception otherwise. */ 1305 staticprivate String uploadFileInternal(String upload_cgi, String cgi_args, String file_path)643 private String uploadFileInternal(String upload_cgi, String cgi_args, String file_path) 1306 644 throws Exception 1307 645 { … … 1433 771 1434 772 1435 staticpublic String getPathRelativeToDirectory(File file, String directory_path)773 public String getPathRelativeToDirectory(File file, String directory_path) 1436 774 { 1437 775 String file_path = file.getAbsolutePath(); -
gli/trunk/src/org/greenstone/gatherer/shell/GShell.java
r17009 r17612 217 217 System.err.println("Script args: " + script_args); 218 218 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); 220 220 status = (command_output.equals("") ? CANCELLED : OK); 221 221 } … … 383 383 if (type == NEW) { 384 384 if (Gatherer.isGsdlRemote) { 385 RemoteGreenstoneServer.downloadCollection(col_name);385 Gatherer.remoteGreenstoneServer.downloadCollection(col_name); 386 386 } 387 387 } … … 395 395 } 396 396 397 RemoteGreenstoneServer.downloadCollectionArchives(col_name);397 Gatherer.remoteGreenstoneServer.downloadCollectionArchives(col_name); 398 398 399 399 if (progress!=null) { … … 428 428 // Only need to download build.cfg file 429 429 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); 431 431 }else{ 432 432 // Only need to download buildConfig.xml file 433 433 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); 435 435 } 436 436
Note:
See TracChangeset
for help on using the changeset viewer.