source: main/trunk/gli/src/org/greenstone/gatherer/remote/RemoteGreenstoneServerAction.java@ 22454

Last change on this file since 22454 was 22454, checked in by ak19, 14 years ago

3rd commit to do with getting Remote GLI to work with colgroups: changes to GLI code to adjust for instances where the collection group and tail names need to be carefully used to get the zip file path and zip file name right.

File size: 27.5 KB
Line 
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
28package org.greenstone.gatherer.remote;
29
30import java.io.*;
31import java.net.*;
32import java.util.*;
33import java.util.zip.*;
34import javax.swing.*;
35import java.io.ByteArrayOutputStream;
36import org.greenstone.gatherer.Configuration;
37import org.greenstone.gatherer.DebugStream;
38import org.greenstone.gatherer.Dictionary;
39import org.greenstone.gatherer.FedoraInfo;
40import org.greenstone.gatherer.GAuthenticator;
41import org.greenstone.gatherer.Gatherer;
42import org.greenstone.gatherer.collection.CollectionManager;
43import org.greenstone.gatherer.feedback.Base64;
44import org.greenstone.gatherer.shell.GShell;
45import org.greenstone.gatherer.util.UnzipTools;
46import org.greenstone.gatherer.util.Utility;
47import org.apache.commons.httpclient.HttpClient;
48import org.apache.commons.httpclient.methods.PostMethod;
49import org.apache.commons.httpclient.methods.GetMethod;
50import org.apache.commons.httpclient.HttpException;
51import org.apache.commons.httpclient.methods.multipart.FilePart;
52import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
53import org.apache.commons.httpclient.methods.multipart.Part;
54import org.apache.commons.httpclient.methods.multipart.*;
55import org.apache.commons.httpclient.params.*;
56import 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*/
66public 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.replace(File.separatorChar, '|'), "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.replace(File.separatorChar, '|'), "UTF-8");
153 delete_collection_file_command += "&file=" + Base64.encodeBytes(collection_file_relative_path.getBytes());
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.replace(File.separatorChar, '|'), "UTF-8");
181 download_collection_command += "&lr=" + remote.lang_region;
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.replace(File.separatorChar, '|'), "UTF-8");
216 download_collection_archives_command += "&lr=" + remote.lang_region;
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";
251 download_collection_configurations_command += "&lr=" + remote.lang_region;
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.replace(File.separatorChar, '|'), "UTF-8");
313 // base64 encode the filename to preserve special characters
314 file_exists_command += "&file=" + Base64.encodeBytes(collection_file_relative_path.getBytes());
315
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.replace(File.separatorChar, '|'), "UTF-8");
350 download_collection_file_command += "&file=" + URLEncoder.encode(collection_file_relative_path, "UTF-8");
351 download_collection_file_command += "&lr=" + remote.lang_region;
352
353 // String zip_file_name = collection_name + "-" + collection_file.getName() + ".zip";
354 // String zip_file_path = collection_directory_path + zip_file_name;
355 String zip_file_path = Gatherer.getCollectDirectoryPath() + collection_name + "-" + collection_file.getName() + ".zip"; // collect/(colgroup/)coltail/colfile.zip
356 action_output = remote.downloadFile(download_collection_file_command, zip_file_path);
357
358 // Unzip the collection file just downloaded
359 UnzipTools.unzipFile(zip_file_path, collection_directory_path);
360 }
361 }
362
363 /**
364 * --------------------------------------------------------------------------------------------
365 * DOWNLOAD web.xml FILE --for a remote GS3
366 * --------------------------------------------------------------------------------------------
367 */
368 static class DownloadWebXMLFileAction
369 extends RemoteGreenstoneServerAction
370 {
371 public DownloadWebXMLFileAction()
372 {}
373
374 public void perform()
375 throws Exception
376 {
377 String web_xml_directory_path=(Configuration.gli_user_directory_path);
378 String download_web_xml_file_command = "cmd=download-web-xml-file";
379 download_web_xml_file_command += "&file=" + URLEncoder.encode("web.xml", "UTF-8");
380 download_web_xml_file_command += "&lr=" + remote.lang_region;
381 String zip_file_name = "web-xml.zip";
382 String zip_file_path = web_xml_directory_path + zip_file_name;
383 action_output = remote.downloadFile(download_web_xml_file_command, zip_file_path);
384
385 // Unzip the web.xml file just downloaded
386 UnzipTools.unzipFile(zip_file_path,web_xml_directory_path);
387 }
388 }
389
390 /**
391 * --------------------------------------------------------------------------------------------
392 * GET SCRIPT OPTIONS
393 * --------------------------------------------------------------------------------------------
394 */
395 static class GetScriptOptionsAction
396 extends RemoteGreenstoneServerAction
397 {
398 private String script_name;
399 private String script_arguments;
400
401 public GetScriptOptionsAction(String script_name, String script_arguments)
402 {
403 this.script_name = script_name;
404 this.script_arguments = script_arguments;
405 }
406
407 public void perform()
408 throws Exception
409 {
410 progress_bar.setAction("Getting options for " + script_name + "...");
411
412 String get_script_options_command = "cmd=get-script-options";
413 get_script_options_command += "&script=" + script_name;
414 get_script_options_command += "&xml=";
415 get_script_options_command += "&language=" + Configuration.getLanguage();
416 get_script_options_command += script_arguments;
417 action_output = remote.sendCommandToServer(get_script_options_command, null);
418 }
419 }
420
421 /**
422 * --------------------------------------------------------------------------------------------
423 * GET ALL NAMES OF SITES // for a remote GS3
424 * --------------------------------------------------------------------------------------------
425 */
426 static class GetSiteNamesAction
427 extends RemoteGreenstoneServerAction
428 {
429 public GetSiteNamesAction()
430 {}
431
432 public void perform()
433 throws Exception
434 {
435 progress_bar.setAction("Getting names of sites ...");
436
437 String get_script_options_command = "cmd=get-site-names";
438 action_output = remote.sendCommandToServer(get_script_options_command, null);
439 }
440 }
441
442 /**
443 * --------------------------------------------------------------------------------------------
444 * MOVE COLLECTION FILE
445 * --------------------------------------------------------------------------------------------
446 */
447 static class MoveCollectionFileAction
448 extends RemoteGreenstoneServerAction
449 {
450 private String collection_name;
451 private File source_collection_file;
452 private File target_collection_file;
453
454 public MoveCollectionFileAction(String collection_name, File source_collection_file, File target_collection_file)
455 {
456 this.collection_name = collection_name;
457 this.source_collection_file = source_collection_file;
458 this.target_collection_file = target_collection_file;
459 }
460
461 public void perform()
462 throws Exception
463 {
464 String collection_directory_path = CollectionManager.getCollectionDirectoryPath(collection_name);
465 String source_collection_file_relative_path = remote.getPathRelativeToDirectory(
466 source_collection_file, collection_directory_path);
467 source_collection_file_relative_path = source_collection_file_relative_path.replaceAll((Utility.isWindows() ? "\\\\" : "\\/"), "|");
468 String target_collection_file_relative_path = remote.getPathRelativeToDirectory(
469 target_collection_file, collection_directory_path);
470 target_collection_file_relative_path = target_collection_file_relative_path.replaceAll((Utility.isWindows() ? "\\\\" : "\\/"), "|");
471 progress_bar.setAction("Moving file " + source_collection_file_relative_path + " -> " + target_collection_file_relative_path + "...");
472
473 String move_collection_file_command = "cmd=move-collection-file";
474 move_collection_file_command += "&c=" + URLEncoder.encode(collection_name.replace(File.separatorChar, '|'), "UTF-8");
475 move_collection_file_command += "&source=" + Base64.encodeBytes(source_collection_file_relative_path.getBytes());
476 move_collection_file_command += "&target=" + Base64.encodeBytes(target_collection_file_relative_path.getBytes());
477 //move_collection_file_command += "&source=" + URLEncoder.encode(source_collection_file_relative_path, "UTF-8");
478 //move_collection_file_command += "&target=" + URLEncoder.encode(target_collection_file_relative_path, "UTF-8");
479 action_output = remote.sendCommandToServer(move_collection_file_command, null);
480 }
481 }
482
483
484 /**
485 * --------------------------------------------------------------------------------------------
486 * NEW COLLECTION DIRECTORY
487 * --------------------------------------------------------------------------------------------
488 */
489 static class NewCollectionDirectoryAction
490 extends RemoteGreenstoneServerAction
491 {
492 private String collection_name;
493 private File new_collection_directory;
494
495 public NewCollectionDirectoryAction(String collection_name, File new_collection_directory)
496 {
497 this.collection_name = collection_name;
498 this.new_collection_directory = new_collection_directory;
499 }
500
501 public void perform()
502 throws Exception
503 {
504 String collection_directory_path = CollectionManager.getCollectionDirectoryPath(collection_name);
505 String new_collection_directory_relative_path = remote.getPathRelativeToDirectory(
506 new_collection_directory, collection_directory_path);
507 new_collection_directory_relative_path = new_collection_directory_relative_path.replaceAll((Utility.isWindows() ? "\\\\" : "\\/"), "|");
508 progress_bar.setAction("Creating new directory " + new_collection_directory_relative_path + "...");
509
510 String new_collection_directory_command = "cmd=new-collection-directory";
511 new_collection_directory_command += "&c=" + URLEncoder.encode(collection_name.replace(File.separatorChar, '|'), "UTF-8");
512 new_collection_directory_command += "&directory=" + URLEncoder.encode(new_collection_directory_relative_path, "UTF-8");
513 action_output = remote.sendCommandToServer(new_collection_directory_command, null);
514 }
515 }
516
517
518 /**
519 * --------------------------------------------------------------------------------------------
520 * RUN SCRIPT
521 * --------------------------------------------------------------------------------------------
522 */
523 static class RunScriptAction
524 extends RemoteGreenstoneServerAction
525 {
526 private String collection_name;
527 private String script_name;
528 private String script_arguments;
529 private GShell shell;
530
531 public RunScriptAction(String collection_name, String script_name, String script_arguments, GShell shell)
532 {
533 this.collection_name = collection_name;
534 this.script_name = script_name;
535 this.script_arguments = script_arguments;
536 this.shell = shell;
537 }
538
539 public void perform()
540 throws Exception
541 {
542 progress_bar.setAction("Running " + script_name + "...");
543
544 String run_script_command = "cmd=run-script";
545 run_script_command += "&c=" + URLEncoder.encode(collection_name.replace(File.separatorChar, '|'), "UTF-8");
546 run_script_command += "&script=" + script_name;
547 run_script_command += "&language=" + Configuration.getLanguage();
548 run_script_command += script_arguments;
549 action_output = remote.sendCommandToServer(run_script_command, shell);
550 }
551 }
552
553
554 /**
555 * --------------------------------------------------------------------------------------------
556 * UPLOAD COLLECTION FILE
557 * --------------------------------------------------------------------------------------------
558 */
559 static class UploadCollectionFilesAction
560 extends RemoteGreenstoneServerAction
561 {
562 private String collection_name;
563 private File[] collection_files;
564
565
566 public UploadCollectionFilesAction(String collection_name, File[] collection_files)
567 {
568 this.collection_name = collection_name;
569 this.collection_files = collection_files;
570 }
571
572
573 public void perform()
574 throws Exception
575 {
576 progress_bar.setAction("Uploading collection files...");
577
578 // Determine the file paths relative to the collection directory
579 String collection_directory_path = CollectionManager.getCollectionDirectoryPath(collection_name);
580 String[] collection_file_relative_paths = new String[collection_files.length];
581 for (int i = 0; i < collection_files.length; i++) {
582 collection_file_relative_paths[i] = remote.getPathRelativeToDirectory(collection_files[i], collection_directory_path);
583 }
584
585 // Zip up the files to send to the server
586 //String zip_file_name = collection_name + "-" + System.currentTimeMillis() + ".zip";
587 //String zip_file_path = collection_directory_path + zip_file_name;
588 String zip_file_path = collection_directory_path; // collect/(colgroup/)coltail/
589 String zip_file_name = new File(zip_file_path).getName() + "-" + System.currentTimeMillis() + ".zip"; // <collection_tail_name>-<time>.zip
590 zip_file_path += zip_file_name; // collect/(colgroup/)coltail/coltail-time.zip
591 ZipTools.zipFiles(zip_file_path, collection_directory_path, collection_file_relative_paths);
592
593 // Upload the zip file
594 String upload_collection_file_command = "cmd=upload-collection-file";
595 upload_collection_file_command += "&c=" + URLEncoder.encode(collection_name.replace(File.separatorChar, '|'), "UTF-8");
596 upload_collection_file_command += "&file=" + URLEncoder.encode(zip_file_name, "UTF-8");
597 upload_collection_file_command += "&directory=";
598 upload_collection_file_command += "&zip=true";
599 upload_collection_file_command += "&lr=" + remote.lang_region;
600 action_output = remote.uploadFile(upload_collection_file_command, zip_file_path);
601 }
602 }
603
604
605 /**
606 * --------------------------------------------------------------------------------------------
607 * UPLOAD FILES INTO COLLECTION
608 * --------------------------------------------------------------------------------------------
609 */
610 static class UploadFilesIntoCollectionAction
611 extends RemoteGreenstoneServerAction
612 {
613 private String collection_name;
614 private File[] source_files;
615 private File target_collection_directory;
616
617
618 public UploadFilesIntoCollectionAction(String collection_name, File[] source_files, File target_collection_directory)
619 {
620 this.collection_name = collection_name;
621 this.source_files = source_files;
622 this.target_collection_directory = target_collection_directory;
623 }
624
625
626 public void perform()
627 throws Exception
628 {
629 String collection_directory_path = CollectionManager.getCollectionDirectoryPath(collection_name);
630 String target_collection_directory_relative_path = remote.getPathRelativeToDirectory(
631 target_collection_directory, collection_directory_path);
632 target_collection_directory_relative_path = target_collection_directory_relative_path.replaceAll((Utility.isWindows() ? "\\\\" : "\\/"), "|");
633 progress_bar.setAction("Uploading files into collection...");
634
635 //String zip_file_name = collection_name + "-" + System.currentTimeMillis() + ".zip";
636 //String zip_file_path = Gatherer.getCollectDirectoryPath() + zip_file_name;
637 String zip_file_path = Gatherer.getCollectDirectoryPath()
638 + collection_name + "-" + System.currentTimeMillis() + ".zip"; // "collect/(colgroup/)collection_tail_name-<time>.zip"
639 String zip_file_name = new File(zip_file_path).getName(); // "collection_tail_name-<time>.zip"
640 DebugStream.println("Zip file path: " + zip_file_path);
641
642 String base_directory_path = source_files[0].getParentFile().getAbsolutePath();
643 DebugStream.println("Base directory path: " + base_directory_path);
644 String[] source_file_relative_paths = new String[source_files.length];
645 for (int i = 0; i < source_files.length; i++) {
646 DebugStream.println("Source file path: " + source_files[i]);
647 source_file_relative_paths[i] = remote.getPathRelativeToDirectory(source_files[i], base_directory_path);
648 }
649
650 ZipTools.zipFiles(zip_file_path, base_directory_path, source_file_relative_paths);
651
652 String upload_collection_file_command = "cmd=upload-collection-file";
653 upload_collection_file_command += "&c=" + URLEncoder.encode(collection_name.replace(File.separatorChar, '|'), "UTF-8");
654 upload_collection_file_command += "&file=" + URLEncoder.encode(zip_file_name, "UTF-8");
655 upload_collection_file_command += "&directory=" + URLEncoder.encode(target_collection_directory_relative_path, "UTF-8");
656 upload_collection_file_command += "&zip=true";
657 upload_collection_file_command += "&lr=" + remote.lang_region;
658 action_output = remote.uploadFile(upload_collection_file_command, zip_file_path);
659 }
660 }
661}
Note: See TracBrowser for help on using the repository browser.