Changeset 19207

Show
Ignore:
Timestamp:
22.04.2009 20:14:54 (10 years ago)
Author:
ak19
Message:

Recurses to add collection-Group configurations to the zip, necessary for colgroup in the remote case.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • gli/trunk/src/org/greenstone/gatherer/remote/ZipCollectionConfigurations.java

    r14306 r19207  
    3131        ZipTools.ZipFilter collection_metadata_zip_filter = new CollectionMetadataZipFilter(); 
    3232 
    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); 
     33        addUserAccessibleCollections(collect_directory_path, "", collect_directory, zos,  
     34                     collection_etc_zip_filter, collection_metadata_zip_filter, 
     35                     user_name, user_groups); 
    4136 
    42             // The "metadata" directory may not exist (non-GLI collections) 
    43             String metadata_relative_path = collection_directories[i].getName() + File.separator + "metadata"; 
    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             } 
    48             } 
    49         } 
    50         } 
     37         
    5138 
    5239        zos.putNextEntry(new ZipEntry(".gli")); 
     
    5542    catch (Exception exception) { 
    5643        exception.printStackTrace(); 
     44    } 
     45    } 
     46 
     47    static private void addUserAccessibleCollections(String toplevel_path,        // remains unchanged 
     48                             String relative_path,        // grows with each level of recursion 
     49                             File collect_directory,      // current collection (group) directory being considered 
     50                             ZipOutputStream zos,  
     51                             ZipTools.ZipFilter collection_etc_zip_filter, 
     52                             ZipTools.ZipFilter collection_metadata_zip_filter, 
     53                             String user_name, 
     54                             String user_groups)  
     55    { 
     56     
     57    if(!relative_path.equals("")) { 
     58        relative_path += File.separator; 
     59    } 
     60     
     61    // Add the etc and metadata directories from each of the collections the user has access to 
     62    File[] collection_directories = collect_directory.listFiles(); 
     63    for (int i = 0; i < collection_directories.length; i++) { 
     64        if (collection_directories[i].isDirectory()) { 
     65        String collection_name = collection_directories[i].getName(); 
     66        if (checkAccess(collection_name, user_name, user_groups)) { 
     67             
     68            String etc_relative_path = relative_path + collection_directories[i].getName() + File.separator + "etc"; 
     69            ZipTools.addFileToZip(zos, toplevel_path, etc_relative_path, collection_etc_zip_filter); 
     70             
     71            // The "metadata" directory may not exist (non-GLI collections) 
     72            String metadata_relative_path = relative_path + collection_directories[i].getName() + File.separator + "metadata"; 
     73            File metadata_directory = new File(collect_directory.getAbsolutePath() + File.separator + metadata_relative_path); 
     74            if (metadata_directory.exists()) { 
     75            ZipTools.addFileToZip(zos, toplevel_path, metadata_relative_path, collection_metadata_zip_filter); 
     76            }  
     77            else { // if a collection contains no metadata directory, then check if it is a collectgroup 
     78             
     79            // read from collection config file in etc folder 
     80            File config_file = new File(collection_directories[i], "etc"+File.separator+"collect.cfg"); 
     81            if(config_file.exists()) { 
     82                try { 
     83                BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(config_file))); 
     84                String line = null; 
     85                while((line = reader.readLine()) != null) { // read lines and look for: collectgroup true 
     86                    line = line.trim(); // need to ignore surrounding whitespace 
     87                    if(line.startsWith("collectgroup") && line.endsWith("true")) { 
     88                    // if collectgroup, then recurse on current folder 
     89                    addUserAccessibleCollections(toplevel_path, relative_path+collection_directories[i].getName(), collection_directories[i], 
     90                                     zos, collection_etc_zip_filter, collection_metadata_zip_filter, 
     91                                     user_name, user_groups); 
     92                    } 
     93                } 
     94                 
     95                reader.close(); 
     96                } catch(Exception e) { 
     97                System.err.println("Exception reading from file " + config_file + ": " + e); 
     98                e.printStackTrace(); 
     99                } 
     100            }                
     101            } 
     102        } 
     103        } 
    57104    } 
    58105    }