Ignore:
Timestamp:
2003-06-16T10:44:18+12:00 (21 years ago)
Author:
jmt12
Message:

* empty log message *

Location:
trunk/gli/src/org/greenstone/gatherer/msm
Files:
3 edited

Legend:

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

    r4515 r4674  
    3636import org.greenstone.gatherer.valuetree.GValueNode;
    3737import org.w3c.dom.*;
    38 /** This class wraps around a DOM Document providing methods for accessing the data within. In this case the DOM represents a Greenstone Directory metadata file. It provides the necessary functionality to create a new metadata.xml file. 
     38/** This class wraps around a DOM Document providing methods for accessing the data within. In this case the DOM represents a Greenstone Directory metadata file. It provides the necessary functionality to create a new metadata.xml file.
    3939 * @author John Thompson, Greenstone Digital Library, University of Waikato
    4040 * @version 2.3b
     
    150150        for(int l = 0; !will_accumulate && l < sibling_metadata_elements.getLength(); l++) {
    151151            Element sibling_metadata_element = (Element) sibling_metadata_elements.item(l);
    152             will_accumulate = sibling_metadata_element.getAttribute(NAME_ATTRIBUTE).equals(metadata_element.getAttribute(NAME_ATTRIBUTE));
     152            // It appears that its possible that we can be asked to add the same metadata twice (especially after a copy action is cancelled then repeated). So we check if we have been asked to add exactly the same value twice.
     153            if(sibling_metadata_element.getAttribute(NAME_ATTRIBUTE).equals(metadata_element.getAttribute(NAME_ATTRIBUTE))) {
     154                // Check the values and return if they are the same.
     155                //if(metadata_element.getAttribute(NAME_ATTRIBUTE).equalsIgnoreCase("dls.Title")) {
     156                //  Gatherer.println("Comparing:");
     157                //  Gatherer.println("'" + metadata.getAbsoluteValue() + "'");
     158                //  Gatherer.println(" with:");
     159                //  Gatherer.println("'" + MSMUtils.getValue(sibling_metadata_element) + "'");
     160                //}
     161                if(metadata.getAbsoluteValue().equals(MSMUtils.getValue(sibling_metadata_element))) {
     162                //  Gatherer.println("Value already exists: " + metadata);
     163                    return;
     164                }
     165                will_accumulate = true;
     166            }
    153167            sibling_metadata_element = null;
    154168        }
     
    187201    }
    188202    /** Get all of the metadata, including directory level, associated with this file. */
    189     public ArrayList getMetadata(String filename, boolean remove, ArrayList metadatum_so_far, File file) {
    190     return getMetadata(filename, remove, metadatum_so_far, file, false);
     203    public ArrayList getMetadata(String filename, boolean remove, ArrayList metadatum_so_far, File file, boolean append_folder_level) {
     204    return getMetadata(filename, remove, metadatum_so_far, file, append_folder_level, false);
    191205    }
    192206    /** Retrieve the metadata associated with the given filename. Keep track of what metadata should be overwritten and what should be accumulated. Also make note of the source file, and remove the metadata if required. Finally if purge is set retrieve every piece of metadata in this file. */
    193     public ArrayList getMetadata(String filename, boolean remove, ArrayList metadatum_so_far, File file, boolean purge) {
     207    public ArrayList getMetadata(String filename, boolean remove, ArrayList metadatum_so_far, File file, boolean append_folder_level, boolean purge) {
    194208    ///ystem.err.println("Get metadata for " + filename);
    195209    ArrayList metadatum = null;
     
    211225            Element filename_element = (Element) filename_elements.item(j);
    212226            String filename_text = MSMUtils.getValue(filename_element);
    213             if((filename != null && filename.matches(filename_text)) || filename_text.equals(DIRECTORY_FILENAME) || purge) {
     227            if((filename != null && filename.matches(filename_text)) || ((filename == null || append_folder_level) && filename_text.equals(DIRECTORY_FILENAME)) || purge) {
    214228            // If they match add all of the metadata found in the Description child element, remembering to abide by desired mode (accumulate vs. overwrite).
    215229            NodeList description_elements = fileset_element.getElementsByTagName(DESCRIPTION_ELEMENT);
     
    236250                    ElementWrapper element = Gatherer.c_man.getCollection().msm.getElement(raw_element);
    237251                    if (element != null) {
    238                    
     252
    239253                    GValueNode value = Metadata.getDefaultValueNode(element, raw_value);
    240254                    ///ystem.err.println("Miss. Create new metadata: " + raw_element + " -> " + raw_value + "\n");
     
    244258                    value = null;
    245259                    element = null;
    246                     } 
     260                    }
    247261                }
    248262                // check whether the metadata is null
     
    251265                    if(filename != null) {
    252266                    ///ystem.err.println("Filename      = " + filename);
    253                     ///ystem.err.println("filename_text = " + filename_text); 
     267                    ///ystem.err.println("filename_text = " + filename_text);
    254268                    // If can only be file level if there is no folder path details in filename and if the filename matched the filename text node (it may have matched .* instead)!
    255269                    if(filename.indexOf(File.separator) == -1 && filename.equals(filename_text)) {
     
    267281                    }
    268282                    metadata.setFile(file);
    269                    
     283
    270284                // If mode is overwrite, then remove any previous values for this metadata element.
    271285                    if(mode.equals("accumulate")) {
     
    285299                    }
    286300                    mode = null;
    287                    
     301
    288302                // Add the completed metadata and clean up
    289303                ///ystem.err.println("Adding metadata: " + metadata);
    290304                    metadatum.add(metadata);
    291                    
     305
    292306                // Having found our metadata check if the value from the xml matches the one from the gvaluenode. If not update it. This happens whenever hierarchy information is involved (indexes rapidly become obsolete).
    293307                // If remove was set, remove it. We can only remove pure file level metadata, or folder level iff we were asked for folder level.
     
    378392                Element description_element = (Element) description_elements.item(k);
    379393                NodeList metadata_elements = description_element.getElementsByTagName("Metadata");
    380                 for(int l = 0; (!found || !make_next_metadata_element_overwrite) && l < metadata_elements.getLength(); l++) {       
     394                for(int l = 0; (!found || !make_next_metadata_element_overwrite) && l < metadata_elements.getLength(); l++) {
    381395                Element metadata_element = (Element) metadata_elements.item(l);
    382396                String element = metadata_element.getAttribute("name");
     
    428442        Gatherer.printStackTrace(error);
    429443    }
    430     }   
     444    }
    431445
    432446    /** Change the up to date flag. */
  • trunk/gli/src/org/greenstone/gatherer/msm/GDMManager.java

    r4595 r4674  
    5656*/
    5757public class GDMManager
    58     extends HashMap 
     58    extends HashMap
    5959    implements MSMListener {
    6060    /** A list of the known metadata instances, thus we only store one of each unique metadata, and reference the rest. */
     
    8484    }
    8585    }
    86     /** Destructor necessary for clean exit, subsequent to saving of metadata.xml files. 
     86    /** Destructor necessary for clean exit, subsequent to saving of metadata.xml files.
    8787      * @see org.greenstone.gatherer.Gatherer
    8888      * @see org.greenstone.gatherer.collection.CollectionManager
     
    154154    /** Recover the metadata associated with a particular file. Note that this call is synchronized, so that all of the data holders don't need to be. */
    155155    public synchronized ArrayList getMetadata(File file) {
    156     return getMetadata(file, false);
     156    return getMetadata(file, false, true);
     157    }
     158
     159/** Recover the metadata associated with a particular file excluding folder level metadata. Note that this call is synchronized, so that all of the data holders don't need to be. */
     160    public synchronized ArrayList getMetadataOnly(File file) {
     161    return getMetadata(file, false, false);
    157162    }
    158163
    159164    public synchronized ArrayList getMetadata(File file, ElementWrapper element) {
    160     ArrayList metadata = getMetadata(file, false);
     165    ArrayList metadata = getMetadata(file, false, true);
    161166    ArrayList values = new ArrayList();
    162167    for(int i = 0; i < metadata.size(); i++) {
     
    172177    }
    173178
    174     private ArrayList getMetadata(File file, boolean remove) {
     179    private ArrayList getMetadata(File file, boolean remove, boolean append_folder_level) {
    175180    ArrayList metadata = null;
    176181    String filename = null;
     
    181186    GDMDocument document = getDocument(file);
    182187    if(document != null) {
    183         metadata = document.getMetadata(filename, remove, metadata, file);
     188        metadata = document.getMetadata(filename, remove, metadata, file, append_folder_level);
    184189        document = null;
    185190    }
     
    221226        if(document != null) {
    222227        // There is one piece of slight of hand here. You can never remove metadata during a get all metadata.
    223         metadata = document.getMetadata(a_search.filename, false, metadata, a_search.file);
     228        metadata = document.getMetadata(a_search.filename, false, metadata, a_search.file, true);
    224229        ///ystem.err.println("Current metadata: " + toString(metadata));
    225230        document = null;
     
    233238    search_files = null;
    234239    return metadata;
    235     } 
     240    }
    236241
    237242    public String toString(ArrayList list) {
     
    244249    }
    245250    text.append(")");
    246     return text.toString();       
     251    return text.toString();
    247252    }
    248253
     
    300305
    301306    public ArrayList removeMetadata(File file) {
    302     return getMetadata(file, true);
    303     }
    304 
    305     /** Causes all currently loaded GDMDocuments to write themselves out. 
     307    return getMetadata(file, true, false);
     308    }
     309
     310    /** Causes all currently loaded GDMDocuments to write themselves out.
    306311      * @see org.greenstone.gatherer.msm.GDMDocument
    307312      */
  • trunk/gli/src/org/greenstone/gatherer/msm/MetadataSetManager.java

    r4673 r4674  
    579579        mds_hashtable.put(family, mds_new);
    580580        }
    581         fireSetChanged(mds_new);
    582581        return true;
    583582    }
     
    915914    // And make back ups of all existing metadata set files.
    916915    File temp[] = file.listFiles();
    917     for(int i = 0; temp != null && i < temp.length; i++) {
     916    for(int i = temp.length - 1; i >= 0; i--) {
    918917        if(temp[i].getName().endsWith(".mds") || temp[i].getName().endsWith(".mdv")) {
    919918        File backup = new File(temp[i].getAbsolutePath() + "~");
Note: See TracChangeset for help on using the changeset viewer.