Changeset 4316


Ignore:
Timestamp:
2003-05-23T16:39:12+12:00 (21 years ago)
Author:
jmt12
Message:

modified to handle dummy runs over base collections

File:
1 edited

Legend:

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

    r4293 r4316  
    8282     static final private String MODE_ATTRIBUTE = "mode";
    8383     static final private String NAME_ATTRIBUTE = "name";
     84     static final private String SEPARATOR = "/";
    8485
    8586     /** A list of the collect.cfg paths that we should ignore. */
     
    9798     /** Locate and import any metadata parsed by this metadata parser given the file involved and its previous incarnation. */
    9899     public boolean process(FileNode destination, FileNode origin, boolean folder_level, boolean dummy_run) {
    99           Gatherer.println("GreenstoneMetadataParser: Process " + origin + ": ");
     100          ///atherer.println("GreenstoneMetadataParser: Process " + origin + ": ");
    100101          int counter = 0;
    101102          dialog_cancelled = false;
     
    161162                     }
    162163                     if(filename != null) {
    163                           filename = file.getName() + "/" + filename;
     164                          filename = file.getName() + SEPARATOR + filename;
    164165                     }
    165166                     else {
    166                           filename = file.getName() + "/";
     167                          filename = file.getName();
    167168                     }
    168169                     file = file.getParentFile();
     
    175176                for(int i = 0; i < search_files.size(); i++) {
    176177                     MetadataXMLFileSearch a_search = (MetadataXMLFileSearch) search_files.get(i);
    177                      ///ystem.err.println("Search " + a_search.file.getAbsolutePath() + " for " + (a_search.filename != null ? a_search.filename : "directory metadata"));
     178                     ///ystem.err.println("Search " + a_search.file.getAbsolutePath() + " for " + (a_search.filename != null ? a_search.filename : ".*"));
    178179                     // Retrieve the document
    179180                     BasicGDMDocument document = getDocument(a_search.file);
     
    210211          ///ystem.err.print("6 ");
    211212          // Used in a complicated test later on.
    212           ArrayList inherited_metadata = null;
    213           if(destination != null) {
    214                 inherited_metadata = Gatherer.c_man.getCollection().gdm.getMetadata(destination.getFile());
    215           }
    216           else {
    217                 inherited_metadata = new ArrayList();
    218           }
    219213          for(int i = 0; !dialog_cancelled && i < metadatum.size(); i++) {
    220214                BasicMetadata basic_metadata = (BasicMetadata) metadatum.get(i);
     
    298292                if(!dummy_run && final_metadata != null && !dialog_cancelled) {
    299293                     final_metadata.setAccumulate(metadata.accumulates);
    300                      // There is one final test, caused by the advent of directory vs file level metadata, but its a mouthfull to explain. And it goes a little something like this:
    301                      // When you drag in a single file you want to record all of the metadata, both file and directory level, associated with it. If a user later sets directory level metadat this is overridden by directory level metadat present at file level in this file then that is just too bad. For example a user gathers a file, ec121e.htm, into a their folder 'docs/'. ec121e.htm has amoungst its metadata 'Date=01-01-01' which it inherited from its folder (ec121e/). Later the user sets 'Date=15-06-03' for the folder 'docs/'. The Date metadata now at the file level of ec121e.htm will now overwrite any such setting, which wouldn't have happened if magically the folder level metadata had stayed folder level. Of course thats some impossible magic due to the fact that source folder structure is unlikely to match destination level when moving individual files, and even asking for the metadata the the new file will inherit won't help (except by chance).
    302                      // Now consider a user dragging in a folder containing several files or folders. Essentially the same tatic taken above is used for the top level folder being moved, in that any and all metadata, inherited or no, is added to this new folder in the collection. However when adding subsequent files and folders it becomes possible to notice if inherited metadata is already set (just ask the collections GDMManager what metadata is available for a certain file -before- the file is actually added to the collection. This being the case only those unique metadata should subsequently be added to the file. Note that these unique metadata may still include directory level metadata that would have been better off added to a folder, but since none is available we make do.
    303                      if(!inherited_metadata.contains(final_metadata) || final_metadata.accumulates()) {
    304                           // Now we can finally add the metadata.
    305                           Gatherer.c_man.getCollection().msm.fireMetadataChanged(0, destination, null, final_metadata);
    306                      }
    307                      else {
    308                           ///ystem.err.println("Metadata already exists: " + final_metadata);
    309                      }
     294                     // Now we can finally add the metadata.
     295                     ///ystem.err.println("Adding Metadata: " + final_metadata);
     296                     Gatherer.c_man.getCollection().msm.fireMetadataChanged(0, destination, null, final_metadata);
    310297                }
    311298                // Otherwise there is no way to add this metadata. No value model no metadata value.
     
    478465                                     // The dls way: ac01ne
    479466                                     // So the three tests are
    480                                      ///ystem.err.println("Check for:");
    481                                      ///ystem.err.println("filename != null && '" + filename + "'.matches('" + filename_text + "') = " + (filename != null ? filename.matches(filename_text) : false));
    482                                      ///ystem.err.println("filename != null && '" + filename + "'.matches('" + filename_text + DIRECTORY_FILENAME_SUFFIX + "') = " + (filename != null ? filename.matches(filename_text + DIRECTORY_FILENAME_SUFFIX) : false));
    483                                      ///ystem.err.println("filename == null && '" + filename_text + "'.equals('.*') = " + (filename == null ? filename_text.equals(DIRECTORY_FILENAME) : false));
    484                                      if((filename != null && (filename.matches(filename_text) || filename.matches(filename_text + DIRECTORY_FILENAME_SUFFIX)))
     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)))
    485473                                         || (filename == null && filename_text.equals(DIRECTORY_FILENAME))) {
    486                                           ///ystem.err.println("Match!!!");
     474                                          ///ystem.err.println("Match: " + (filename != null ? filename : ".*") + " => " + filename_text);
    487475                                          // If they match add all of the metadata found in the Description child element, remembering to abide by desired mode (accumulate vs. overwrite).
    488476                                          NodeList description_elements = fileset_element.getElementsByTagName(DESCRIPTION_ELEMENT);
Note: See TracChangeset for help on using the changeset viewer.