- Timestamp:
- 2003-06-03T12:17:47+12:00 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/msm/parsers/GreenstoneMetadataParser.java
r4365 r4449 137 137 // Continue only if we are sure this is a greenstone collection 138 138 if(collection_dir != null && collect_cfg != null) { 139 140 139 // 2. Attempt to merge in any mdses and make note of those that are successfully imported (by removing reference from collect.cfg). 140 ///ystem.err.print("2 "); 141 141 ArrayList mdses = collect_cfg.getMetadataSets(); 142 142 for(int i = 0; i < mdses.size(); i++) { … … 147 147 mdses = null; 148 148 149 150 149 // 3. Locate all of the metadata.xml files that may have an affect on the origin file. Make sure the metadata.xml closest to the origin files directory is last (to ensure property inheritance regarding accumulate/overwrite). 150 ///ystem.err.print("3 "); 151 151 ArrayList search_files = new ArrayList(); 152 152 File file = origin.getFile(); 153 153 String filename = null; 154 boolean file_level; 154 155 if(file.isFile()) { 156 file_level = false; 155 157 filename = file.getName(); 156 158 file = file.getParentFile(); 159 } 160 else { 161 file_level = true; 157 162 } 158 163 while(!file.equals(collection_dir)) { … … 171 176 filename = null; 172 177 file = null; 173 178 // Start with an initially empty ArrayList of metadata 174 179 ArrayList metadatum = new ArrayList(); 175 180 // Now search each of these metadata xml for metadata, remembering to accumulate or overwrite as we go along. 176 181 for(int i = 0; i < search_files.size(); i++) { 177 182 MetadataXMLFileSearch a_search = (MetadataXMLFileSearch) search_files.get(i); … … 185 190 } 186 191 else { 187 metadatum = document.getMetadata(a_search.filename, metadatum, true);192 metadatum = document.getMetadata(a_search.filename, metadatum, folder_level); 188 193 } 189 194 document = null; … … 192 197 } 193 198 search_files = null; 194 195 199 // Finally assign the metadata 200 ///ystem.err.println("Found " + metadatum.size() + " pieces of metadata for " + destination); 196 201 if(metadatum.size() > 0) { 197 202 addMetadata(destination, metadatum, collection_dir, collect_cfg, dummy_run); … … 372 377 /** This constructor takes the original document and parsed out and stores metadata with its association to filenames. */ 373 378 public BasicGDMDocument(File file) { 374 379 ///ystem.err.println("New BasicGDMDocument: " + file.getAbsolutePath()); 375 380 base_document = Utility.parse(file.getAbsolutePath(), false); 376 381 } … … 378 383 public ArrayList getAllMetadata() { 379 384 ArrayList metadatum = new ArrayList(); 380 385 // Don't search the cache as this would never have been added. 381 386 try { 382 387 // Retrieve the document element. … … 432 437 /** Retrieve any metadata associated with a certain file. If filename is null we are attempting to find directory level metadata. */ 433 438 public ArrayList getMetadata(String filename, ArrayList metadatum_so_far, boolean folder_level) { 434 ///ystem.err.println("Retrieving metadata for: " + filename);439 ///ystem.err.println("Retrieving metadata for: " + filename + " [" + folder_level + "]"); 435 440 ArrayList metadatum = null; 436 441 // We start by attempting to retrieve this metadata from the cache. 437 442 if(filename != null) { 438 443 metadatum = (ArrayList) get(filename); … … 441 446 metadatum = (ArrayList) get(DIRECTORY_FILENAME); 442 447 } 443 448 // If that failed we consult the document for metadata. 444 449 if(metadatum == null) { 445 450 metadatum = new ArrayList(); … … 461 466 Element filename_element = (Element) filename_elements.item(j); 462 467 String filename_text = MSMUtils.getValue(filename_element); 463 // Crappy. There are apparently two ways of assigning, say, directory level metadata to anything in the ac01ne directory from a parent directories metadata.xml. 464 // The developers guide way: ac01ne/.* 465 // The dls way: ac01ne 466 // So the three tests are 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))) 473 || (filename == null && filename_text.equals(DIRECTORY_FILENAME))) { 468 if(isMatchingFileSet(filename, filename_text, folder_level)) { 474 469 ///ystem.err.println("Match: " + (filename != null ? filename : ".*") + " => " + filename_text); 475 470 // If they match add all of the metadata found in the Description child element, remembering to abide by desired mode (accumulate vs. overwrite). … … 537 532 return metadatum; 538 533 } 534 535 private boolean isMatchingFileSet(String filename, String filename_text, boolean folder_level) { 536 // Crappy. There are apparently two ways of assigning, say, directory level metadata to anything in the ac01ne directory from a parent directories metadata.xml. 537 // The developers guide way: ac01ne/.* 538 // The dls way: ac01ne 539 // So the three tests are: 540 // 1. Check for an exact match i.e "ac01ne/ac01ne.htm" matches "ac01ne/".* 541 // 2. Check for a parent folder match, in the absence of further pattern i.e "ac01ne/ac01ne.htm" matches "ac01ne" 542 // 3. Check for a folder level match if thats what we are looking for i.e "null" matches ".*" 543 544 ///ystem.err.println("Check for: " + (filename != null ? filename : ".*")); 545 ///ystem.err.println("Folder level = " + folder_level); 546 ///ystem.err.println("filename != null && '" + filename + "'.matches('" + filename_text + "') = " + (filename != null ? filename.matches(filename_text) : false)); 547 ///ystem.err.println("filename != null && '" + filename + "'.matches('" + filename_text + DIRECTORY_FILENAME_SUFFIX + "') [folder level = " + folder_level + "] = " + (filename != null ? filename.matches(filename_text + DIRECTORY_FILENAME_SUFFIX) && folder_level: false)); 548 ///ystem.err.println("filename == null && '" + filename_text + "'.equals('.*') = " + (filename == null ? filename_text.equals(DIRECTORY_FILENAME) : false)); 549 if (filename != null) { 550 if(folder_level) { 551 return filename.matches(filename_text) || filename.matches(filename_text + DIRECTORY_FILENAME_SUFFIX); 552 } 553 else { 554 return filename.matches(filename_text); 555 } 556 } 557 else { 558 return filename_text.equals(DIRECTORY_FILENAME); 559 } 560 } 539 561 540 562 /** Determine is this is a valid Greenstone Directory Metadata file. It may of course just be some xml file with the name metadata.xml. */
Note:
See TracChangeset
for help on using the changeset viewer.