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

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

(Remote building) Added a check for the existence of the collection "metadata" directories to prevent errors in the Apache error_log file for non-GLI collections.

  • Property svn:keywords set to Author Date Id Revision
File size: 3.2 KB
RevLine 
[10726]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 {
[11942]13 if (args.length != 4) {
14 System.err.println("Usage: ZipCollectionConfigurations <zip-file> <collect-directory-path> <user-name> <user-groups>");
[10726]15 return;
16 }
17
18 String zip_file_path = args[0];
19 String collect_directory_path = args[1];
[11942]20 String user_name = args[2];
21 String user_groups = args[3];
[10726]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
[11942]33 // Add the etc and metadata directories from each of the collections the user has access to
[10726]34 File[] collection_directories = collect_directory.listFiles();
35 for (int i = 0; i < collection_directories.length; i++) {
36 if (collection_directories[i].isDirectory()) {
[11942]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);
[13392]41
42 // The "metadata" directory may not exist (non-GLI collections)
[11942]43 String metadata_relative_path = collection_directories[i].getName() + File.separator + "metadata";
[13392]44 File metadata_directory = new File(collect_directory_path + File.separator + metadata_relative_path);
45 if (metadata_directory.exists()) {
46 ZipTools.addFileToZip(zos, collect_directory_path, metadata_relative_path, collection_metadata_zip_filter);
47 }
[11942]48 }
[10726]49 }
50 }
51
[11942]52 zos.putNextEntry(new ZipEntry(".gli"));
[10726]53 zos.close();
54 }
55 catch (Exception exception) {
56 exception.printStackTrace();
57 }
58 }
59
60
[11942]61 static private boolean checkAccess(String collection_name, String user_name, String user_groups)
62 {
63 String[] user_groups_array = user_groups.split(",");
64 for (int i = 0; i < user_groups_array.length; i++) {
65 if (user_groups_array[i].equals("all-collections-editor")) {
66 return true;
67 }
68 if (user_groups_array[i].equals("personal-collections-editor") && collection_name.startsWith(user_name + "-")) {
69 return true;
70 }
71 if (user_groups_array[i].equals(collection_name + "-collection-editor")) {
72 return true;
73 }
74 }
75
76 return false;
77 }
78
79
[10726]80 static private class CollectionEtcZipFilter
81 extends ZipTools.NullZipFilter
82 {
83 public boolean shouldIncludeFile(String relative_file_path)
84 {
85 // Only collect.cfg files are included
86 return (relative_file_path.equals("collect.cfg") || relative_file_path.endsWith(File.separator + "collect.cfg"));
87 }
88 }
89
90
91 static private class CollectionMetadataZipFilter
92 extends ZipTools.NullZipFilter
93 {
94 public boolean shouldIncludeFileContent(String relative_file_path)
95 {
96 // We don't include content for any of the metadata set files
97 return false;
98 }
99 }
100}
Note: See TracBrowser for help on using the repository browser.