- Timestamp:
- 2003-06-11T13:43:03+12:00 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/collection/CollectionManager.java
r4513 r4557 53 53 import org.greenstone.gatherer.gui.MetaEditPane; 54 54 import org.greenstone.gatherer.gui.NewCollectionMetadataPrompt; 55 import org.greenstone.gatherer.msm.ElementWrapper; 55 56 import org.greenstone.gatherer.msm.GDMManager; 57 import org.greenstone.gatherer.msm.GreenstoneArchiveParser; 56 58 import org.greenstone.gatherer.msm.MetadataSet; 57 59 import org.greenstone.gatherer.msm.MetadataSetManager; … … 195 197 } 196 198 197 /** Used to set the current collection to the given collection. Note that this call should -always- be proceeded by a ready call, and if the colection is ready and the saved flag is unset then the user should be prompted to save. Also note that this method creates yet another GShell to run buildcol.pl. */ 199 /** Used to set the current collection to the given collection. Note that this call should -always- be proceeded by a ready call, and if the colection is ready and the saved flag is unset then the user should be prompted to save. Also note that this method creates yet another GShell to run buildcol.pl. 200 * @param description a description of the collection as a String 201 * @param email the email address of the author/maintainer as a String 202 * @param name the short name of the collection, which will subsequently be used to refer to this particular collection, as a String 203 * @param title the longer title of the collection as a String 204 * @param base_collection_directory if the user has chosen to base their new collection on an existing one, this is the directory where this base collection can be found, as a File, otherwise its null 205 * @param metadata_sets if the user has decided to select several metadata sets with which to initially populate the GLI then this is an ArrayList of metadata set file names, otherwise its null 206 */ 198 207 public void createCollection(String description, String email, String name, String title, File base_collection_directory, ArrayList metadata_sets) { 208 boolean cancelled = false; 199 209 special_case = NO_SPECIAL_CASE; 200 210 try { 201 211 // Create a progress monitor. 202 212 ProgressMonitor progress = new ProgressMonitor(Gatherer.g_man, get("Creating_New"), "mkcol.pl", 0, 7); 203 213 // Create the new collection. 204 214 makeCollection(description, email, name, title); 205 215 progress.setProgress(1); 206 216 207 217 // ACTIVE_DIR/gimport/ 208 218 String a_dir = Utility.getCollectionDir(Gatherer.config.gsdl_path) + name + File.separator; 209 219 210 220 // Has to be done before creating greenstone directory metadata manager. 211 221 File gimport_dir_temp = new File(Utility.getImportDir(a_dir)+"temp.dat"); 212 222 File gimport_dir = gimport_dir_temp.getParentFile(); … … 216 226 } 217 227 218 228 // ACTIVE_DIR/gcache/ 219 229 File gcache_dir_temp = new File(Utility.getCacheDir(a_dir)+"temp.dat"); 220 230 File gcache_dir = gcache_dir_temp.getParentFile(); … … 224 234 } 225 235 226 236 // ACTIVE_DIR/log/ 227 237 File log_dir_temp = new File(Utility.getLogDir(a_dir)+"temp.dat"); 228 238 File log_dir = log_dir_temp.getParentFile(); … … 234 244 progress.setProgress(2); 235 245 236 246 // Now create the collection object around the directory. 237 247 collection = new Collection(new File(a_dir, name + ".col")); 238 248 collection.msm = new MetadataSetManager(); 239 249 msm = collection.msm; // Legacy 240 250 collection.msm.load(); 241 251 // Import default metadata sets if any. 242 252 for(int i = 0; metadata_sets != null && i < metadata_sets.size(); i++) { 243 253 MetadataSet metadata_set = (MetadataSet) metadata_sets.get(i); … … 247 257 // Before we create the CollectionDesignManager we have to check if we are basing it upon some other collection. 248 258 if(base_collection_directory != null) { 249 // If so our first step is to correctly generate an import profile for our collection from this base collection.259 Gatherer.println("Basing new collection on existing one: " + base_collection_directory); 250 260 // Try to import any existing metadata sets for this collection. Look in base_collection_directory/metadata and import any metadata sets found. 251 File base_metadata = new File(base_collection_directory, Utility.META DATA_DIR);261 File base_metadata = new File(base_collection_directory, Utility.META_DIR); 252 262 if(base_metadata.exists()) { 263 Gatherer.println("Found the metadata directory."); 253 264 File[] possible_metadata_sets = base_metadata.listFiles(); 254 265 for(int i = 0; possible_metadata_sets != null && i < possible_metadata_sets.length; i++) { 255 266 String filename = possible_metadata_sets[i].getName(); 256 267 if(filename.endsWith(".mds")) { 257 ///ystem.err.println("Found a metadata set. Importing: " + possible_metadata_sets[i].getAbsolutePath());268 Gatherer.println("+ Found a metadata set. Importing: " + possible_metadata_sets[i].getAbsolutePath()); 258 269 collection.msm.importMDS(possible_metadata_sets[i], false); 259 270 } 260 271 } 261 272 } 273 else { 274 Gatherer.println("This base collection has no metadata directory."); 275 } 262 276 // If no sets were imported, then create a new metadata with this new collections name. Note that if this is one of the 'big five' collections then I already know the importing mappings as well. 263 277 boolean skip_import_phase = false; 264 278 if(collection.msm.getSets().size() == 0) { 279 Gatherer.println("As there are no metadata sets loaded yet, we'll make special checks for the collections available on the GS2.39CD."); 265 280 CollectionConfiguration col_con = new CollectionConfiguration(new File(base_collection_directory, Utility.CONFIG_DIR)); 266 281 // If the source collection is one of the 'big five' then we know what the metadata set is. … … 268 283 // Demo collection - part of the DLS 269 284 if(collection_name.equals(Utility.COLLECTION_DEMO) || collection_name.equals(Utility.COLLECTION_DLS)) { 285 Gatherer.println("+ This is a DLS.mds collection."); 270 286 special_case = SPECIAL_DLS; 271 287 String demo_directory = (new File(base_collection_directory.getParentFile(), Utility.COLLECTION_DEMO_DIRECTORY)).getAbsolutePath(); 272 System.err.println("Demo directory = " + demo_directory);273 288 String dls_directory = (new File(base_collection_directory.getParentFile(), Utility.COLLECTION_DLS_DIRECTORY)).getAbsolutePath(); 274 System.err.println("DLS directory = " + dls_directory);275 289 // Add the dls.mds 276 290 collection.msm.importMDS(new File(Utility.METADATA_DIR + Utility.DLS_MDS), false); … … 294 308 // Prompt the user so that they can choose at least one initial metadata set. We're sneaky here and just create a ncm_prompt 295 309 else { 310 Gatherer.println("This collection has no metadata sets, nor is it one of our special collections, thus we cannot import any metadata sets automatically. Present the user with the metadata set selection prompt."); 296 311 NewCollectionMetadataPrompt ncm_prompt = new NewCollectionMetadataPrompt(); 297 312 // If cancelled then they really do mean to start a collection with no metadata sets. … … 310 325 } 311 326 // Do a dry metadata import run over the entire base collection, recording profile mappings. We do this by finding the archive files, and then iterating over them using the GreenstoneArchiveParser to retrieve metadata from them. We then process the importing of new metadata elements using the selectElement prompt used in a file action metadata import. However the big change is that we don't actually import any metadata, just create importing profiles. 312 File base_archives = new File(base_collection_directory, Utility.ARCHIVE_DIR); 313 if(!skip_import_phase && base_archives.exists()) { 314 ///ystem.err.println("Found archives directory."); 315 } 316 // Failing that we do a dummy run over the files in the collection. 317 else if(!skip_import_phase) { 318 ///ystem.err.println("No archives directory. Searching files for metadata.xml information."); 319 // Find the import directory 320 File base_import = new File(base_collection_directory, Utility.IMPORT_DIR); 321 if(!base_import.exists()) { 322 base_import = new File(base_collection_directory, Utility.OLD_IMPORT_DIR); 327 if(!skip_import_phase) { 328 File base_archive = new File(base_collection_directory, Utility.ARCHIVE_DIR); 329 if(base_archive.exists()) { 330 Gatherer.println("+ Archive directory found. Inspecting archives for metadata information."); 331 ArrayList metadata_elements = GreenstoneArchiveParser.extractMetadataElements(base_archive); 332 for(int i = 0; !cancelled && i < metadata_elements.size(); i++) { 333 String metadata_name = (String) metadata_elements.get(i); 334 ElementWrapper target = collection.msm.prompt.selectElement(metadata_name); 335 cancelled = Gatherer.c_man.getCollection().msm.prompt.wasDialogCancelled(); 336 if(!cancelled) { 337 if(target != null) { 338 collection.msm.profiler.addAction(base_collection_directory.getAbsolutePath(), metadata_name, target.getName()); 339 } 340 else { 341 collection.msm.profiler.addAction(base_collection_directory.getAbsolutePath(), metadata_name, null); 342 } 343 } 344 } 345 // Hopefully mappings should now be in place for metadata extracted from this collection. 323 346 } 324 if(base_import.exists()) { 325 searchForMetadata(base_import); 347 else { 348 Gatherer.println("+ Searching files for metadata.xml information."); 349 // Find the import directory 350 File base_import = new File(base_collection_directory, Utility.IMPORT_DIR); 351 if(!base_import.exists()) { 352 base_import = new File(base_collection_directory, Utility.OLD_IMPORT_DIR); 353 } 354 if(base_import.exists()) { 355 searchForMetadata(base_import); 356 } 326 357 } 327 // And if that fails then we must have been asked by Satan himself to build the very digital collections of hell, because they don't match any goodly greenstone collection I have ever seen, so you can't blame me if I can't import them. 328 } 358 } 359 // And if that fails then we must have been asked by Satan himself to build the very digital collections of hell, because they don't match any goodly greenstone collection I have ever seen, so you can't blame me if I can't import them. 360 361 329 362 // Now we update our collect.cfg 363 Gatherer.println("Copy and update collect.cfg from base collection."); 330 364 updateCollectionCFG(new File(base_collection_directory, Utility.CONFIG_DIR), new File(a_dir, Utility.CONFIG_DIR), description, email, title); 331 365 } … … 716 750 */ 717 751 public boolean loadCollection(String location) { 718 ///ystem.err.println("Load Collection '" + location + "'");752 Gatherer.println("Load Collection '" + location + "'"); 719 753 String[] args2 = new String[1]; 720 754 args2[0] = location; … … 1121 1155 String collection_path = (base_cfg.getParentFile().getParentFile()).getAbsolutePath(); 1122 1156 1123 System.err.println("Searching for " + collection_path);1124 1157 HashMap mappings = collection.msm.profiler.getActions(collection_path); 1125 1158 if(mappings == null) { 1126 System.err.println("How is this happening?");1159 Gatherer.println("Mappings is null, which is odd. Leaving all configuration commands which use metadata as they are."); 1127 1160 } 1128 1161 … … 1194 1227 text.append(token); 1195 1228 String temp_metadata = tokenizer.nextToken(); 1196 String replacement = (String) mappings.get(temp_metadata); 1229 String replacement = null; 1230 if(mappings != null) { 1231 replacement = (String) mappings.get(temp_metadata); 1232 } 1197 1233 if(replacement != null) { 1198 1234 token = replacement; … … 1212 1248 text.append(token); 1213 1249 String temp_metadata = tokenizer.nextToken(); 1214 String replacement = (String) mappings.get(temp_metadata); 1250 String replacement = null; 1251 if(mappings != null) { 1252 replacement = (String) mappings.get(temp_metadata); 1253 } 1215 1254 if(replacement != null) { 1216 1255 token = replacement;
Note:
See TracChangeset
for help on using the changeset viewer.