1 | package org.greenstone.gatherer.remote;
|
---|
2 |
|
---|
3 | import java.io.*;
|
---|
4 | import java.util.zip.*;
|
---|
5 |
|
---|
6 |
|
---|
7 | /**
|
---|
8 | */
|
---|
9 | public class ZipCollectionShell
|
---|
10 | {
|
---|
11 | static public void main(String[] args)
|
---|
12 | {
|
---|
13 | if ((args.length < 3) || (args.length > 4)) {
|
---|
14 | System.err.println("Usage: ZipCollectionShell <zip-file> <collect-directory-path> <collection-name> [gsdl3]");
|
---|
15 | return;
|
---|
16 | }
|
---|
17 |
|
---|
18 | String zip_file_path = args[0];
|
---|
19 | String collect_directory_path = args[1];
|
---|
20 | String collection_name = args[2];
|
---|
21 | String run_gsdl3 ="";
|
---|
22 | if (args.length == 4){
|
---|
23 | run_gsdl3 = args[3];
|
---|
24 | }
|
---|
25 | if (!collect_directory_path.endsWith(File.separator)) {
|
---|
26 | collect_directory_path += File.separator;
|
---|
27 | }
|
---|
28 |
|
---|
29 | try {
|
---|
30 | ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zip_file_path));
|
---|
31 | ZipTools.ZipFilter null_zip_filter = new ZipTools.NullZipFilter();
|
---|
32 |
|
---|
33 | // Add archives directory, with doc.xml files only
|
---|
34 | String archives_relative_path = collection_name + File.separator + "archives";
|
---|
35 | ZipTools.ZipFilter collection_archives_zip_filter = new ZipCollectionArchives.CollectionArchivesZipFilter();
|
---|
36 | ZipTools.addFileToZip(zos, collect_directory_path, archives_relative_path, collection_archives_zip_filter);
|
---|
37 |
|
---|
38 | // Add /etc/collect.cfg file for 2 GS2
|
---|
39 | if (run_gsdl3.length()==0){
|
---|
40 | String collect_cfg_relative_path = collection_name + File.separator + "etc" + File.separator + "collect.cfg";
|
---|
41 | ZipTools.addFileToZip(zos, collect_directory_path, collect_cfg_relative_path, null_zip_filter);
|
---|
42 | }
|
---|
43 | // Add /etc/collectConfig.xml file for a GS3
|
---|
44 | if (run_gsdl3.equals("gsdl3")){
|
---|
45 | String collectionConfig_xml_relative_path = collection_name + File.separator + "etc" + File.separator + "collectionConfig.xml";
|
---|
46 | ZipTools.addFileToZip(zos, collect_directory_path, collectionConfig_xml_relative_path, null_zip_filter);
|
---|
47 | }
|
---|
48 | // Add images directory
|
---|
49 | String images_relative_path = collection_name + File.separator + "images";
|
---|
50 | ZipTools.addFileToZip(zos, collect_directory_path, images_relative_path, null_zip_filter);
|
---|
51 |
|
---|
52 | // Add import directory, with zero-length files except for metadata.xml
|
---|
53 | String import_relative_path = collection_name + File.separator + "import";
|
---|
54 | ZipTools.ZipFilter collection_import_zip_filter = new CollectionImportZipFilter();
|
---|
55 | ZipTools.addFileToZip(zos, collect_directory_path, import_relative_path, collection_import_zip_filter);
|
---|
56 |
|
---|
57 | // Add index/build.cfg file
|
---|
58 | String build_cfg_relative_path = collection_name + File.separator + "index" + File.separator + "build.cfg";
|
---|
59 | ZipTools.addFileToZip(zos, collect_directory_path, build_cfg_relative_path, null_zip_filter);
|
---|
60 |
|
---|
61 | // Add macros/extra.dm file
|
---|
62 | String extra_dm_relative_path = collection_name + File.separator + "macros" + File.separator + "extra.dm";
|
---|
63 | ZipTools.addFileToZip(zos, collect_directory_path, extra_dm_relative_path, null_zip_filter);
|
---|
64 |
|
---|
65 | // Add metadata directory
|
---|
66 | String metadata_relative_path = collection_name + File.separator + "metadata";
|
---|
67 | ZipTools.addFileToZip(zos, collect_directory_path, metadata_relative_path, null_zip_filter);
|
---|
68 |
|
---|
69 | zos.close();
|
---|
70 | }
|
---|
71 | catch (Exception exception) {
|
---|
72 | exception.printStackTrace();
|
---|
73 | }
|
---|
74 | }
|
---|
75 |
|
---|
76 |
|
---|
77 | static private class CollectionImportZipFilter
|
---|
78 | extends ZipTools.NullZipFilter
|
---|
79 | {
|
---|
80 | public boolean shouldIncludeFileContent(String relative_file_path)
|
---|
81 | {
|
---|
82 | // We only include file content for metadata.xml files
|
---|
83 | return (relative_file_path.equals("metadata.xml") || relative_file_path.endsWith(File.separator + "metadata.xml"));
|
---|
84 | }
|
---|
85 | }
|
---|
86 | }
|
---|