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, "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");
|
---|
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, "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, "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, "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, "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 | 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");
|
---|
378 | download_web_xml_file_command += "&lr=" + remote.lang_region;
|
---|
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");
|
---|
473 | move_collection_file_command += "&source=" + URLEncoder.encode(source_collection_file_relative_path, "UTF-8");
|
---|
474 | move_collection_file_command += "&target=" + URLEncoder.encode(target_collection_file_relative_path, "UTF-8");
|
---|
475 | action_output = remote.sendCommandToServer(move_collection_file_command, null);
|
---|
476 | }
|
---|
477 | }
|
---|
478 |
|
---|
479 |
|
---|
480 | /**
|
---|
481 | * --------------------------------------------------------------------------------------------
|
---|
482 | * NEW COLLECTION DIRECTORY
|
---|
483 | * --------------------------------------------------------------------------------------------
|
---|
484 | */
|
---|
485 | static class NewCollectionDirectoryAction
|
---|
486 | extends RemoteGreenstoneServerAction
|
---|
487 | {
|
---|
488 | private String collection_name;
|
---|
489 | private File new_collection_directory;
|
---|
490 |
|
---|
491 | public NewCollectionDirectoryAction(String collection_name, File new_collection_directory)
|
---|
492 | {
|
---|
493 | this.collection_name = collection_name;
|
---|
494 | this.new_collection_directory = new_collection_directory;
|
---|
495 | }
|
---|
496 |
|
---|
497 | public void perform()
|
---|
498 | throws Exception
|
---|
499 | {
|
---|
500 | String collection_directory_path = CollectionManager.getCollectionDirectoryPath(collection_name);
|
---|
501 | String new_collection_directory_relative_path = remote.getPathRelativeToDirectory(
|
---|
502 | new_collection_directory, collection_directory_path);
|
---|
503 | new_collection_directory_relative_path = new_collection_directory_relative_path.replaceAll((Utility.isWindows() ? "\\\\" : "\\/"), "|");
|
---|
504 | progress_bar.setAction("Creating new directory " + new_collection_directory_relative_path + "...");
|
---|
505 |
|
---|
506 | String new_collection_directory_command = "cmd=new-collection-directory";
|
---|
507 | new_collection_directory_command += "&c=" + URLEncoder.encode(collection_name, "UTF-8");
|
---|
508 | new_collection_directory_command += "&directory=" + URLEncoder.encode(new_collection_directory_relative_path, "UTF-8");
|
---|
509 | action_output = remote.sendCommandToServer(new_collection_directory_command, null);
|
---|
510 | }
|
---|
511 | }
|
---|
512 |
|
---|
513 |
|
---|
514 | /**
|
---|
515 | * --------------------------------------------------------------------------------------------
|
---|
516 | * RUN SCRIPT
|
---|
517 | * --------------------------------------------------------------------------------------------
|
---|
518 | */
|
---|
519 | static class RunScriptAction
|
---|
520 | extends RemoteGreenstoneServerAction
|
---|
521 | {
|
---|
522 | private String collection_name;
|
---|
523 | private String script_name;
|
---|
524 | private String script_arguments;
|
---|
525 | private GShell shell;
|
---|
526 |
|
---|
527 | public RunScriptAction(String collection_name, String script_name, String script_arguments, GShell shell)
|
---|
528 | {
|
---|
529 | this.collection_name = collection_name;
|
---|
530 | this.script_name = script_name;
|
---|
531 | this.script_arguments = script_arguments;
|
---|
532 | this.shell = shell;
|
---|
533 | }
|
---|
534 |
|
---|
535 | public void perform()
|
---|
536 | throws Exception
|
---|
537 | {
|
---|
538 | progress_bar.setAction("Running " + script_name + "...");
|
---|
539 |
|
---|
540 | String run_script_command = "cmd=run-script";
|
---|
541 | run_script_command += "&c=" + URLEncoder.encode(collection_name, "UTF-8");
|
---|
542 | run_script_command += "&script=" + script_name;
|
---|
543 | run_script_command += "&language=" + Configuration.getLanguage();
|
---|
544 | run_script_command += script_arguments;
|
---|
545 | action_output = remote.sendCommandToServer(run_script_command, shell);
|
---|
546 | }
|
---|
547 | }
|
---|
548 |
|
---|
549 |
|
---|
550 | /**
|
---|
551 | * --------------------------------------------------------------------------------------------
|
---|
552 | * UPLOAD COLLECTION FILE
|
---|
553 | * --------------------------------------------------------------------------------------------
|
---|
554 | */
|
---|
555 | static class UploadCollectionFilesAction
|
---|
556 | extends RemoteGreenstoneServerAction
|
---|
557 | {
|
---|
558 | private String collection_name;
|
---|
559 | private File[] collection_files;
|
---|
560 |
|
---|
561 |
|
---|
562 | public UploadCollectionFilesAction(String collection_name, File[] collection_files)
|
---|
563 | {
|
---|
564 | this.collection_name = collection_name;
|
---|
565 | this.collection_files = collection_files;
|
---|
566 | }
|
---|
567 |
|
---|
568 |
|
---|
569 | public void perform()
|
---|
570 | throws Exception
|
---|
571 | {
|
---|
572 | progress_bar.setAction("Uploading collection files...");
|
---|
573 |
|
---|
574 | // Determine the file paths relative to the collection directory
|
---|
575 | String collection_directory_path = CollectionManager.getCollectionDirectoryPath(collection_name);
|
---|
576 | String[] collection_file_relative_paths = new String[collection_files.length];
|
---|
577 | for (int i = 0; i < collection_files.length; i++) {
|
---|
578 | collection_file_relative_paths[i] = remote.getPathRelativeToDirectory(collection_files[i], collection_directory_path);
|
---|
579 | }
|
---|
580 |
|
---|
581 | // Zip up the files to send to the server
|
---|
582 | String zip_file_name = collection_name + "-" + System.currentTimeMillis() + ".zip";
|
---|
583 | String zip_file_path = collection_directory_path + zip_file_name;
|
---|
584 | ZipTools.zipFiles(zip_file_path, collection_directory_path, collection_file_relative_paths);
|
---|
585 |
|
---|
586 | // Upload the zip file
|
---|
587 | String upload_collection_file_command = "cmd=upload-collection-file";
|
---|
588 | upload_collection_file_command += "&c=" + URLEncoder.encode(collection_name, "UTF-8");
|
---|
589 | upload_collection_file_command += "&file=" + URLEncoder.encode(zip_file_name, "UTF-8");
|
---|
590 | upload_collection_file_command += "&directory=";
|
---|
591 | upload_collection_file_command += "&zip=true";
|
---|
592 | upload_collection_file_command += "&lr=" + remote.lang_region;
|
---|
593 | action_output = remote.uploadFile(upload_collection_file_command, zip_file_path);
|
---|
594 | }
|
---|
595 | }
|
---|
596 |
|
---|
597 |
|
---|
598 | /**
|
---|
599 | * --------------------------------------------------------------------------------------------
|
---|
600 | * UPLOAD FILES INTO COLLECTION
|
---|
601 | * --------------------------------------------------------------------------------------------
|
---|
602 | */
|
---|
603 | static class UploadFilesIntoCollectionAction
|
---|
604 | extends RemoteGreenstoneServerAction
|
---|
605 | {
|
---|
606 | private String collection_name;
|
---|
607 | private File[] source_files;
|
---|
608 | private File target_collection_directory;
|
---|
609 |
|
---|
610 |
|
---|
611 | public UploadFilesIntoCollectionAction(String collection_name, File[] source_files, File target_collection_directory)
|
---|
612 | {
|
---|
613 | this.collection_name = collection_name;
|
---|
614 | this.source_files = source_files;
|
---|
615 | this.target_collection_directory = target_collection_directory;
|
---|
616 | }
|
---|
617 |
|
---|
618 |
|
---|
619 | public void perform()
|
---|
620 | throws Exception
|
---|
621 | {
|
---|
622 | String collection_directory_path = CollectionManager.getCollectionDirectoryPath(collection_name);
|
---|
623 | String target_collection_directory_relative_path = remote.getPathRelativeToDirectory(
|
---|
624 | target_collection_directory, collection_directory_path);
|
---|
625 | target_collection_directory_relative_path = target_collection_directory_relative_path.replaceAll((Utility.isWindows() ? "\\\\" : "\\/"), "|");
|
---|
626 | progress_bar.setAction("Uploading files into collection...");
|
---|
627 |
|
---|
628 | String zip_file_name = collection_name + "-" + System.currentTimeMillis() + ".zip";
|
---|
629 | String zip_file_path = Gatherer.getCollectDirectoryPath() + zip_file_name;
|
---|
630 | DebugStream.println("Zip file path: " + zip_file_path);
|
---|
631 |
|
---|
632 | String base_directory_path = source_files[0].getParentFile().getAbsolutePath();
|
---|
633 | DebugStream.println("Base directory path: " + base_directory_path);
|
---|
634 | String[] source_file_relative_paths = new String[source_files.length];
|
---|
635 | for (int i = 0; i < source_files.length; i++) {
|
---|
636 | DebugStream.println("Source file path: " + source_files[i]);
|
---|
637 | source_file_relative_paths[i] = remote.getPathRelativeToDirectory(source_files[i], base_directory_path);
|
---|
638 | }
|
---|
639 |
|
---|
640 | ZipTools.zipFiles(zip_file_path, base_directory_path, source_file_relative_paths);
|
---|
641 |
|
---|
642 | String upload_collection_file_command = "cmd=upload-collection-file";
|
---|
643 | upload_collection_file_command += "&c=" + URLEncoder.encode(collection_name, "UTF-8");
|
---|
644 | upload_collection_file_command += "&file=" + URLEncoder.encode(zip_file_name, "UTF-8");
|
---|
645 | upload_collection_file_command += "&directory=" + URLEncoder.encode(target_collection_directory_relative_path, "UTF-8");
|
---|
646 | upload_collection_file_command += "&zip=true";
|
---|
647 | upload_collection_file_command += "&lr=" + remote.lang_region;
|
---|
648 | action_output = remote.uploadFile(upload_collection_file_command, zip_file_path);
|
---|
649 | }
|
---|
650 | }
|
---|
651 | }
|
---|