Changeset 7168


Ignore:
Timestamp:
2004-03-31T13:58:29+12:00 (20 years ago)
Author:
mdewsnip
Message:

Put Katherine's backing up metadata.xml files code back in.

Location:
trunk/gli/src/org/greenstone/gatherer
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/collection/CollectionManager.java

    r7166 r7168  
    844844        // We first recurse the Import folder tree, reading in any metadata.xml files, and then altering the non-namespaced element names to be valid GLI names
    845845        LegacyCollectionImporter lci = new LegacyCollectionImporter(collection_directory, collection.cdm);
     846        lci.backupMetadataXMLFiles(collection_directory);
    846847        lci.importMetadata();
    847848        lci.updateClassifiers();
     
    928929    return true;
    929930    }
     931
     932
     933//      // now try to load in existing metadata, delete the existing metadata.xml files, then save the new ones.
     934//      private boolean findAndLoadExistingMetadata(File collection_dir)
     935//      {
     936//      TreeModel collection_tree = getRecordSet();
     937//      FileNode root_node = (FileNode) collection_tree.getRoot();
     938//      if (searchForMetadata(collection_tree, root_node) == false) {
     939//          return false;
     940//      }
     941//      collection.gdm.save(root_node);
     942//      return true;
     943//      }
     944
    930945
    931946    private boolean searchForMetadata(TreeModel collection_tree, FileNode current_node) {
  • trunk/gli/src/org/greenstone/gatherer/msm/LegacyCollectionImporter.java

    r7119 r7168  
    105105
    106106
     107    // This copies all the existing metadata.xml files into a backup directory
     108    public void backupMetadataXMLFiles(File collection_dir)
     109    {
     110    File import_dir = new File(collection_dir, Utility.IMPORT_DIR);
     111    File import_bak_dir = new File(collection_dir, Utility.IMPORT_BAK_DIR);
     112    import_bak_dir.mkdir();
     113    copyMetadataXMLFiles(import_dir, import_bak_dir);
     114    }
     115
     116
     117    private void copyMetadataXMLFiles(File source_dir, File target_dir)
     118    {
     119    // Find the metadata.xml file in this dir
     120    File metadata_file = new File(source_dir, StaticStrings.METADATA_XML);
     121    if (metadata_file.exists()) {
     122        File backup_metadata_file = new File(target_dir, StaticStrings.METADATA_XML);
     123        try {
     124        target_dir.mkdirs();
     125        Gatherer.f_man.getQueue().copyFile(metadata_file, backup_metadata_file, null);
     126        if (!backup_metadata_file.exists()) {
     127            throw new Exception("");
     128        }
     129        }
     130        catch (Exception e) {
     131        Gatherer.println("Exception: couldn't copy file " + metadata_file.getPath() + e.getMessage());
     132        }
     133    }
     134
     135    // Now go through child directories
     136    File [] children = source_dir.listFiles();
     137    for (int i = 0; i < children.length; i++) {
     138        File child = children[i];
     139        if (child.isDirectory()) {
     140        copyMetadataXMLFiles(child, new File(target_dir, child.getName()));
     141        }
     142    }
     143    }
     144
     145
    107146    public void importMetadata()
    108147    {
     
    137176    }
    138177
    139     // First, copy the original file to make a backup
    140     File backup_file = new File(file.getParentFile(), StaticStrings.METADATA_BAK);
    141     try {
    142         Gatherer.f_man.getQueue().copyFile(file, backup_file, null);
    143         if (!backup_file.exists()) {
    144         throw new Error();
    145         }
    146     }
    147     catch (Exception ex) {
    148         System.err.println("Exception occurred while importing legacy collection.");
    149         System.err.println("Error: Could not backup metadata.xml file to " + backup_file);
    150         ex.printStackTrace();
    151         System.err.println("Aborting legacy collection import.");
    152         cancelled = true;
    153         return;
    154     }
     178//      // First, copy the original file to make a backup
     179//      File backup_file = new File(file.getParentFile(), StaticStrings.METADATA_BAK);
     180//      try {
     181//          Gatherer.f_man.getQueue().copyFile(file, backup_file, null);
     182//          if (!backup_file.exists()) {
     183//          throw new Error();
     184//          }
     185//      }
     186//      catch (Exception ex) {
     187//          System.err.println("Exception occurred while importing legacy collection.");
     188//          System.err.println("Error: Could not backup metadata.xml file to " + backup_file);
     189//          ex.printStackTrace();
     190//          System.err.println("Aborting legacy collection import.");
     191//          cancelled = true;
     192//          return;
     193//      }
    155194
    156195    // Parse the metadata.xml file
Note: See TracChangeset for help on using the changeset viewer.