Skip to content

Commit 32d5dfd

Browse files
authored
Remove slashes from filenames (#1057)
Co-authored-by: KochTobi <[email protected]>
1 parent 48f0c76 commit 32d5dfd

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

user-interface/src/main/java/life/qbic/datamanager/files/export/FileNameFormatter.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public class FileNameFormatter {
99
private static final String PART_JOINER = "_";
1010

1111
private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd");
12+
private static final String SLASH_REPLACEMENT = "_";
1213

1314
private FileNameFormatter() {
1415

@@ -19,18 +20,26 @@ public static String formatWithTimestampedContext(LocalDate timestamp, String pr
1920
String experimentPart, String type, String extension) {
2021
return DATE_FORMATTER.format(timestamp)
2122
+ PART_JOINER
22-
+ replaceSpaces(projectPart)
23+
+ replaceForbiddenCharacters(projectPart)
2324
+ PART_JOINER
24-
+ replaceSpaces(experimentPart)
25+
+ replaceForbiddenCharacters(experimentPart)
2526
+ PART_JOINER
26-
+ replaceSpaces(type)
27-
+ "." + replaceSpaces(extension);
27+
+ replaceForbiddenCharacters(type)
28+
+ "." + replaceForbiddenCharacters(extension);
29+
}
30+
31+
private static String replaceForbiddenCharacters(String input) {
32+
return replaceSlashes(replaceSpaces(input));
2833
}
2934

3035
private static String replaceSpaces(String projectPart) {
3136
return projectPart.replaceAll("\\s", SPACE_REPLACEMENT);
3237
}
3338

39+
private static String replaceSlashes(String input) {
40+
return input.replace("/", SLASH_REPLACEMENT);
41+
}
42+
3443
public static String formatWithVersion(String filename, int version,
3544
String extension) {
3645
return replaceSpaces(filename) + "_" + "v" + version + "." + replaceSpaces(extension);

0 commit comments

Comments
 (0)