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;
|
---|
43 | import org.greenstone.gatherer.feedback.Base64;
|
---|
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.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.encodeBytesInSingleLine(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.encodeBytesInSingleLine(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 | // classinfo.pl script has a "collection" argument. Convert any colgroup/coltail to colgroup|coltail:
|
---|
406 | // (Note that this may be the only method here that does not url encode the collection name before sendit it to the server)
|
---|
407 | this.script_arguments = script_arguments.replace(File.separatorChar, '|');
|
---|
408 | }
|
---|
409 |
|
---|
410 | public void perform()
|
---|
411 | throws Exception
|
---|
412 | {
|
---|
413 | progress_bar.setAction("Getting options for " + script_name + "...");
|
---|
414 |
|
---|
415 | String get_script_options_command = "cmd=get-script-options";
|
---|
416 | get_script_options_command += "&script=" + script_name;
|
---|
417 | get_script_options_command += "&xml=";
|
---|
418 | get_script_options_command += "&language=" + Configuration.getLanguage();
|
---|
419 | get_script_options_command += script_arguments;
|
---|
420 | action_output = remote.sendCommandToServer(get_script_options_command, null);
|
---|
421 | }
|
---|
422 | }
|
---|
423 |
|
---|
424 | /**
|
---|
425 | * --------------------------------------------------------------------------------------------
|
---|
426 | * GET ALL NAMES OF SITES // for a remote GS3
|
---|
427 | * --------------------------------------------------------------------------------------------
|
---|
428 | */
|
---|
429 | static class GetSiteNamesAction
|
---|
430 | extends RemoteGreenstoneServerAction
|
---|
431 | {
|
---|
432 | public GetSiteNamesAction()
|
---|
433 | {}
|
---|
434 |
|
---|
435 | public void perform()
|
---|
436 | throws Exception
|
---|
437 | {
|
---|
438 | progress_bar.setAction("Getting names of sites ...");
|
---|
439 |
|
---|
440 | String get_script_options_command = "cmd=get-site-names";
|
---|
441 | action_output = remote.sendCommandToServer(get_script_options_command, null);
|
---|
442 | }
|
---|
443 | }
|
---|
444 |
|
---|
445 | /**
|
---|
446 | * --------------------------------------------------------------------------------------------
|
---|
447 | * MOVE COLLECTION FILE
|
---|
448 | * --------------------------------------------------------------------------------------------
|
---|
449 | */
|
---|
450 | static class MoveCollectionFileAction
|
---|
451 | extends RemoteGreenstoneServerAction
|
---|
452 | {
|
---|
453 | private String collection_name;
|
---|
454 | private File source_collection_file;
|
---|
455 | private File target_collection_file;
|
---|
456 |
|
---|
457 | public MoveCollectionFileAction(String collection_name, File source_collection_file, File target_collection_file)
|
---|
458 | {
|
---|
459 | this.collection_name = collection_name;
|
---|
460 | this.source_collection_file = source_collection_file;
|
---|
461 | this.target_collection_file = target_collection_file;
|
---|
462 | }
|
---|
463 |
|
---|
464 | public void perform()
|
---|
465 | throws Exception
|
---|
466 | {
|
---|
467 | String collection_directory_path = CollectionManager.getCollectionDirectoryPath(collection_name);
|
---|
468 | String source_collection_file_relative_path = remote.getPathRelativeToDirectory(
|
---|
469 | source_collection_file, collection_directory_path);
|
---|
470 | source_collection_file_relative_path = source_collection_file_relative_path.replaceAll((Utility.isWindows() ? "\\\\" : "\\/"), "|");
|
---|
471 | String target_collection_file_relative_path = remote.getPathRelativeToDirectory(
|
---|
472 | target_collection_file, collection_directory_path);
|
---|
473 | target_collection_file_relative_path = target_collection_file_relative_path.replaceAll((Utility.isWindows() ? "\\\\" : "\\/"), "|");
|
---|
474 | progress_bar.setAction("Moving file " + source_collection_file_relative_path + " -> " + target_collection_file_relative_path + "...");
|
---|
475 |
|
---|
476 | String move_collection_file_command = "cmd=move-collection-file";
|
---|
477 | move_collection_file_command += "&c=" + URLEncoder.encode(collection_name.replace(File.separatorChar, '|'), "UTF-8");
|
---|
478 | move_collection_file_command += "&source=" + Base64.encodeBytesInSingleLine(source_collection_file_relative_path.getBytes());
|
---|
479 | move_collection_file_command += "&target=" + Base64.encodeBytesInSingleLine(target_collection_file_relative_path.getBytes());
|
---|
480 | //move_collection_file_command += "&source=" + URLEncoder.encode(source_collection_file_relative_path, "UTF-8");
|
---|
481 | //move_collection_file_command += "&target=" + URLEncoder.encode(target_collection_file_relative_path, "UTF-8");
|
---|
482 | action_output = remote.sendCommandToServer(move_collection_file_command, null);
|
---|
483 | }
|
---|
484 | }
|
---|
485 |
|
---|
486 |
|
---|
487 | /**
|
---|
488 | * --------------------------------------------------------------------------------------------
|
---|
489 | * NEW COLLECTION DIRECTORY
|
---|
490 | * --------------------------------------------------------------------------------------------
|
---|
491 | */
|
---|
492 | static class NewCollectionDirectoryAction
|
---|
493 | extends RemoteGreenstoneServerAction
|
---|
494 | {
|
---|
495 | private String collection_name;
|
---|
496 | private File new_collection_directory;
|
---|
497 |
|
---|
498 | public NewCollectionDirectoryAction(String collection_name, File new_collection_directory)
|
---|
499 | {
|
---|
500 | this.collection_name = collection_name;
|
---|
501 | this.new_collection_directory = new_collection_directory;
|
---|
502 | }
|
---|
503 |
|
---|
504 | public void perform()
|
---|
505 | throws Exception
|
---|
506 | {
|
---|
507 | String collection_directory_path = CollectionManager.getCollectionDirectoryPath(collection_name);
|
---|
508 | String new_collection_directory_relative_path = remote.getPathRelativeToDirectory(
|
---|
509 | new_collection_directory, collection_directory_path);
|
---|
510 | new_collection_directory_relative_path = new_collection_directory_relative_path.replaceAll((Utility.isWindows() ? "\\\\" : "\\/"), "|");
|
---|
511 | progress_bar.setAction("Creating new directory " + new_collection_directory_relative_path + "...");
|
---|
512 |
|
---|
513 | String new_collection_directory_command = "cmd=new-collection-directory";
|
---|
514 | new_collection_directory_command += "&c=" + URLEncoder.encode(collection_name.replace(File.separatorChar, '|'), "UTF-8");
|
---|
515 | new_collection_directory_command += "&directory=" + URLEncoder.encode(new_collection_directory_relative_path, "UTF-8");
|
---|
516 | action_output = remote.sendCommandToServer(new_collection_directory_command, null);
|
---|
517 | }
|
---|
518 | }
|
---|
519 |
|
---|
520 |
|
---|
521 | /**
|
---|
522 | * --------------------------------------------------------------------------------------------
|
---|
523 | * RUN SCRIPT
|
---|
524 | * --------------------------------------------------------------------------------------------
|
---|
525 | */
|
---|
526 | static class RunScriptAction
|
---|
527 | extends RemoteGreenstoneServerAction
|
---|
528 | {
|
---|
529 | private String collection_name;
|
---|
530 | private String script_name;
|
---|
531 | private String script_arguments;
|
---|
532 | private GShell shell;
|
---|
533 |
|
---|
534 | public RunScriptAction(String collection_name, String script_name, String script_arguments, GShell shell)
|
---|
535 | {
|
---|
536 | this.collection_name = collection_name;
|
---|
537 | this.script_name = script_name;
|
---|
538 | this.script_arguments = script_arguments;
|
---|
539 | this.shell = shell;
|
---|
540 | }
|
---|
541 |
|
---|
542 | public void perform()
|
---|
543 | throws Exception
|
---|
544 | {
|
---|
545 | progress_bar.setAction("Running " + script_name + "...");
|
---|
546 |
|
---|
547 | String run_script_command = "cmd=run-script";
|
---|
548 | run_script_command += "&c=" + URLEncoder.encode(collection_name.replace(File.separatorChar, '|'), "UTF-8");
|
---|
549 | run_script_command += "&script=" + script_name;
|
---|
550 | run_script_command += "&language=" + Configuration.getLanguage();
|
---|
551 | run_script_command += script_arguments;
|
---|
552 | action_output = remote.sendCommandToServer(run_script_command, shell);
|
---|
553 | }
|
---|
554 | }
|
---|
555 |
|
---|
556 |
|
---|
557 | /**
|
---|
558 | * --------------------------------------------------------------------------------------------
|
---|
559 | * UPLOAD COLLECTION FILE
|
---|
560 | * --------------------------------------------------------------------------------------------
|
---|
561 | */
|
---|
562 | static class UploadCollectionFilesAction
|
---|
563 | extends RemoteGreenstoneServerAction
|
---|
564 | {
|
---|
565 | private String collection_name;
|
---|
566 | private File[] collection_files;
|
---|
567 |
|
---|
568 |
|
---|
569 | public UploadCollectionFilesAction(String collection_name, File[] collection_files)
|
---|
570 | {
|
---|
571 | this.collection_name = collection_name;
|
---|
572 | this.collection_files = collection_files;
|
---|
573 | }
|
---|
574 |
|
---|
575 |
|
---|
576 | public void perform()
|
---|
577 | throws Exception
|
---|
578 | {
|
---|
579 | progress_bar.setAction("Uploading collection files...");
|
---|
580 |
|
---|
581 | // Determine the file paths relative to the collection directory
|
---|
582 | String collection_directory_path = CollectionManager.getCollectionDirectoryPath(collection_name);
|
---|
583 | String[] collection_file_relative_paths = new String[collection_files.length];
|
---|
584 | for (int i = 0; i < collection_files.length; i++) {
|
---|
585 | collection_file_relative_paths[i] = remote.getPathRelativeToDirectory(collection_files[i], collection_directory_path);
|
---|
586 | }
|
---|
587 |
|
---|
588 | // Zip up the files to send to the server
|
---|
589 | //String zip_file_name = collection_name + "-" + System.currentTimeMillis() + ".zip";
|
---|
590 | //String zip_file_path = collection_directory_path + zip_file_name;
|
---|
591 | String zip_file_path = collection_directory_path; // collect/(colgroup/)coltail/
|
---|
592 | String zip_file_name = new File(zip_file_path).getName() + "-" + System.currentTimeMillis() + ".zip"; // <collection_tail_name>-<time>.zip
|
---|
593 | zip_file_path += zip_file_name; // collect/(colgroup/)coltail/coltail-time.zip
|
---|
594 | ZipTools.zipFiles(zip_file_path, collection_directory_path, collection_file_relative_paths);
|
---|
595 |
|
---|
596 | // Upload the zip file
|
---|
597 | String upload_collection_file_command = "cmd=upload-collection-file";
|
---|
598 | upload_collection_file_command += "&c=" + URLEncoder.encode(collection_name.replace(File.separatorChar, '|'), "UTF-8");
|
---|
599 | upload_collection_file_command += "&file=" + URLEncoder.encode(zip_file_name, "UTF-8");
|
---|
600 | upload_collection_file_command += "&directory=";
|
---|
601 | upload_collection_file_command += "&zip=true";
|
---|
602 | upload_collection_file_command += "&lr=" + remote.lang_region;
|
---|
603 | action_output = remote.uploadFile(upload_collection_file_command, zip_file_path);
|
---|
604 | }
|
---|
605 | }
|
---|
606 |
|
---|
607 |
|
---|
608 | /**
|
---|
609 | * --------------------------------------------------------------------------------------------
|
---|
610 | * UPLOAD FILES INTO COLLECTION
|
---|
611 | * --------------------------------------------------------------------------------------------
|
---|
612 | */
|
---|
613 | static class UploadFilesIntoCollectionAction
|
---|
614 | extends RemoteGreenstoneServerAction
|
---|
615 | {
|
---|
616 | private String collection_name;
|
---|
617 | private File[] source_files;
|
---|
618 | private File target_collection_directory;
|
---|
619 |
|
---|
620 |
|
---|
621 | public UploadFilesIntoCollectionAction(String collection_name, File[] source_files, File target_collection_directory)
|
---|
622 | {
|
---|
623 | this.collection_name = collection_name;
|
---|
624 | this.source_files = source_files;
|
---|
625 | this.target_collection_directory = target_collection_directory;
|
---|
626 | }
|
---|
627 |
|
---|
628 |
|
---|
629 | public void perform()
|
---|
630 | throws Exception
|
---|
631 | {
|
---|
632 | String collection_directory_path = CollectionManager.getCollectionDirectoryPath(collection_name);
|
---|
633 | String target_collection_directory_relative_path = remote.getPathRelativeToDirectory(
|
---|
634 | target_collection_directory, collection_directory_path);
|
---|
635 | target_collection_directory_relative_path = target_collection_directory_relative_path.replaceAll((Utility.isWindows() ? "\\\\" : "\\/"), "|");
|
---|
636 | progress_bar.setAction("Uploading files into collection...");
|
---|
637 |
|
---|
638 | //String zip_file_name = collection_name + "-" + System.currentTimeMillis() + ".zip";
|
---|
639 | //String zip_file_path = Gatherer.getCollectDirectoryPath() + zip_file_name;
|
---|
640 | String zip_file_path = Gatherer.getCollectDirectoryPath()
|
---|
641 | + collection_name + "-" + System.currentTimeMillis() + ".zip"; // "collect/(colgroup/)collection_tail_name-<time>.zip"
|
---|
642 | String zip_file_name = new File(zip_file_path).getName(); // "collection_tail_name-<time>.zip"
|
---|
643 | DebugStream.println("Zip file path: " + zip_file_path);
|
---|
644 |
|
---|
645 | String base_directory_path = source_files[0].getParentFile().getAbsolutePath();
|
---|
646 | DebugStream.println("Base directory path: " + base_directory_path);
|
---|
647 | String[] source_file_relative_paths = new String[source_files.length];
|
---|
648 | for (int i = 0; i < source_files.length; i++) {
|
---|
649 | DebugStream.println("Source file path: " + source_files[i]);
|
---|
650 | source_file_relative_paths[i] = remote.getPathRelativeToDirectory(source_files[i], base_directory_path);
|
---|
651 | }
|
---|
652 |
|
---|
653 | ZipTools.zipFiles(zip_file_path, base_directory_path, source_file_relative_paths);
|
---|
654 |
|
---|
655 | String upload_collection_file_command = "cmd=upload-collection-file";
|
---|
656 | upload_collection_file_command += "&c=" + URLEncoder.encode(collection_name.replace(File.separatorChar, '|'), "UTF-8");
|
---|
657 | upload_collection_file_command += "&file=" + URLEncoder.encode(zip_file_name, "UTF-8");
|
---|
658 | upload_collection_file_command += "&directory=" + URLEncoder.encode(target_collection_directory_relative_path, "UTF-8");
|
---|
659 | upload_collection_file_command += "&zip=true";
|
---|
660 | upload_collection_file_command += "&lr=" + remote.lang_region;
|
---|
661 | action_output = remote.uploadFile(upload_collection_file_command, zip_file_path);
|
---|
662 | }
|
---|
663 | }
|
---|
664 | }
|
---|