- Timestamp:
- 2019-11-29T23:40:14+13:00 (4 years ago)
- Location:
- main/trunk/gli/src/org/greenstone/gatherer/metadata
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/gli/src/org/greenstone/gatherer/metadata/FilenameEncoding.java
r33728 r33730 311 311 public static String decodeStringContainingHexEntities(String str) { 312 312 String result = ""; 313 boolean done = false;314 313 Pattern hexPattern = Pattern.compile("(&#x[0-9a-zA-Z]{1,4}+;)"); 315 314 Matcher matcher = hexPattern.matcher(str); … … 345 344 } 346 345 347 if(endMatchIndex != -1) { 346 if(endMatchIndex != -1) { // attach any suffix once we finished processing all the hex codes 348 347 result += str.substring(endMatchIndex); 349 348 //System.err.println("suffix: " + str.substring(endMatchIndex)); 350 349 } 350 else { // there were no hex codes to decode, return string as is 351 result = str; 352 } 351 353 352 354 return result; … … 355 357 /** Attempting to produce the equivalent method fileToURLEncoding() above, but taking a String as input parameter */ 356 358 public static String fileNameToHex(String filename) { 357 /*String filename_url_encoded = ""; 358 try { 359 URI filename_uri = new URI(filename); 360 String filename_ascii = filename_uri.toASCIIString(); 361 String filename_raw_bytes = URLDecoder.decode(filename_ascii,"ISO-8859-1"); 362 filename_url_encoded = iso_8859_1_filename_to_url_encoded(filename_raw_bytes); 363 return filename_url_encoded; 364 } catch (Exception e) { 365 e.printStackTrace(); 366 // Give up trying to convert 367 filename_url_encoded = filename; 368 } 369 return filename_url_encoded; 370 */ 371 359 372 360 String hexFilename = ""; 373 361 for(int i = 0; i < filename.length(); i++) { -
main/trunk/gli/src/org/greenstone/gatherer/metadata/MetadataXMLFile.java
r33727 r33730 35 35 import org.w3c.dom.*; 36 36 37 import org.greenstone.gatherer.util.Utility; 37 38 38 39 /** This class represents one metadata.xml file */ … … 262 263 String current_filename_element_value = XMLTools.getElementTextValue(current_filename_element); 263 264 264 String regexed_file_relative_path = MetadataTools.getRegularExpressionThatMatchesFilePath(file_relative_path); 265 //System.err.println("Looking in meta.xml for regexed version of filename: " + regexed_file_relative_path); 265 //System.err.println("\n Original TAIL filename was: " + Utility.debugUnicodeString(file.getName())); 266 String hexdecoded_regexed_file_relative_path = FilenameEncoding.decodeStringContainingHexEntities(file_relative_path); 267 //System.err.println("Looking in meta.xml for hexdecoded_regexed_file_RELATIVE_path: " + hexdecoded_regexed_file_relative_path 268 //+ " - debug version: " + Utility.debugUnicodeString(hexdecoded_regexed_file_relative_path)); 266 269 267 270 // Does this fileset specify metadata for one file only? … … 272 275 } 273 276 274 String current_filename_element_value_hex = FilenameEncoding.fileNameToHex(current_filename_element_value); 277 String hexdecoded_current_filename_element_value = FilenameEncoding.decodeStringContainingHexEntities(current_filename_element_value); 278 //System.err.println(" Checking to see if it matches " + hexdecoded_current_filename_element_value + " - debug: " + Utility.debugUnicodeString(hexdecoded_current_filename_element_value)); 279 //System.err.println(" Checking to see if it matches " + current_filename_element_value + " - debug: " + Utility.debugUnicodeString(current_filename_element_value)); 275 280 276 281 // This fileset specifies metadata for the file 277 // MetadataXMLFile.addMetadata(CollectionTreeNode, ArrayList) stored filename in uppercase hex, so need to compare with the same 278 if (file_relative_path.matches(current_filename_element_value_hex)) { //if (file_relative_path.matches(current_filename_element_value)) { 279 //System.err.println("Found a match in meta.xml for file name: " + regexed_file_relative_path); 282 // MetadataXMLFile.addMetadata(CollectionTreeNode, ArrayList) stored filename in uppercase hex 283 // so need to make sure everything hex has been decoded (no more hex) to compare apples with apples 284 if (hexdecoded_regexed_file_relative_path.matches(hexdecoded_current_filename_element_value)) { //if (file_relative_path.matches(current_filename_element_value)) { 285 //System.err.println(" @@@ Found a match in meta.xml for hexdecoded_regexed_file_relative_path: " + hexdecoded_regexed_file_relative_path); 280 286 current_fileset_matches = true; 281 287 if (!file_relative_path.equals("") && current_filename_element_value.equals(DIRECTORY_FILENAME)) { … … 283 289 } 284 290 break; 285 } 291 } //else { 292 //System.err.println( hexdecoded_regexed_file_relative_path + " does not match " + hexdecoded_current_filename_element_value); 293 //System.err.println( Utility.debugUnicodeString(hexdecoded_regexed_file_relative_path) + " does not match " + Utility.debugUnicodeString(hexdecoded_current_filename_element_value)); 294 //} 286 295 287 296 // This fileset specifies metadata for the folder the file is in 288 if ( regexed_file_relative_path.startsWith(current_filename_element_value + FilenameEncoding.URL_FILE_SEPARATOR)) {297 if (hexdecoded_regexed_file_relative_path.startsWith(hexdecoded_current_filename_element_value + FilenameEncoding.URL_FILE_SEPARATOR)) { 289 298 current_fileset_matches = true; 290 299 folder_metadata_inherited_from = new File(metadata_xml_file_directory, current_filename_element_value); … … 616 625 // If we have a file loaded into memory and it has been modified, save it now 617 626 if (loaded_file != null && loaded_file_changed == true) { 627 //System.err.println("START saveLoadedFile(), loaded_file_document:\n" + XMLTools.elementToString(loaded_file_document.getDocumentElement(), true)); 628 618 629 XMLTools.writeXMLFile(loaded_file, loaded_file_document, nonEscapingElements); 619 630 631 Document doc = XMLTools.parseXMLFile(loaded_file); 632 //System.err.println("AT END saveLoadedFile(), PARSED loaded_file contains:\n" + XMLTools.elementToString(doc.getDocumentElement(), true)); 620 633 621 634 loaded_file_changed = false;
Note:
See TracChangeset
for help on using the changeset viewer.