source: trunk/gli/src/org/greenstone/gatherer/remote/ZipCollectionConfigurations.java@ 13328

Last change on this file since 13328 was 13328, checked in by mdewsnip, 17 years ago

Moved most of the zip code into the "remote" package, to better indicate where it is used and to simplify the creation of the GLIServer.jar file.

  • Property svn:keywords set to Author Date Id Revision
File size: 3.0 KB
Line 
1package org.greenstone.gatherer.remote;
2
3import java.io.*;
4import java.util.zip.*;
5
6
7/**
8 */
9public class ZipCollectionConfigurations
10{
11 static public void main(String[] args)
12 {
13 if (args.length != 4) {
14 System.err.println("Usage: ZipCollectionConfigurations <zip-file> <collect-directory-path> <user-name> <user-groups>");
15 return;
16 }
17
18 String zip_file_path = args[0];
19 String collect_directory_path = args[1];
20 String user_name = args[2];
21 String user_groups = args[3];
22
23 if (!collect_directory_path.endsWith(File.separator)) {
24 collect_directory_path += File.separator;
25 }
26 File collect_directory = new File(collect_directory_path);
27
28 try {
29 ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zip_file_path));
30 ZipTools.ZipFilter collection_etc_zip_filter = new CollectionEtcZipFilter();
31 ZipTools.ZipFilter collection_metadata_zip_filter = new CollectionMetadataZipFilter();
32
33 // Add the etc and metadata directories from each of the collections the user has access to
34 File[] collection_directories = collect_directory.listFiles();
35 for (int i = 0; i < collection_directories.length; i++) {
36 if (collection_directories[i].isDirectory()) {
37 String collection_name = collection_directories[i].getName();
38 if (checkAccess(collection_name, user_name, user_groups)) {
39 String etc_relative_path = collection_directories[i].getName() + File.separator + "etc";
40 ZipTools.addFileToZip(zos, collect_directory_path, etc_relative_path, collection_etc_zip_filter);
41 String metadata_relative_path = collection_directories[i].getName() + File.separator + "metadata";
42 ZipTools.addFileToZip(zos, collect_directory_path, metadata_relative_path, collection_metadata_zip_filter);
43 }
44 }
45 }
46
47 zos.putNextEntry(new ZipEntry(".gli"));
48 zos.close();
49 }
50 catch (Exception exception) {
51 exception.printStackTrace();
52 }
53 }
54
55
56 static private boolean checkAccess(String collection_name, String user_name, String user_groups)
57 {
58 String[] user_groups_array = user_groups.split(",");
59 for (int i = 0; i < user_groups_array.length; i++) {
60 if (user_groups_array[i].equals("all-collections-editor")) {
61 return true;
62 }
63 if (user_groups_array[i].equals("personal-collections-editor") && collection_name.startsWith(user_name + "-")) {
64 return true;
65 }
66 if (user_groups_array[i].equals(collection_name + "-collection-editor")) {
67 return true;
68 }
69 }
70
71 return false;
72 }
73
74
75 static private class CollectionEtcZipFilter
76 extends ZipTools.NullZipFilter
77 {
78 public boolean shouldIncludeFile(String relative_file_path)
79 {
80 // Only collect.cfg files are included
81 return (relative_file_path.equals("collect.cfg") || relative_file_path.endsWith(File.separator + "collect.cfg"));
82 }
83 }
84
85
86 static private class CollectionMetadataZipFilter
87 extends ZipTools.NullZipFilter
88 {
89 public boolean shouldIncludeFileContent(String relative_file_path)
90 {
91 // We don't include content for any of the metadata set files
92 return false;
93 }
94 }
95}
Note: See TracBrowser for help on using the repository browser.