Changeset 6026
- Timestamp:
- 2003-11-28T17:39:07+13:00 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/collection/CollectionManager.java
r5996 r6026 55 55 import org.greenstone.gatherer.gui.ExternalCollectionPrompt; 56 56 import org.greenstone.gatherer.gui.NewMetaSetPrompt; 57 import org.greenstone.gatherer.gui.WarningDialog; 57 58 import org.greenstone.gatherer.gui.tree.WorkspaceTree; 58 59 import org.greenstone.gatherer.msm.ElementWrapper; 59 60 import org.greenstone.gatherer.msm.GDMManager; 60 61 import org.greenstone.gatherer.msm.GreenstoneArchiveParser; 62 import org.greenstone.gatherer.msm.LegacyCollectionImporter; 61 63 import org.greenstone.gatherer.msm.MetadataSet; 62 64 import org.greenstone.gatherer.msm.MetadataSetManager; … … 799 801 collection.cdm = new CollectionDesignManager(new File(collection_file.getParent(), Utility.CONFIG_DIR)); 800 802 if (non_gatherer_collection) { 801 // do a dummy load of GDMManager - so we don't load in the old 802 // metadata.xml files, we just create new empty ones. 803 collection.gdm = new GDMManager(true); 804 if (findAndLoadExistingMetadata(collection_directory)==false) { 805 lock_file = null; 806 collection_directory = null; 807 closeCollection(); 808 return false; 809 } 810 } else { 811 collection.gdm = new GDMManager(); 812 } 803 // 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 804 LegacyCollectionImporter lci = new LegacyCollectionImporter(collection_directory, collection.cdm); 805 lci.importMetadata(); 806 lci = null; 807 } 808 809 // Whether the collection is legacy or not, we should now be able to prepared the GDMManager 810 collection.gdm = new GDMManager(); 813 811 814 812 // Tell everyone that it worked. … … 885 883 886 884 return true; 887 } 888 889 890 // now try to load in existing metadata, delete the existing metadata.xml files, then save the new ones. 891 private boolean findAndLoadExistingMetadata(File collection_dir) { 892 893 TreeModel collection_tree = getRecordSet(); 894 FileNode root_node = (FileNode)collection_tree.getRoot(); 895 if (searchForMetadata(collection_tree, root_node)==false) { 896 return false; 897 } 898 removeOldMetadataFiles(collection_dir); 899 collection.gdm.save(root_node); 900 return true; 901 } 902 903 // this moves all the existing metadata files into a back up directory 904 public void removeOldMetadataFiles(File collection_dir) { 905 File import_dir = new File(collection_dir, Utility.IMPORT_DIR); 906 File import_bak_dir = new File(collection_dir, Utility.IMPORT_BAK_DIR); 907 import_bak_dir.mkdir(); 908 909 moveMetadataFiles(import_dir, import_bak_dir); 910 911 } 912 913 private boolean moveMetadataFiles(File source_dir, File dest_dir) { 914 915 // find the metadata file in this dir 916 File meta_file = new File(source_dir, "metadata.xml"); 917 if (meta_file.exists()) { 918 File new_meta_file = new File(dest_dir, "metadata.xml"); 919 try { 920 dest_dir.mkdirs(); 921 if (meta_file.renameTo(new_meta_file)== false) { 922 throw new Exception(""); 923 } 924 } catch (Exception e) { 925 Gatherer.println("Exception: couldn't move the file "+meta_file.getPath() + e.getMessage()); 926 } 927 } 928 929 // now go through child directories 930 File [] children = source_dir.listFiles(); 931 for (int i=0; i<children.length; i++) { 932 File child = children[i]; 933 if (child.isDirectory()) { 934 moveMetadataFiles(child, new File(dest_dir, child.getName())); 935 } 936 } 937 return true; 938 } 939 885 } 940 886 941 887 private boolean searchForMetadata(TreeModel collection_tree, FileNode current_node) { … … 969 915 String command[]; 970 916 if(Utility.isWindows()) { 971 if(description == null || email == null ||title == null) {917 if(description == null || title == null) { 972 918 command = new String[4]; 919 command[0] = Gatherer.config.perl_path; 920 command[1] = "-S"; 921 command[2] = Gatherer.config.getScriptPath() + "mkcol.pl"; 922 command[3] = name; 923 } 924 // Users are no longer required to supply an email 925 else if(email == null) { 926 command = new String[8]; 927 command[0] = Gatherer.config.perl_path; 928 command[1] = "-S"; 929 command[2] = Gatherer.config.getScriptPath() + "mkcol.pl"; 930 command[3] = "-title"; 931 command[4] = title; 932 command[5] = "-about"; 933 command[6] = description; 934 command[7] = name; 973 935 } 974 936 else { 975 937 command = new String[10]; 976 } 977 command[0] = Gatherer.config.perl_path; 978 command[1] = "-S"; 979 command[2] = Gatherer.config.getScriptPath() + "mkcol.pl"; 980 if(description == null || email == null || title == null) { 981 command[3] = name; 982 } 983 else { 938 command[0] = Gatherer.config.perl_path; 939 command[1] = "-S"; 940 command[2] = Gatherer.config.getScriptPath() + "mkcol.pl"; 984 941 command[3] = "-title"; 985 942 command[4] = title; … … 992 949 } 993 950 else { 994 if(description == null || email == null ||title == null) {951 if(description == null || title == null) { 995 952 command = new String[2]; 996 953 command[0] = "mkcol.pl"; 997 954 command[1] = name; 955 } 956 else if(email == null) { 957 command = new String[6]; 958 command[0] = "mkcol.pl"; 959 command[1] = "-title"; 960 command[2] = title; 961 command[3] = "-about"; 962 command[4] = description; 963 command[5] = name; 998 964 } 999 965 else { … … 1051 1017 ///ystem.err.println("Recieved process complete event - " + event); 1052 1018 // If we were running an import, now run a build. 1053 if(event.getType() == GShell.IMPORT && event.getStatus() != GShell.ERROR) {1019 if(event.getType() == GShell.IMPORT && event.getStatus() == GShell.OK) { 1054 1020 // Finish import. 1055 1021 collection.setImported(true); … … 1057 1023 } 1058 1024 // If we were running a build, now is when we move files across. 1059 else if(event.getType() == GShell.BUILD && event.getStatus() != GShell.ERROR) { 1060 ///ystem.err.println("Installing collection."); 1025 else if(event.getType() == GShell.BUILD && event.getStatus() == GShell.OK) { 1061 1026 if(installCollection()) { 1062 1027 // If we have a local library running (that we know about) then we ask it to add our newly create collection 1063 ///ystem.err.println("Check if we should reset local server.");1064 1028 if(Gatherer.config.exec_file != null) { 1065 ///ystem.err.println("Local Library Found!");1066 //Gatherer.g_man.preview_pane.configServer(GSDLSiteConfig.ADD_COMMAND + collection.getName());1067 1029 Gatherer.self.configServer(GSDLSiteConfig.ADD_COMMAND + collection.getName()); 1068 1030 } 1069 //else { 1070 ///ystem.err.println("GLI can't recognize a local library."); 1071 //} 1072 // Signal collection changed. 1073 // workspace_model = null; 1031 WarningDialog collection_built_warning_dialog = new WarningDialog("warning.CollectionBuilt", false); 1032 collection_built_warning_dialog.display(); 1033 collection_built_warning_dialog.dispose(); 1034 collection_built_warning_dialog = null; 1074 1035 Gatherer.g_man.collectionChanged(ready()); 1075 JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("CollectionManager.Preview_Ready"), Dictionary.get("CollectionManager.Preview_Ready_Title"), JOptionPane.INFORMATION_MESSAGE);1076 1036 } 1077 1037 else {
Note:
See TracChangeset
for help on using the changeset viewer.