Create a new PatternFilter instance suitable for processing output to files produced using the supplied template. @param templateFileName The file name of the output template file. @throws IOException If the pattern filter cannot be read.
(String templateFileName)
| 51 | * @throws IOException If the pattern filter cannot be read. |
| 52 | */ |
| 53 | public PatternFilter(String templateFileName) throws IOException |
| 54 | { |
| 55 | |
| 56 | int idx = templateFileName.lastIndexOf('.'); |
| 57 | if (idx < 0) |
| 58 | { |
| 59 | idx = templateFileName.lastIndexOf('-'); |
| 60 | } |
| 61 | |
| 62 | String filterName = templateFileName; |
| 63 | if (idx >= 0) |
| 64 | { |
| 65 | filterName = filterName.substring(idx + 1); |
| 66 | } |
| 67 | |
| 68 | filterName = filterName.toLowerCase(); |
| 69 | |
| 70 | if (filterName.equals(outputFilterName)) |
| 71 | { |
| 72 | return; |
| 73 | } |
| 74 | |
| 75 | filterName = new File(ConfigurationSettings.getSystemsDir()) + File.separator + "outputFilters" + File.separator |
| 76 | + "re" + filterName + Constants.EXTENSION_LIST_FILE; |
| 77 | // Logging.debugPrint("Creating filter from " + filterName); |
| 78 | |
| 79 | final File filterFile = new File(filterName); |
| 80 | |
| 81 | if (filterFile.canRead() && filterFile.isFile()) |
| 82 | { |
| 83 | |
| 84 | try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(filterFile), StandardCharsets.UTF_8))) |
| 85 | { |
| 86 | |
| 87 | outputFilterName = filterName; |
| 88 | match = new ArrayList<>(); |
| 89 | replace = new ArrayList<>(); |
| 90 | |
| 91 | while (true) |
| 92 | { |
| 93 | final String aLine = br.readLine(); |
| 94 | // Logging.debugPrint("Line read:" + aLine); |
| 95 | |
| 96 | if (aLine == null) |
| 97 | { |
| 98 | break; |
| 99 | } |
| 100 | |
| 101 | String aLineWOComment; |
| 102 | if (aLine.isEmpty() || aLine.charAt(0) == '#') |
| 103 | { |
| 104 | continue; |
| 105 | } else if (aLine.indexOf("\t#") > 0) |
| 106 | { |
| 107 | aLineWOComment = aLine.substring(0, aLine.indexOf("\t#")); |
| 108 | } else |
| 109 | { |
| 110 | aLineWOComment = aLine; |
nothing calls this directly
no test coverage detected