Ignore:
Timestamp:
2004-11-03T12:08:31+13:00 (20 years ago)
Author:
mdewsnip
Message:

Now escapes '(', ')', ',', '{', '}' in file paths when converting to regular expressions so files with these characters in the names can have metadata assigned and removed.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/metadata/MetadataXMLFile.java

    r8371 r8433  
    6868    }
    6969
    70     // Convert the file path into a regular expression that will match it
    71     String file_path_regexp = file_relative_path.replaceAll("\\.", "\\\\.");
    72     if (file_relative_path.equals("")) {
     70    // Form a regular expression that specifies the scope of the metadata
     71    String file_path_regexp = file_relative_path;
     72    if (file_path_regexp.equals("")) {
    7373        file_path_regexp = DIRECTORY_FILENAME;
     74    }
     75    else {
     76        // Convert the file path into a regular expression that will match it
     77        file_path_regexp = file_path_regexp.replaceAll("\\.", "\\\\.");
     78        file_path_regexp = file_path_regexp.replaceAll("\\(", "\\\\(");
     79        file_path_regexp = file_path_regexp.replaceAll("\\)", "\\\\)");
     80        file_path_regexp = file_path_regexp.replaceAll("\\[", "\\\\[");
     81        file_path_regexp = file_path_regexp.replaceAll("\\]", "\\\\]");
     82        file_path_regexp = file_path_regexp.replaceAll("\\{", "\\\\{");
     83        file_path_regexp = file_path_regexp.replaceAll("\\}", "\\\\}");
    7484    }
    7585
     
    273283    }
    274284
    275     // Convert the file path into a regular expression that will match it
    276     String file_path_regexp = file_relative_path.replaceAll("\\.", "\\\\.");
    277     if (file_relative_path.equals("")) {
     285    // Form a regular expression that specifies the scope of the metadata
     286    String file_path_regexp = file_relative_path;
     287    if (file_path_regexp.equals("")) {
    278288        file_path_regexp = DIRECTORY_FILENAME;
     289    }
     290    else {
     291        // Convert the file path into a regular expression that will match it
     292        file_path_regexp = file_path_regexp.replaceAll("\\.", "\\\\.");
     293        file_path_regexp = file_path_regexp.replaceAll("\\(", "\\\\(");
     294        file_path_regexp = file_path_regexp.replaceAll("\\)", "\\\\)");
     295        file_path_regexp = file_path_regexp.replaceAll("\\[", "\\\\[");
     296        file_path_regexp = file_path_regexp.replaceAll("\\]", "\\\\]");
     297        file_path_regexp = file_path_regexp.replaceAll("\\{", "\\\\{");
     298        file_path_regexp = file_path_regexp.replaceAll("\\}", "\\\\}");
    279299    }
    280300
Note: See TracChangeset for help on using the changeset viewer.