- Timestamp:
- 2020-09-22T00:57:33+12:00 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/gli/src/org/greenstone/gatherer/metadata/FilenameEncoding.java
r33748 r34415 77 77 public static final Pattern HEX_PATTERN = Pattern.compile("(&#x[0-9a-zA-Z]{1,4}+;)"); 78 78 79 /** The hex entity version of the ampersand character.79 /** The hex version of the ampersand character: previously hex entity (&) now hex url encoded (%26). 80 80 * We use this in place of the ampersand character in filenames in metadata.xml files to 81 81 * preserve the reference to the literal ampersand in the real file name on the file system. 82 82 */ 83 public static final String HEX_ ENTITY_AMPERSAND= FilenameEncoding.hexEntityForChar("&"); //"&";83 public static final String HEX_AMPERSAND = "%26"; //= FilenameEncoding.hexEntityForChar("&"); //"&"; 84 84 85 85 … … 257 257 258 258 /** URL encoded version of the byte codes of the given file's name */ 259 public static String calcURLEncodedFilePath(File file) { 260 if(!MULTIPLE_FILENAME_ENCODINGS_SUPPORTED) { 261 return file.getAbsolutePath(); 262 } 263 else { 264 String filename = fileToURLEncoding(file); 265 return filename; 266 } 259 public static String calcURLEncodedFilePath(File file) { 260 return fileToURLEncoding(file); 267 261 } 268 262 … … 380 374 // just return input filename param, but with any & in the filename replaced with its hex entity 381 375 if(!MULTIPLE_FILENAME_ENCODINGS_SUPPORTED) { 382 // protect ampersands in filenames by converting it to its hex entity383 376 String filepath = file.getAbsolutePath(); 384 filepath = filepath.replace("&", HEX_ENTITY_AMPERSAND);385 377 return filepath; 386 378 } … … 430 422 431 423 // Before proceeding, protect & in the filename too. 432 // &'s ASCII code is 36 in decimal, and 26 in hex, so replace with & (HEX_ ENTITY_AMPERSAND)424 // &'s ASCII code is 36 in decimal, and 26 in hex, so replace with & (HEX_AMPERSAND) 433 425 // But dangerous to do simple replace if there are &#x...; entities in the filename already! 434 426 // That is, we'll want to protect & by replacing with &'s hex value, but we don't want to replace the & in "&#x....;" with the same! … … 445 437 //filename_url_encoded = filename_url_encoded.replace("%2B", "+"); // Don't do this, won't get regex escaped when converted back to a + by caller 446 438 filename_url_encoded = filename_url_encoded.replace("%2B", "+"); // + signs are special, as they will need to be escaped since the caller wants the filename representing a regex 447 filename_url_encoded = filename_url_encoded.replace("%26", HEX_ENTITY_AMPERSAND); // convert URL encoding for ampersand into hex entity for ampersand439 filename_url_encoded = filename_url_encoded.replace("%26", "&"); // now putting back ampersands too, instead of replacing with HEX_ENTITY_AMPERSAND (&) 448 440 } 449 441 catch (Exception e) { … … 544 536 // just return input filename param, but with any & in the filename replaced with its hex entity 545 537 if(!MULTIPLE_FILENAME_ENCODINGS_SUPPORTED) { 546 return filename .replace("&", HEX_ENTITY_AMPERSAND);538 return filename; //return filename.replace("&", HEX_AMPERSAND); 547 539 } 548 540 … … 567 559 public static String relativeFilenameToURLEncoding(String filename) { 568 560 if(!MULTIPLE_FILENAME_ENCODINGS_SUPPORTED) { // on a UTF-8 file system, DO NOT do the stuff below, just return input param 569 return filename .replace("&", HEX_ENTITY_AMPERSAND);561 return filename; // return filename.replace("&", HEX_AMPERSAND); 570 562 } 571 563 … … 580 572 public static String filenameToURLEncodingWithPrefixRemoved(String filename, String removeFilePathPrefix) { 581 573 if(!MULTIPLE_FILENAME_ENCODINGS_SUPPORTED) { // on a UTF-8 file system, DO NOT do the stuff below, just return input param 582 return filename .replace("&", HEX_ENTITY_AMPERSAND);574 return filename; //return filename.replace("&", HEX_AMPERSAND); 583 575 } 584 576
Note:
See TracChangeset
for help on using the changeset viewer.