Changeset 4370


Ignore:
Timestamp:
2003-05-27T17:00:14+12:00 (21 years ago)
Author:
jmt12
Message:

Fixes to removeMetadata to prevent it removing folder level metadata for a file level replace, and addMetadata to stop it adding erroneous filesets despite it finding an existing fileset - John

File:
1 edited

Legend:

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

    r4365 r4370  
    6767    }
    6868    catch (Exception error) {
    69                 // Poorly formed, or completely invalid metadata.xml file!
     69        // Poorly formed, or completely invalid metadata.xml file!
    7070    }
    7171    }
     
    7878    System.err.println("Add '" + metadata + "' to " + (filename != null ? filename : "directory."));
    7979    try {
    80                 // Retrieve the document element.
     80        // Retrieve the document element.
    8181        Element directorymetadata_element = base_document.getDocumentElement();
    82                 // Iterate through the filesets looking for one that matches the given filename.
     82        // Iterate through the filesets looking for one that matches the given filename.
    8383        Element fileset_element = null;
     84        boolean found = false;
    8485        NodeList fileset_elements = directorymetadata_element.getElementsByTagName(FILESET_ELEMENT);
    85         for(int i = 0; i < fileset_elements.getLength(); i++) {
     86        for(int i = 0; !found && i < fileset_elements.getLength(); i++) {
    8687        fileset_element = (Element) fileset_elements.item(i);
    8788        NodeList filename_elements = fileset_element.getElementsByTagName(FILENAME_ELEMENT);
    88         boolean found = false;
    8989        for(int j = 0; !found && j < filename_elements.getLength(); j++) {
    9090            Element filename_element = (Element) filename_elements.item(j);
     
    109109        }
    110110        fileset_elements = null;
    111                 // If we still haven't found an existing fileset, then its time to create one.
     111        // If we still haven't found an existing fileset, then its time to create one.
    112112        if(fileset_element == null) {
    113113        System.err.println("Creating a new fileset.");
     
    367367            Element filename_element = (Element) filename_elements.item(j);
    368368            String filename_text = MSMUtils.getValue(filename_element);
    369             if((filename != null && filename.matches(filename_text)) || filename_text.equals(DIRECTORY_FILENAME)) {
     369            if((filename != null && filename.matches(filename_text) && !filename.equals(DIRECTORY_FILENAME)) || (filename == null && filename_text.equals(DIRECTORY_FILENAME))) {
    370370            // Retrieve the Metadata Element for this fileset, and iterate through them looking for the one which we are to remove.
    371371            NodeList description_elements = fileset_element.getElementsByTagName("Description");
     
    373373                Element description_element = (Element) description_elements.item(k);
    374374                NodeList metadata_elements = description_element.getElementsByTagName("Metadata");
    375                 for(int l = 0; !found && !make_next_metadata_element_overwrite && l < metadata_elements.getLength(); l++) {     
     375                for(int l = 0; (!found || !make_next_metadata_element_overwrite) && l < metadata_elements.getLength(); l++) {       
    376376                Element metadata_element = (Element) metadata_elements.item(l);
    377377                String element = metadata_element.getAttribute("name");
     
    386386                    // If this was the first metadata with this element found, and it was set to overwrite, then we have to ensure that the next metadata with this element found (if any) is changed to be overwrite now.
    387387                    if(first_metadata_element_found && !metadata.accumulates()) {
     388                        System.err.println("First of this element found!");
    388389                        make_next_metadata_element_overwrite = true;
    389390                    }
     
    391392                    // If this was the first metadata we've found with the element of the one to be removed set first found to false.
    392393                    else if(first_metadata_element_found) {
     394                    System.err.println("Found a matching element: " + element + "=" + value);
    393395                    first_metadata_element_found = false;
    394396                    }
    395397                    // Otherwise we should make this metadata overwrite as requested.
    396398                    else if(make_next_metadata_element_overwrite) {
     399                    System.err.println("Changing to overwrite: " + element + "=" + value);
    397400                    metadata_element.setAttribute(MODE_ATTRIBUTE, "");
    398401                    }
Note: See TracChangeset for help on using the changeset viewer.