[17612] | 1 | /**
|
---|
| 2 | *#########################################################################
|
---|
| 3 | *
|
---|
| 4 | * A component of the Greenstone Librarian Interface application, part of
|
---|
| 5 | * the Greenstone digital library suite from the New Zealand Digital
|
---|
| 6 | * Library Project at the University of Waikato, New Zealand.
|
---|
| 7 | *
|
---|
| 8 | * Author: Michael Dewsnip, NZDL Project, University of Waikato
|
---|
| 9 | *
|
---|
| 10 | * Copyright (C) 2005 New Zealand Digital Library Project
|
---|
| 11 | *
|
---|
| 12 | * This program is free software; you can redistribute it and/or modify
|
---|
| 13 | * it under the terms of the GNU General Public License as published by
|
---|
| 14 | * the Free Software Foundation; either version 2 of the License, or
|
---|
| 15 | * (at your option) any later version.
|
---|
| 16 | *
|
---|
| 17 | * This program is distributed in the hope that it will be useful,
|
---|
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 20 | * GNU General Public License for more details.
|
---|
| 21 | *
|
---|
| 22 | * You should have received a copy of the GNU General Public License
|
---|
| 23 | * along with this program; if not, write to the Free Software
|
---|
| 24 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 25 | *########################################################################
|
---|
| 26 | */
|
---|
| 27 |
|
---|
| 28 | package org.greenstone.gatherer.remote;
|
---|
| 29 |
|
---|
| 30 | import java.io.*;
|
---|
| 31 | import java.net.*;
|
---|
| 32 | import java.util.*;
|
---|
| 33 | import java.util.zip.*;
|
---|
| 34 | import javax.swing.*;
|
---|
| 35 | import java.io.ByteArrayOutputStream;
|
---|
| 36 | import org.greenstone.gatherer.Configuration;
|
---|
| 37 | import org.greenstone.gatherer.DebugStream;
|
---|
| 38 | import org.greenstone.gatherer.Dictionary;
|
---|
| 39 | import org.greenstone.gatherer.FedoraInfo;
|
---|
| 40 | import org.greenstone.gatherer.GAuthenticator;
|
---|
| 41 | import org.greenstone.gatherer.Gatherer;
|
---|
| 42 | import org.greenstone.gatherer.collection.CollectionManager;
|
---|
[18646] | 43 | import org.greenstone.gatherer.feedback.Base64;
|
---|
[17612] | 44 | import org.greenstone.gatherer.shell.GShell;
|
---|
| 45 | import org.greenstone.gatherer.util.UnzipTools;
|
---|
| 46 | import org.greenstone.gatherer.util.Utility;
|
---|
| 47 | import org.apache.commons.httpclient.HttpClient;
|
---|
| 48 | import org.apache.commons.httpclient.methods.PostMethod;
|
---|
| 49 | import org.apache.commons.httpclient.methods.GetMethod;
|
---|
| 50 | import org.apache.commons.httpclient.HttpException;
|
---|
| 51 | import org.apache.commons.httpclient.methods.multipart.FilePart;
|
---|
| 52 | import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
|
---|
| 53 | import org.apache.commons.httpclient.methods.multipart.Part;
|
---|
| 54 | import org.apache.commons.httpclient.methods.multipart.*;
|
---|
| 55 | import org.apache.commons.httpclient.params.*;
|
---|
| 56 | import org.apache.commons.httpclient.HttpStatus;
|
---|
| 57 |
|
---|
| 58 |
|
---|
| 59 | // Code moved here from RemoteGreenstoneServer.java
|
---|
| 60 | // ----------------------------------------------------------------------------------------------------
|
---|
| 61 | // ACTIONS
|
---|
| 62 | // ----------------------------------------------------------------------------------------------------
|
---|
| 63 | /** RemoteGreenstoneServer Actions that can go into the remote GS server's ActionQueue.
|
---|
| 64 | * Contains many package access inner classes that are Actions.
|
---|
| 65 | */
|
---|
| 66 | public abstract class RemoteGreenstoneServerAction
|
---|
| 67 | {
|
---|
| 68 | public String action_output = null;
|
---|
| 69 | public boolean processed = false;
|
---|
| 70 | public boolean processed_successfully;
|
---|
| 71 |
|
---|
| 72 | protected RemoteGreenstoneServer remote = null;
|
---|
| 73 | protected RemoteGreenstoneServer.ProgressBar progress_bar = null;
|
---|
| 74 |
|
---|
| 75 | public RemoteGreenstoneServerAction() {
|
---|
| 76 | remote = Gatherer.remoteGreenstoneServer;
|
---|
| 77 | progress_bar = remote.getProgressBar();
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | abstract public void perform()
|
---|
| 81 | throws Exception;
|
---|
| 82 |
|
---|
| 83 | /*
|
---|
| 84 | protected String sendCommandToServer(String gliserver_args, GShell shell)
|
---|
| 85 | throws Exception
|
---|
| 86 | {
|
---|
| 87 | return Gatherer.remoteGreenstoneServer.sendCommandToServer(gliserver_args, shell);
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | protected void setAction(String action) {
|
---|
| 91 | Gatherer.remoteGreenstoneServer.progress_bar.setAction(action);
|
---|
| 92 | }*/
|
---|
| 93 |
|
---|
| 94 | static class ActionCancelledException
|
---|
| 95 | extends Exception
|
---|
| 96 | {
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | /**
|
---|
| 100 | * --------------------------------------------------------------------------------------------
|
---|
| 101 | * DELETE COLLECTION
|
---|
| 102 | * --------------------------------------------------------------------------------------------
|
---|
| 103 | */
|
---|
| 104 | static class DeleteCollectionAction
|
---|
| 105 | extends RemoteGreenstoneServerAction
|
---|
| 106 | {
|
---|
| 107 | private String collection_name;
|
---|
| 108 |
|
---|
| 109 | public DeleteCollectionAction(String collection_name)
|
---|
| 110 | {
|
---|
| 111 | this.collection_name = collection_name;
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | public void perform()
|
---|
| 115 | throws Exception
|
---|
| 116 | {
|
---|
| 117 | progress_bar.setAction("Deleting collection " + collection_name + "...");
|
---|
| 118 |
|
---|
| 119 | String delete_collection_command = "cmd=delete-collection";
|
---|
| 120 | delete_collection_command += "&c=" + URLEncoder.encode(collection_name, "UTF-8");
|
---|
| 121 | action_output = remote.sendCommandToServer(delete_collection_command, null);
|
---|
| 122 | }
|
---|
| 123 | }
|
---|
| 124 |
|
---|
| 125 |
|
---|
| 126 | /**
|
---|
| 127 | * --------------------------------------------------------------------------------------------
|
---|
| 128 | * DELETE COLLECTION FILE
|
---|
| 129 | * --------------------------------------------------------------------------------------------
|
---|
| 130 | */
|
---|
| 131 | static class DeleteCollectionFileAction
|
---|
| 132 | extends RemoteGreenstoneServerAction
|
---|
| 133 | {
|
---|
| 134 | private String collection_name;
|
---|
| 135 | private File collection_file;
|
---|
| 136 |
|
---|
| 137 | public DeleteCollectionFileAction(String collection_name, File collection_file)
|
---|
| 138 | {
|
---|
| 139 | this.collection_name = collection_name;
|
---|
| 140 | this.collection_file = collection_file;
|
---|
| 141 | }
|
---|
| 142 |
|
---|
| 143 | public void perform()
|
---|
| 144 | throws Exception
|
---|
| 145 | {
|
---|
| 146 | String collection_directory_path = CollectionManager.getCollectionDirectoryPath(collection_name);
|
---|
| 147 | String collection_file_relative_path = remote.getPathRelativeToDirectory(collection_file, collection_directory_path);
|
---|
| 148 | collection_file_relative_path = collection_file_relative_path.replaceAll((Utility.isWindows() ? "\\\\" : "\\/"), "|");
|
---|
| 149 | progress_bar.setAction("Deleting collection file " + collection_file_relative_path + "...");
|
---|
| 150 |
|
---|
| 151 | String delete_collection_file_command = "cmd=delete-collection-file";
|
---|
| 152 | delete_collection_file_command += "&c=" + URLEncoder.encode(collection_name, "UTF-8");
|
---|
[18646] | 153 | delete_collection_file_command += "&file=" + Base64.encodeBytes(collection_file_relative_path.getBytes());
|
---|
[17612] | 154 | action_output = remote.sendCommandToServer(delete_collection_file_command, null);
|
---|
| 155 | }
|
---|
| 156 | }
|
---|
| 157 |
|
---|
| 158 |
|
---|
| 159 | /**
|
---|
| 160 | * --------------------------------------------------------------------------------------------
|
---|
| 161 | * DOWNLOAD COLLECTION
|
---|
| 162 | * --------------------------------------------------------------------------------------------
|
---|
| 163 | */
|
---|
| 164 | static class DownloadCollectionAction
|
---|
| 165 | extends RemoteGreenstoneServerAction
|
---|
| 166 | {
|
---|
| 167 | private String collection_name;
|
---|
| 168 |
|
---|
| 169 | public DownloadCollectionAction(String collection_name)
|
---|
| 170 | {
|
---|
| 171 | this.collection_name = collection_name;
|
---|
| 172 | }
|
---|
| 173 |
|
---|
| 174 | public void perform()
|
---|
| 175 | throws Exception
|
---|
| 176 | {
|
---|
| 177 | progress_bar.setAction("Downloading remote collection " + collection_name + "...");
|
---|
| 178 |
|
---|
| 179 | String download_collection_command = "cmd=download-collection";
|
---|
| 180 | download_collection_command += "&c=" + URLEncoder.encode(collection_name, "UTF-8");
|
---|
[19173] | 181 | download_collection_command += "&lr=" + remote.lang_region;
|
---|
[17612] | 182 | String zip_file_path = Gatherer.getCollectDirectoryPath() + collection_name + ".zip";
|
---|
| 183 | action_output = remote.downloadFile(download_collection_command, zip_file_path);
|
---|
| 184 |
|
---|
| 185 | // Delete the existing (local) collection directory
|
---|
| 186 | Utility.delete(new File(CollectionManager.getCollectionDirectoryPath(collection_name)));
|
---|
| 187 |
|
---|
| 188 | // Unzip the collection just downloaded
|
---|
| 189 | UnzipTools.unzipFile(zip_file_path, Gatherer.getCollectDirectoryPath());
|
---|
| 190 | }
|
---|
| 191 | }
|
---|
| 192 |
|
---|
| 193 |
|
---|
| 194 | /**
|
---|
| 195 | * --------------------------------------------------------------------------------------------
|
---|
| 196 | * DOWNLOAD COLLECTION ARCHIVES
|
---|
| 197 | * --------------------------------------------------------------------------------------------
|
---|
| 198 | */
|
---|
| 199 | static class DownloadCollectionArchivesAction
|
---|
| 200 | extends RemoteGreenstoneServerAction
|
---|
| 201 | {
|
---|
| 202 | private String collection_name;
|
---|
| 203 |
|
---|
| 204 | public DownloadCollectionArchivesAction(String collection_name)
|
---|
| 205 | {
|
---|
| 206 | this.collection_name = collection_name;
|
---|
| 207 | }
|
---|
| 208 |
|
---|
| 209 | public void perform()
|
---|
| 210 | throws Exception
|
---|
| 211 | {
|
---|
| 212 | progress_bar.setAction("Downloading collection archives for " + collection_name + "...");
|
---|
| 213 |
|
---|
| 214 | String download_collection_archives_command = "cmd=download-collection-archives";
|
---|
| 215 | download_collection_archives_command += "&c=" + URLEncoder.encode(collection_name, "UTF-8");
|
---|
[19173] | 216 | download_collection_archives_command += "&lr=" + remote.lang_region;
|
---|
[17612] | 217 | String zip_file_path = Gatherer.getCollectDirectoryPath() + collection_name + "-archives.zip";
|
---|
| 218 | action_output = remote.downloadFile(download_collection_archives_command, zip_file_path);
|
---|
| 219 |
|
---|
| 220 | // Delete the existing (local) collection archives
|
---|
| 221 | Utility.delete(new File(CollectionManager.getLoadedCollectionArchivesDirectoryPath()));
|
---|
| 222 |
|
---|
| 223 | // Unzip the collection archives just downloaded
|
---|
| 224 | UnzipTools.unzipFile(zip_file_path, Gatherer.getCollectDirectoryPath());
|
---|
| 225 | }
|
---|
| 226 | }
|
---|
| 227 |
|
---|
| 228 |
|
---|
| 229 | /**
|
---|
| 230 | * --------------------------------------------------------------------------------------------
|
---|
| 231 | * DOWNLOAD COLLECTION CONFIGURATIONS
|
---|
| 232 | * --------------------------------------------------------------------------------------------
|
---|
| 233 | */
|
---|
| 234 | static class DownloadCollectionConfigurationsAction
|
---|
| 235 | extends RemoteGreenstoneServerAction
|
---|
| 236 | {
|
---|
| 237 | public DownloadCollectionConfigurationsAction()
|
---|
| 238 | {
|
---|
| 239 | }
|
---|
| 240 |
|
---|
| 241 | public void perform()
|
---|
| 242 | throws Exception
|
---|
| 243 | {
|
---|
| 244 | progress_bar.setAction("Downloading collection configurations...");
|
---|
| 245 |
|
---|
| 246 | // Delete the existing (local) collect directory
|
---|
| 247 | Utility.delete(new File(Gatherer.getCollectDirectoryPath()));
|
---|
| 248 | new File(Gatherer.getCollectDirectoryPath()).mkdirs();
|
---|
| 249 |
|
---|
| 250 | String download_collection_configurations_command = "cmd=download-collection-configurations";
|
---|
[19173] | 251 | download_collection_configurations_command += "&lr=" + remote.lang_region;
|
---|
[17612] | 252 | String zip_file_path = Gatherer.getCollectDirectoryPath() + "collections.zip";
|
---|
| 253 | action_output = remote.downloadFile(download_collection_configurations_command, zip_file_path);
|
---|
| 254 |
|
---|
| 255 | // Unzip the collection configurations just downloaded
|
---|
| 256 | UnzipTools.unzipFile(zip_file_path, Gatherer.getCollectDirectoryPath());
|
---|
| 257 | }
|
---|
| 258 | }
|
---|
| 259 |
|
---|
| 260 | /**
|
---|
| 261 | * --------------------------------------------------------------------------------------------
|
---|
| 262 | * DISCOVERING WHAT VERSION THE REMOTE GREENSTONE SERVER IS (2 or 3)
|
---|
| 263 | * --------------------------------------------------------------------------------------------
|
---|
| 264 | */
|
---|
| 265 |
|
---|
| 266 | static class VersionAction
|
---|
| 267 | extends RemoteGreenstoneServerAction
|
---|
| 268 | {
|
---|
| 269 | public void perform()
|
---|
| 270 | throws Exception
|
---|
| 271 | {
|
---|
| 272 | action_output = remote.sendCommandToServer("cmd=greenstone-server-version", null);
|
---|
| 273 | }
|
---|
| 274 | }
|
---|
| 275 |
|
---|
| 276 | static class LibraryURLSuffixAction
|
---|
| 277 | extends RemoteGreenstoneServerAction
|
---|
| 278 | {
|
---|
| 279 | public void perform()
|
---|
| 280 | throws Exception
|
---|
| 281 | {
|
---|
| 282 | action_output = remote.sendCommandToServer("cmd=get-library-url-suffix", null);
|
---|
| 283 | }
|
---|
| 284 | }
|
---|
| 285 |
|
---|
| 286 | /**
|
---|
| 287 | * --------------------------------------------------------------------------------------------
|
---|
| 288 | * CHECKING IF A FILE/FOLDER EXISTS ON SERVER SIDE
|
---|
| 289 | * --------------------------------------------------------------------------------------------
|
---|
| 290 | */
|
---|
| 291 | static class ExistsAction
|
---|
| 292 | extends RemoteGreenstoneServerAction
|
---|
| 293 | {
|
---|
| 294 | private String collection_name;
|
---|
| 295 | private File collection_file;
|
---|
| 296 |
|
---|
| 297 | public ExistsAction(String collection_name, File collection_file)
|
---|
| 298 | {
|
---|
| 299 | this.collection_name = collection_name;
|
---|
| 300 | this.collection_file = collection_file;
|
---|
| 301 | }
|
---|
| 302 |
|
---|
| 303 | public void perform()
|
---|
| 304 | throws Exception
|
---|
| 305 | {
|
---|
| 306 | String collection_directory_path = CollectionManager.getCollectionDirectoryPath(collection_name);
|
---|
| 307 | String collection_file_relative_path = remote.getPathRelativeToDirectory(collection_file, collection_directory_path);
|
---|
| 308 | collection_file_relative_path = collection_file_relative_path.replaceAll((Utility.isWindows() ? "\\\\" : "\\/"), "|");
|
---|
| 309 | File file = new File(collection_directory_path, collection_file_relative_path);
|
---|
| 310 |
|
---|
| 311 | String file_exists_command = "cmd=file-exists";
|
---|
| 312 | file_exists_command += "&c=" + URLEncoder.encode(collection_name, "UTF-8");
|
---|
[18646] | 313 | // base64 encode the filename to preserve special characters
|
---|
| 314 | file_exists_command += "&file=" + Base64.encodeBytes(collection_file_relative_path.getBytes());
|
---|
| 315 |
|
---|
[17612] | 316 | // returns either "File <filename> exists" or "File <filename> does not exist"
|
---|
| 317 | // for the file/folder collection_file
|
---|
| 318 | action_output = remote.sendCommandToServer(file_exists_command, null);
|
---|
| 319 | }
|
---|
| 320 | }
|
---|
| 321 |
|
---|
| 322 |
|
---|
| 323 | /**
|
---|
| 324 | * --------------------------------------------------------------------------------------------
|
---|
| 325 | * DOWNLOAD COLLECTION FILE
|
---|
| 326 | * --------------------------------------------------------------------------------------------
|
---|
| 327 | */
|
---|
| 328 | static class DownloadCollectionFileAction
|
---|
| 329 | extends RemoteGreenstoneServerAction
|
---|
| 330 | {
|
---|
| 331 | private String collection_name;
|
---|
| 332 | private File collection_file;
|
---|
| 333 |
|
---|
| 334 | public DownloadCollectionFileAction(String collection_name, File collection_file)
|
---|
| 335 | {
|
---|
| 336 | this.collection_name = collection_name;
|
---|
| 337 | this.collection_file = collection_file;
|
---|
| 338 | }
|
---|
| 339 |
|
---|
| 340 | public void perform()
|
---|
| 341 | throws Exception
|
---|
| 342 | {
|
---|
| 343 | String collection_directory_path = CollectionManager.getCollectionDirectoryPath(collection_name);
|
---|
| 344 | String collection_file_relative_path = remote.getPathRelativeToDirectory(collection_file, collection_directory_path);
|
---|
| 345 | collection_file_relative_path = collection_file_relative_path.replaceAll((Utility.isWindows() ? "\\\\" : "\\/"), "|");
|
---|
| 346 | progress_bar.setAction("Downloading collection file " + collection_file_relative_path + "...");
|
---|
| 347 |
|
---|
| 348 | String download_collection_file_command = "cmd=download-collection-file";
|
---|
| 349 | download_collection_file_command += "&c=" + URLEncoder.encode(collection_name, "UTF-8");
|
---|
| 350 | download_collection_file_command += "&file=" + URLEncoder.encode(collection_file_relative_path, "UTF-8");
|
---|
[19173] | 351 | download_collection_file_command += "&lr=" + remote.lang_region;
|
---|
[17612] | 352 | String zip_file_name = collection_name + "-" + collection_file.getName() + ".zip";
|
---|
| 353 | String zip_file_path = collection_directory_path + zip_file_name;
|
---|
| 354 | action_output = remote.downloadFile(download_collection_file_command, zip_file_path);
|
---|
| 355 |
|
---|
| 356 | // Unzip the collection file just downloaded
|
---|
| 357 | UnzipTools.unzipFile(zip_file_path, collection_directory_path);
|
---|
| 358 | }
|
---|
| 359 | }
|
---|
| 360 |
|
---|
| 361 | /**
|
---|
| 362 | * --------------------------------------------------------------------------------------------
|
---|
| 363 | * DOWNLOAD web.xml FILE --for a remote GS3
|
---|
| 364 | * --------------------------------------------------------------------------------------------
|
---|
| 365 | */
|
---|
| 366 | static class DownloadWebXMLFileAction
|
---|
| 367 | extends RemoteGreenstoneServerAction
|
---|
| 368 | {
|
---|
| 369 | public DownloadWebXMLFileAction()
|
---|
| 370 | {}
|
---|
| 371 |
|
---|
| 372 | public void perform()
|
---|
| 373 | throws Exception
|
---|
| 374 | {
|
---|
| 375 | String web_xml_directory_path=(Configuration.gli_user_directory_path);
|
---|
| 376 | String download_web_xml_file_command = "cmd=download-web-xml-file";
|
---|
| 377 | download_web_xml_file_command += "&file=" + URLEncoder.encode("web.xml", "UTF-8");
|
---|
[19173] | 378 | download_web_xml_file_command += "&lr=" + remote.lang_region;
|
---|
[17612] | 379 | String zip_file_name = "web-xml.zip";
|
---|
| 380 | String zip_file_path = web_xml_directory_path + zip_file_name;
|
---|
| 381 | action_output = remote.downloadFile(download_web_xml_file_command, zip_file_path);
|
---|
| 382 |
|
---|
| 383 | // Unzip the web.xml file just downloaded
|
---|
| 384 | UnzipTools.unzipFile(zip_file_path,web_xml_directory_path);
|
---|
| 385 | }
|
---|
| 386 | }
|
---|
| 387 |
|
---|
| 388 | /**
|
---|
| 389 | * --------------------------------------------------------------------------------------------
|
---|
| 390 | * GET SCRIPT OPTIONS
|
---|
| 391 | * --------------------------------------------------------------------------------------------
|
---|
| 392 | */
|
---|
| 393 | static class GetScriptOptionsAction
|
---|
| 394 | extends RemoteGreenstoneServerAction
|
---|
| 395 | {
|
---|
| 396 | private String script_name;
|
---|
| 397 | private String script_arguments;
|
---|
| 398 |
|
---|
| 399 | public GetScriptOptionsAction(String script_name, String script_arguments)
|
---|
| 400 | {
|
---|
| 401 | this.script_name = script_name;
|
---|
| 402 | this.script_arguments = script_arguments;
|
---|
| 403 | }
|
---|
| 404 |
|
---|
| 405 | public void perform()
|
---|
| 406 | throws Exception
|
---|
| 407 | {
|
---|
| 408 | progress_bar.setAction("Getting options for " + script_name + "...");
|
---|
| 409 |
|
---|
| 410 | String get_script_options_command = "cmd=get-script-options";
|
---|
| 411 | get_script_options_command += "&script=" + script_name;
|
---|
| 412 | get_script_options_command += "&xml=";
|
---|
| 413 | get_script_options_command += "&language=" + Configuration.getLanguage();
|
---|
| 414 | get_script_options_command += script_arguments;
|
---|
| 415 | action_output = remote.sendCommandToServer(get_script_options_command, null);
|
---|
| 416 | }
|
---|
| 417 | }
|
---|
| 418 |
|
---|
| 419 | /**
|
---|
| 420 | * --------------------------------------------------------------------------------------------
|
---|
| 421 | * GET ALL NAMES OF SITES // for a remote GS3
|
---|
| 422 | * --------------------------------------------------------------------------------------------
|
---|
| 423 | */
|
---|
| 424 | static class GetSiteNamesAction
|
---|
| 425 | extends RemoteGreenstoneServerAction
|
---|
| 426 | {
|
---|
| 427 | public GetSiteNamesAction()
|
---|
| 428 | {}
|
---|
| 429 |
|
---|
| 430 | public void perform()
|
---|
| 431 | throws Exception
|
---|
| 432 | {
|
---|
| 433 | progress_bar.setAction("Getting names of sites ...");
|
---|
| 434 |
|
---|
| 435 | String get_script_options_command = "cmd=get-site-names";
|
---|
| 436 | action_output = remote.sendCommandToServer(get_script_options_command, null);
|
---|
| 437 | }
|
---|
| 438 | }
|
---|
| 439 |
|
---|
| 440 | /**
|
---|
| 441 | * --------------------------------------------------------------------------------------------
|
---|
| 442 | * MOVE COLLECTION FILE
|
---|
| 443 | * --------------------------------------------------------------------------------------------
|
---|
| 444 | */
|
---|
| 445 | static class MoveCollectionFileAction
|
---|
| 446 | extends RemoteGreenstoneServerAction
|
---|
| 447 | {
|
---|
| 448 | private String collection_name;
|
---|
| 449 | private File source_collection_file;
|
---|
| 450 | private File target_collection_file;
|
---|
| 451 |
|
---|
| 452 | public MoveCollectionFileAction(String collection_name, File source_collection_file, File target_collection_file)
|
---|
| 453 | {
|
---|
| 454 | this.collection_name = collection_name;
|
---|
| 455 | this.source_collection_file = source_collection_file;
|
---|
| 456 | this.target_collection_file = target_collection_file;
|
---|
| 457 | }
|
---|
| 458 |
|
---|
| 459 | public void perform()
|
---|
| 460 | throws Exception
|
---|
| 461 | {
|
---|
| 462 | String collection_directory_path = CollectionManager.getCollectionDirectoryPath(collection_name);
|
---|
| 463 | String source_collection_file_relative_path = remote.getPathRelativeToDirectory(
|
---|
| 464 | source_collection_file, collection_directory_path);
|
---|
| 465 | source_collection_file_relative_path = source_collection_file_relative_path.replaceAll((Utility.isWindows() ? "\\\\" : "\\/"), "|");
|
---|
| 466 | String target_collection_file_relative_path = remote.getPathRelativeToDirectory(
|
---|
| 467 | target_collection_file, collection_directory_path);
|
---|
| 468 | target_collection_file_relative_path = target_collection_file_relative_path.replaceAll((Utility.isWindows() ? "\\\\" : "\\/"), "|");
|
---|
| 469 | progress_bar.setAction("Moving file " + source_collection_file_relative_path + " -> " + target_collection_file_relative_path + "...");
|
---|
| 470 |
|
---|
| 471 | String move_collection_file_command = "cmd=move-collection-file";
|
---|
| 472 | move_collection_file_command += "&c=" + URLEncoder.encode(collection_name, "UTF-8");
|
---|
[19231] | 473 | move_collection_file_command += "&source=" + Base64.encodeBytes(source_collection_file_relative_path.getBytes());
|
---|
| 474 | move_collection_file_command += "&target=" + Base64.encodeBytes(target_collection_file_relative_path.getBytes());
|
---|
| 475 | //move_collection_file_command += "&source=" + URLEncoder.encode(source_collection_file_relative_path, "UTF-8");
|
---|
| 476 | //move_collection_file_command += "&target=" + URLEncoder.encode(target_collection_file_relative_path, "UTF-8");
|
---|
[17612] | 477 | action_output = remote.sendCommandToServer(move_collection_file_command, null);
|
---|
| 478 | }
|
---|
| 479 | }
|
---|
| 480 |
|
---|
| 481 |
|
---|
| 482 | /**
|
---|
| 483 | * --------------------------------------------------------------------------------------------
|
---|
| 484 | * NEW COLLECTION DIRECTORY
|
---|
| 485 | * --------------------------------------------------------------------------------------------
|
---|
| 486 | */
|
---|
| 487 | static class NewCollectionDirectoryAction
|
---|
| 488 | extends RemoteGreenstoneServerAction
|
---|
| 489 | {
|
---|
| 490 | private String collection_name;
|
---|
| 491 | private File new_collection_directory;
|
---|
| 492 |
|
---|
| 493 | public NewCollectionDirectoryAction(String collection_name, File new_collection_directory)
|
---|
| 494 | {
|
---|
| 495 | this.collection_name = collection_name;
|
---|
| 496 | this.new_collection_directory = new_collection_directory;
|
---|
| 497 | }
|
---|
| 498 |
|
---|
| 499 | public void perform()
|
---|
| 500 | throws Exception
|
---|
| 501 | {
|
---|
| 502 | String collection_directory_path = CollectionManager.getCollectionDirectoryPath(collection_name);
|
---|
| 503 | String new_collection_directory_relative_path = remote.getPathRelativeToDirectory(
|
---|
| 504 | new_collection_directory, collection_directory_path);
|
---|
| 505 | new_collection_directory_relative_path = new_collection_directory_relative_path.replaceAll((Utility.isWindows() ? "\\\\" : "\\/"), "|");
|
---|
| 506 | progress_bar.setAction("Creating new directory " + new_collection_directory_relative_path + "...");
|
---|
| 507 |
|
---|
| 508 | String new_collection_directory_command = "cmd=new-collection-directory";
|
---|
| 509 | new_collection_directory_command += "&c=" + URLEncoder.encode(collection_name, "UTF-8");
|
---|
| 510 | new_collection_directory_command += "&directory=" + URLEncoder.encode(new_collection_directory_relative_path, "UTF-8");
|
---|
| 511 | action_output = remote.sendCommandToServer(new_collection_directory_command, null);
|
---|
| 512 | }
|
---|
| 513 | }
|
---|
| 514 |
|
---|
| 515 |
|
---|
| 516 | /**
|
---|
| 517 | * --------------------------------------------------------------------------------------------
|
---|
| 518 | * RUN SCRIPT
|
---|
| 519 | * --------------------------------------------------------------------------------------------
|
---|
| 520 | */
|
---|
| 521 | static class RunScriptAction
|
---|
| 522 | extends RemoteGreenstoneServerAction
|
---|
| 523 | {
|
---|
| 524 | private String collection_name;
|
---|
| 525 | private String script_name;
|
---|
| 526 | private String script_arguments;
|
---|
| 527 | private GShell shell;
|
---|
| 528 |
|
---|
| 529 | public RunScriptAction(String collection_name, String script_name, String script_arguments, GShell shell)
|
---|
| 530 | {
|
---|
| 531 | this.collection_name = collection_name;
|
---|
| 532 | this.script_name = script_name;
|
---|
| 533 | this.script_arguments = script_arguments;
|
---|
| 534 | this.shell = shell;
|
---|
| 535 | }
|
---|
| 536 |
|
---|
| 537 | public void perform()
|
---|
| 538 | throws Exception
|
---|
| 539 | {
|
---|
| 540 | progress_bar.setAction("Running " + script_name + "...");
|
---|
| 541 |
|
---|
| 542 | String run_script_command = "cmd=run-script";
|
---|
| 543 | run_script_command += "&c=" + URLEncoder.encode(collection_name, "UTF-8");
|
---|
| 544 | run_script_command += "&script=" + script_name;
|
---|
| 545 | run_script_command += "&language=" + Configuration.getLanguage();
|
---|
| 546 | run_script_command += script_arguments;
|
---|
| 547 | action_output = remote.sendCommandToServer(run_script_command, shell);
|
---|
| 548 | }
|
---|
| 549 | }
|
---|
| 550 |
|
---|
| 551 |
|
---|
| 552 | /**
|
---|
| 553 | * --------------------------------------------------------------------------------------------
|
---|
| 554 | * UPLOAD COLLECTION FILE
|
---|
| 555 | * --------------------------------------------------------------------------------------------
|
---|
| 556 | */
|
---|
| 557 | static class UploadCollectionFilesAction
|
---|
| 558 | extends RemoteGreenstoneServerAction
|
---|
| 559 | {
|
---|
| 560 | private String collection_name;
|
---|
| 561 | private File[] collection_files;
|
---|
| 562 |
|
---|
| 563 |
|
---|
| 564 | public UploadCollectionFilesAction(String collection_name, File[] collection_files)
|
---|
| 565 | {
|
---|
| 566 | this.collection_name = collection_name;
|
---|
| 567 | this.collection_files = collection_files;
|
---|
| 568 | }
|
---|
| 569 |
|
---|
| 570 |
|
---|
| 571 | public void perform()
|
---|
| 572 | throws Exception
|
---|
| 573 | {
|
---|
| 574 | progress_bar.setAction("Uploading collection files...");
|
---|
| 575 |
|
---|
| 576 | // Determine the file paths relative to the collection directory
|
---|
| 577 | String collection_directory_path = CollectionManager.getCollectionDirectoryPath(collection_name);
|
---|
| 578 | String[] collection_file_relative_paths = new String[collection_files.length];
|
---|
| 579 | for (int i = 0; i < collection_files.length; i++) {
|
---|
| 580 | collection_file_relative_paths[i] = remote.getPathRelativeToDirectory(collection_files[i], collection_directory_path);
|
---|
| 581 | }
|
---|
| 582 |
|
---|
| 583 | // Zip up the files to send to the server
|
---|
| 584 | String zip_file_name = collection_name + "-" + System.currentTimeMillis() + ".zip";
|
---|
| 585 | String zip_file_path = collection_directory_path + zip_file_name;
|
---|
| 586 | ZipTools.zipFiles(zip_file_path, collection_directory_path, collection_file_relative_paths);
|
---|
| 587 |
|
---|
| 588 | // Upload the zip file
|
---|
| 589 | String upload_collection_file_command = "cmd=upload-collection-file";
|
---|
| 590 | upload_collection_file_command += "&c=" + URLEncoder.encode(collection_name, "UTF-8");
|
---|
| 591 | upload_collection_file_command += "&file=" + URLEncoder.encode(zip_file_name, "UTF-8");
|
---|
| 592 | upload_collection_file_command += "&directory=";
|
---|
| 593 | upload_collection_file_command += "&zip=true";
|
---|
[19173] | 594 | upload_collection_file_command += "&lr=" + remote.lang_region;
|
---|
[17612] | 595 | action_output = remote.uploadFile(upload_collection_file_command, zip_file_path);
|
---|
| 596 | }
|
---|
| 597 | }
|
---|
| 598 |
|
---|
| 599 |
|
---|
| 600 | /**
|
---|
| 601 | * --------------------------------------------------------------------------------------------
|
---|
| 602 | * UPLOAD FILES INTO COLLECTION
|
---|
| 603 | * --------------------------------------------------------------------------------------------
|
---|
| 604 | */
|
---|
| 605 | static class UploadFilesIntoCollectionAction
|
---|
| 606 | extends RemoteGreenstoneServerAction
|
---|
| 607 | {
|
---|
| 608 | private String collection_name;
|
---|
| 609 | private File[] source_files;
|
---|
| 610 | private File target_collection_directory;
|
---|
| 611 |
|
---|
| 612 |
|
---|
| 613 | public UploadFilesIntoCollectionAction(String collection_name, File[] source_files, File target_collection_directory)
|
---|
| 614 | {
|
---|
| 615 | this.collection_name = collection_name;
|
---|
| 616 | this.source_files = source_files;
|
---|
| 617 | this.target_collection_directory = target_collection_directory;
|
---|
| 618 | }
|
---|
| 619 |
|
---|
| 620 |
|
---|
| 621 | public void perform()
|
---|
| 622 | throws Exception
|
---|
| 623 | {
|
---|
| 624 | String collection_directory_path = CollectionManager.getCollectionDirectoryPath(collection_name);
|
---|
| 625 | String target_collection_directory_relative_path = remote.getPathRelativeToDirectory(
|
---|
| 626 | target_collection_directory, collection_directory_path);
|
---|
| 627 | target_collection_directory_relative_path = target_collection_directory_relative_path.replaceAll((Utility.isWindows() ? "\\\\" : "\\/"), "|");
|
---|
| 628 | progress_bar.setAction("Uploading files into collection...");
|
---|
| 629 |
|
---|
| 630 | String zip_file_name = collection_name + "-" + System.currentTimeMillis() + ".zip";
|
---|
| 631 | String zip_file_path = Gatherer.getCollectDirectoryPath() + zip_file_name;
|
---|
| 632 | DebugStream.println("Zip file path: " + zip_file_path);
|
---|
| 633 |
|
---|
| 634 | String base_directory_path = source_files[0].getParentFile().getAbsolutePath();
|
---|
| 635 | DebugStream.println("Base directory path: " + base_directory_path);
|
---|
| 636 | String[] source_file_relative_paths = new String[source_files.length];
|
---|
| 637 | for (int i = 0; i < source_files.length; i++) {
|
---|
| 638 | DebugStream.println("Source file path: " + source_files[i]);
|
---|
| 639 | source_file_relative_paths[i] = remote.getPathRelativeToDirectory(source_files[i], base_directory_path);
|
---|
| 640 | }
|
---|
| 641 |
|
---|
| 642 | ZipTools.zipFiles(zip_file_path, base_directory_path, source_file_relative_paths);
|
---|
| 643 |
|
---|
| 644 | String upload_collection_file_command = "cmd=upload-collection-file";
|
---|
| 645 | upload_collection_file_command += "&c=" + URLEncoder.encode(collection_name, "UTF-8");
|
---|
| 646 | upload_collection_file_command += "&file=" + URLEncoder.encode(zip_file_name, "UTF-8");
|
---|
| 647 | upload_collection_file_command += "&directory=" + URLEncoder.encode(target_collection_directory_relative_path, "UTF-8");
|
---|
| 648 | upload_collection_file_command += "&zip=true";
|
---|
[19173] | 649 | upload_collection_file_command += "&lr=" + remote.lang_region;
|
---|
[17612] | 650 | action_output = remote.uploadFile(upload_collection_file_command, zip_file_path);
|
---|
| 651 | }
|
---|
| 652 | }
|
---|
[18646] | 653 | }
|
---|