Changeset 6200


Ignore:
Timestamp:
2003-12-10T16:30:09+13:00 (20 years ago)
Author:
jmt12
Message:

Extracted metadata is now properly and efficently removed before new metadata is extracted

File:
1 edited

Legend:

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

    r6143 r6200  
    6868    if(Gatherer.c_man.msm.getSet(Utility.EXTRACTED_METADATA_NAMESPACE) != null) {
    6969        this.shell = shell;
     70        // The very firstist thing we do is remove any existing extracted metadata
     71        if(Gatherer.c_man != null && Gatherer.c_man.getCollection() != null) {
     72        Gatherer.c_man.getCollection().getGDM().removeExtractedMetadata();
     73        }
     74
    7075        // Determine the collection archive directory.
    7176        File archive_directory = new File(Gatherer.c_man.getCollectionArchive());
     
    144149                // Retrieve the metadata for the current file
    145150                File target_file = new File(file_path);
    146                 ArrayList metadatum = Gatherer.c_man.getCollection().gdm.getMetadata(target_file);
    147                 // Remove any existing metadata for this element
    148                 boolean found = false;
    149                 for(int k = 0; !found && k < metadatum.size(); k++) {
    150                     Metadata sibling = (Metadata) metadatum.get(k);
    151                     ///ystem.err.println("Comparing " + element + " to " + sibling.getElement());
    152                     if(element.equals(sibling.getElement())) {
    153                           ///ystem.err.println("Removing metadata for: " + sibling);
    154                     Gatherer.c_man.getCollection().gdm.metadataChanged(new MSMEvent(this, System.currentTimeMillis(), target_file, sibling, null));
     151                String value = "";
     152                try {
     153                    value = Utility.decodeGreenstone(URLDecoder.decode(MSMUtils.getValue(metadata_element), "UTF-8"));
     154                }
     155                catch(UnsupportedEncodingException error) {
     156                    Gatherer.printStackTrace(error);
     157                }
     158                // If we successfully retrieved a value we can continue.
     159                if(value != null) {
     160                    // Create a new metadata object.
     161                    GValueModel value_tree = Gatherer.c_man.msm.getValueTree(element);
     162                    GValueNode value_node = null;
     163                    if(value_tree != null) {
     164                    value_node = value_tree.getValue(value);
    155165                    }
    156                 }
    157                 metadatum = null;
    158                 if(!found) {
    159                     String value = "";
    160                     try {
    161                     value = Utility.decodeGreenstone(URLDecoder.decode(MSMUtils.getValue(metadata_element), "UTF-8"));
     166                    else {
     167                    value_node = new GValueNode(element.toString(), value);
    162168                    }
    163                     catch(UnsupportedEncodingException error) {
    164                     Gatherer.printStackTrace(error);
    165                     }
    166                     // If we successfully retrieved a value we can continue.
    167                     if(value != null) {
    168                     // Create a new metadata object.
    169                     GValueModel value_tree = Gatherer.c_man.msm.getValueTree(element);
    170                     GValueNode value_node = null;
    171                     if(value_tree != null) {
    172                         value_node = value_tree.getValue(value);
    173                     }
    174                     else {
    175                         value_node = new GValueNode(element.toString(), value);
    176                     }
    177                     Metadata metadata = new Metadata(element, value_node);
    178                     Gatherer.c_man.getCollection().gdm.metadataChanged(new MSMEvent(this, System.currentTimeMillis(), target_file, null, metadata));
    179                     count++;
    180                     // All done. On to next metadata.
    181                     }
    182                 }
     169                    Metadata metadata = new Metadata(element, value_node);
     170                    element.inc();
     171                    ///ystem.err.println("Adding extracted metadata: " + metadata);
     172                    Gatherer.c_man.getCollection().msm.fireMetadataChanged(new MSMEvent(this, System.currentTimeMillis(), target_file, null, metadata));
     173                    count++;
     174                    // All done. On to next metadata.
     175                }
     176                value = null;
    183177                target_file = null;
    184178                }
Note: See TracChangeset for help on using the changeset viewer.