Changeset 4449 for trunk/gli


Ignore:
Timestamp:
2003-06-03T12:17:47+12:00 (21 years ago)
Author:
jmt12
Message:

Moved the 'does the file we are processing match the fileset in the current document' test to its own little method so as to make searching for bug 2030101 easier.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/msm/parsers/GreenstoneMetadataParser.java

    r4365 r4449  
    137137    // Continue only if we are sure this is a greenstone collection
    138138    if(collection_dir != null && collect_cfg != null) {
    139                 // 2. Attempt to merge in any mdses and make note of those that are successfully imported (by removing reference from collect.cfg).
    140                 ///ystem.err.print("2 ");
     139        // 2. Attempt to merge in any mdses and make note of those that are successfully imported (by removing reference from collect.cfg).
     140        ///ystem.err.print("2 ");
    141141        ArrayList mdses = collect_cfg.getMetadataSets();
    142142        for(int i = 0; i < mdses.size(); i++) {
     
    147147        mdses = null;
    148148
    149                 // 3. Locate all of the metadata.xml files that may have an affect on the origin file. Make sure the metadata.xml closest to the origin files directory is last (to ensure property inheritance regarding accumulate/overwrite).
    150                 ///ystem.err.print("3 ");
     149        // 3. Locate all of the metadata.xml files that may have an affect on the origin file. Make sure the metadata.xml closest to the origin files directory is last (to ensure property inheritance regarding accumulate/overwrite).
     150        ///ystem.err.print("3 ");
    151151        ArrayList search_files = new ArrayList();
    152152        File file = origin.getFile();
    153153        String filename = null;
     154        boolean file_level;
    154155        if(file.isFile()) {
     156        file_level = false;
    155157        filename = file.getName();
    156158        file = file.getParentFile();
     159        }
     160        else {
     161        file_level = true;
    157162        }
    158163        while(!file.equals(collection_dir)) {
     
    171176        filename = null;
    172177        file = null;
    173                 // Start with an initially empty ArrayList of metadata
     178        // Start with an initially empty ArrayList of metadata
    174179        ArrayList metadatum = new ArrayList();
    175                 // Now search each of these metadata xml for metadata, remembering to accumulate or overwrite as we go along.
     180        // Now search each of these metadata xml for metadata, remembering to accumulate or overwrite as we go along.
    176181        for(int i = 0; i < search_files.size(); i++) {
    177182        MetadataXMLFileSearch a_search = (MetadataXMLFileSearch) search_files.get(i);
     
    185190            }
    186191            else {
    187             metadatum = document.getMetadata(a_search.filename, metadatum, true);
     192            metadatum = document.getMetadata(a_search.filename, metadatum, folder_level);
    188193            }
    189194            document = null;
     
    192197        }
    193198        search_files = null;
    194                 // Finally assign the metadata
    195                 ///ystem.err.println("Found " + metadatum.size() + " pieces of metadata for " + destination);
     199        // Finally assign the metadata
     200        ///ystem.err.println("Found " + metadatum.size() + " pieces of metadata for " + destination);
    196201        if(metadatum.size() > 0) {
    197202        addMetadata(destination, metadatum, collection_dir, collect_cfg, dummy_run);
     
    372377    /** This constructor takes the original document and parsed out and stores metadata with its association to filenames. */
    373378    public BasicGDMDocument(File file) {
    374                 ///ystem.err.println("New BasicGDMDocument: " + file.getAbsolutePath());
     379        ///ystem.err.println("New BasicGDMDocument: " + file.getAbsolutePath());
    375380        base_document = Utility.parse(file.getAbsolutePath(), false);
    376381    }
     
    378383    public ArrayList getAllMetadata() {
    379384        ArrayList metadatum = new ArrayList();
    380                 // Don't search the cache as this would never have been added.
     385        // Don't search the cache as this would never have been added.
    381386        try {
    382387        // Retrieve the document element.
     
    432437    /** Retrieve any metadata associated with a certain file. If filename is null we are attempting to find directory level metadata. */
    433438    public ArrayList getMetadata(String filename, ArrayList metadatum_so_far, boolean folder_level) {
    434                 ///ystem.err.println("Retrieving metadata for: " + filename);
     439        ///ystem.err.println("Retrieving metadata for: " + filename + " [" + folder_level + "]");
    435440        ArrayList metadatum = null;
    436                 // We start by attempting to retrieve this metadata from the cache.
     441        // We start by attempting to retrieve this metadata from the cache.
    437442        if(filename != null) {
    438443        metadatum = (ArrayList) get(filename);
     
    441446        metadatum = (ArrayList) get(DIRECTORY_FILENAME);
    442447        }
    443                 // If that failed we consult the document for metadata.
     448        // If that failed we consult the document for metadata.
    444449        if(metadatum == null) {
    445450        metadatum = new ArrayList();
     
    461466                Element filename_element = (Element) filename_elements.item(j);
    462467                String filename_text = MSMUtils.getValue(filename_element);
    463                 // Crappy. There are apparently two ways of assigning, say, directory level metadata to anything in the ac01ne directory from a parent directories metadata.xml.
    464                 // The developers guide way: ac01ne/.*
    465                 // The dls way: ac01ne
    466                 // So the three tests are
    467                 //System.err.println("Check for: " + (filename != null ? filename : ".*"));
    468                 //System.err.println("Folder level = " + folder_level);
    469                 //System.err.println("filename != null && '" + filename + "'.matches('" + filename_text + "') = " + (filename != null ? filename.matches(filename_text) : false));
    470                 //System.err.println("filename != null && '" + filename + "'.matches('" + filename_text + DIRECTORY_FILENAME_SUFFIX + "') = " + (filename != null ? filename.matches(filename_text + DIRECTORY_FILENAME_SUFFIX) : false));
    471                 //System.err.println("filename == null && '" + filename_text + "'.equals('.*') = " + (filename == null ? filename_text.equals(DIRECTORY_FILENAME) : false));
    472                 if((filename != null && (filename.matches(filename_text) || filename.matches(filename_text)))
    473                    || (filename == null && filename_text.equals(DIRECTORY_FILENAME))) {
     468                if(isMatchingFileSet(filename, filename_text, folder_level)) {
    474469                ///ystem.err.println("Match: " + (filename != null ? filename : ".*") + " => " + filename_text);
    475470                // If they match add all of the metadata found in the Description child element, remembering to abide by desired mode (accumulate vs. overwrite).
     
    537532        return metadatum;
    538533    }
     534
     535    private boolean isMatchingFileSet(String filename, String filename_text, boolean folder_level) {
     536        // Crappy. There are apparently two ways of assigning, say, directory level metadata to anything in the ac01ne directory from a parent directories metadata.xml.
     537        // The developers guide way: ac01ne/.*
     538        // The dls way: ac01ne
     539        // So the three tests are:
     540        // 1. Check for an exact match i.e "ac01ne/ac01ne.htm" matches "ac01ne/".*
     541        // 2. Check for a parent folder match, in the absence of further pattern i.e "ac01ne/ac01ne.htm" matches "ac01ne"
     542        // 3. Check for a folder level match if thats what we are looking for i.e "null" matches ".*"
     543
     544        ///ystem.err.println("Check for: " + (filename != null ? filename : ".*"));
     545        ///ystem.err.println("Folder level = " + folder_level);
     546        ///ystem.err.println("filename != null && '" + filename + "'.matches('" + filename_text + "') = " + (filename != null ? filename.matches(filename_text) : false));
     547        ///ystem.err.println("filename != null && '" + filename + "'.matches('" + filename_text + DIRECTORY_FILENAME_SUFFIX + "') [folder level = " + folder_level + "] = " + (filename != null ? filename.matches(filename_text + DIRECTORY_FILENAME_SUFFIX) && folder_level: false));
     548        ///ystem.err.println("filename == null && '" + filename_text + "'.equals('.*') = " + (filename == null ? filename_text.equals(DIRECTORY_FILENAME) : false));
     549        if (filename != null) {
     550        if(folder_level) {
     551            return filename.matches(filename_text) || filename.matches(filename_text + DIRECTORY_FILENAME_SUFFIX);
     552        }
     553        else {
     554            return filename.matches(filename_text);
     555        }
     556        }
     557        else {
     558        return filename_text.equals(DIRECTORY_FILENAME);
     559        }
     560    }
    539561         
    540562    /** Determine is this is a valid Greenstone Directory Metadata file. It may of course just be some xml file with the name metadata.xml. */
Note: See TracChangeset for help on using the changeset viewer.