Ignore:
Timestamp:
2003-11-25T16:25:15+13:00 (21 years ago)
Author:
jmt12
Message:

Now that it knows whether it was called from an assign or a replace action, GDMDocument can correctly deal with metadata that should either accumulate with or overwrite inherited metadata

File:
1 edited

Legend:

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

    r5808 r5998  
    8282    }
    8383
    84     /** Add this metadata to the named file. There is one tricky thing to consider. Whenever a metadata entry is added it is taken to be accumulating except if it is the first added, in which case it overwrites! */
    85     public void addMetadata(String filename, Metadata metadata) {
     84    /** Add this metadata to the named file. There is one tricky thing to consider. Whenever a metadata entry is added it is taken to be accumulating except if it is the first added, in which case it overwrites! Actually this gets worse, as we could have been told to append this metadata to a document which already inherits metadata. Thus we need a new argument to determine whether this add was triggered by an append or a replace. */
     85    public void addMetadata(String filename, Metadata metadata, boolean force_accumulate) {
    8686    Gatherer.println("Add '" + metadata + "' to " + (filename != null ? filename : "directory."));
    8787    try {
     
    176176        }
    177177        sibling_description_elements = null;
    178         if(will_accumulate) { //mode.equals(ACCUMULATE)) {
     178        if(will_accumulate || force_accumulate) { //mode.equals(ACCUMULATE)) {
    179179        metadata_element.setAttribute(MODE_ATTRIBUTE, ACCUMULATE);
    180180        }
     
    295295                // Using the element string and value, retrieve a matching Metadata object from the cache
    296296                Metadata metadata = null;
    297                 // If this element has hierarchy values then we must ensure the raw value is a full path, not an index.
    298                 if(GDMManager.metadata_cache.contains(raw_element, raw_value)) {
     297                // If this element has hierarchy values then we must ensure the raw value is a full path, not an index.
     298                // Try to retrieve an already comstructed piece of metadata from file - but not if we are purging, as this will stuff up anything that is still using that metadata - such as the GTable
     299                if(GDMManager.metadata_cache.contains(raw_element, raw_value) && !purge) {
    299300                    ///ystem.err.println("HIT! Retrieve metadata from cache: " + raw_element + " -> " + raw_value + "\n");
    300301                    metadata = (Metadata) GDMManager.metadata_cache.get(raw_element, raw_value);
     
    307308                    ///ystem.err.println("Miss. Create new metadata: " + raw_element + " -> " + raw_value + "\n");
    308309                    metadata = new Metadata(element, value);
    309                     GDMManager.metadata_cache.put(raw_element, raw_value, metadata);
     310                    if(!purge) {
     311                        GDMManager.metadata_cache.put(raw_element, raw_value, metadata);
     312                    }
    310313                    ///ystem.err.println("Added metadata to cache: " + raw_element + " -> " + raw_value + "\n");
    311314                    value = null;
     
    432435        boolean first_metadata_element_found = true;
    433436        boolean make_next_metadata_element_overwrite = false;
    434                 // Retrieve the document element.
     437        boolean remove_fileset = false;
     438        // Retrieve the document element.
    435439        Element directorymetadata_element = base_document.getDocumentElement();
    436                 // Iterate through the filesets looking for the directory level one.
     440        // Iterate through the filesets looking for the directory level one.
    437441        NodeList fileset_elements = directorymetadata_element.getElementsByTagName(FILESET_ELEMENT);
    438         for(int i = 0; i < fileset_elements.getLength(); i++) {
     442        for(int i = 0; !found && i < fileset_elements.getLength(); i++) {
    439443        Element fileset_element = (Element) fileset_elements.item(i);
    440444        NodeList filename_elements = fileset_element.getElementsByTagName(FILENAME_ELEMENT);
    441         for(int j = 0; j < filename_elements.getLength(); j++) {
     445        for(int j = 0; !found && j < filename_elements.getLength(); j++) {
    442446            Element filename_element = (Element) filename_elements.item(j);
    443447            String filename_text = MSMUtils.getValue(filename_element);
     
    445449            // Retrieve the Metadata Element for this fileset, and iterate through them looking for the one which we are to remove.
    446450            NodeList description_elements = fileset_element.getElementsByTagName("Description");
    447             for(int k = 0; k < description_elements.getLength(); k++) {
     451            for(int k = 0; !found && k < description_elements.getLength(); k++) {
    448452                Element description_element = (Element) description_elements.item(k);
    449453                NodeList metadata_elements = description_element.getElementsByTagName("Metadata");
     
    480484                metadata_element = null;
    481485                }
     486                metadata_elements = description_element.getElementsByTagName("Metadata");
     487                // If we found it, removed it, and now the description tag has no children, mark the fileset for removal
     488                if(metadata_elements.getLength() == 0) {
     489                remove_fileset = true;
     490                }
    482491                metadata_elements = null;
    483492                description_element = null;
     
    489498        }
    490499        filename_elements = null;
     500        if(found && remove_fileset) {
     501            directorymetadata_element.removeChild(fileset_element);
     502        }
    491503        fileset_element = null;
    492504        }
Note: See TracChangeset for help on using the changeset viewer.