forked from j62/ctbrec
1
0
Fork 0

Add placeholder for recording notes

This commit is contained in:
0xb00bface 2020-09-26 20:18:17 +02:00
parent 5fa72eaaa0
commit 43cf0a0bc1
3 changed files with 19 additions and 3 deletions

View File

@ -60,4 +60,14 @@ public class StringUtil {
} }
return hex; return hex;
} }
// @formatter:off
public static String sanitize(String input) {
return input
.replace(' ', '_')
.replace('\\', '_')
.replace('/', '_')
.replace('\'', '_')
.replace('"', '_');
} // @formatter:on
} }

View File

@ -1,5 +1,6 @@
package ctbrec.recorder.postprocessing; package ctbrec.recorder.postprocessing;
import static ctbrec.StringUtil.*;
import static java.util.Optional.*; import static java.util.Optional.*;
import java.time.ZoneId; import java.time.ZoneId;
@ -26,6 +27,7 @@ public abstract class AbstractPlaceholderAwarePostProcessor extends AbstractPost
"${epochSecond}", "${epochSecond}",
"${fileSuffix}", "${fileSuffix}",
"${modelNotes}", "${modelNotes}",
"${recordingNotes}",
"${recordingsDir}", "${recordingsDir}",
"${absolutePath}", "${absolutePath}",
"${absoluteParentPath}" "${absoluteParentPath}"
@ -41,7 +43,8 @@ public abstract class AbstractPlaceholderAwarePostProcessor extends AbstractPost
.replace("${siteSanitizedName}", getSanitizedSiteName(rec)) .replace("${siteSanitizedName}", getSanitizedSiteName(rec))
.replace("${fileSuffix}", getFileSuffix(rec)) .replace("${fileSuffix}", getFileSuffix(rec))
.replace("${epochSecond}", Long.toString(rec.getStartDate().getEpochSecond())) .replace("${epochSecond}", Long.toString(rec.getStartDate().getEpochSecond()))
.replace("${modelNotes}", config.getModelNotes(rec.getModel())) .replace("${modelNotes}", sanitize(config.getModelNotes(rec.getModel())))
.replace("${recordingNotes}", getSanitizedRecordingNotes(rec))
.replace("${recordingsDir}", config.getSettings().recordingsDir) .replace("${recordingsDir}", config.getSettings().recordingsDir)
.replace("${absolutePath}", rec.getPostProcessedFile().getAbsolutePath()) .replace("${absolutePath}", rec.getPostProcessedFile().getAbsolutePath())
.replace("${absoluteParentPath}", rec.getPostProcessedFile().getParentFile().getAbsolutePath()) .replace("${absoluteParentPath}", rec.getPostProcessedFile().getParentFile().getAbsolutePath())
@ -92,7 +95,10 @@ public abstract class AbstractPlaceholderAwarePostProcessor extends AbstractPost
} }
private CharSequence getSanitizedSiteName(Recording rec) { private CharSequence getSanitizedSiteName(Recording rec) {
return ofNullable(rec.getModel().getSite()).map(Site::getName).orElse("").replace(' ', '_').replace('\\', '_').replace('/', '_'); return sanitize(ofNullable(rec.getModel().getSite()).map(Site::getName).orElse(""));
} }
private CharSequence getSanitizedRecordingNotes(Recording rec) {
return sanitize(ofNullable(rec.getNote()).orElse(""));
}
} }

View File

@ -120,6 +120,6 @@ public class AbstractPlaceholderAwarePostProcessorTest extends AbstractPpTest {
@Test @Test
public void testModelNotesReplacement() { public void testModelNotesReplacement() {
String input = "asdf_${modelNotes}_asdf"; String input = "asdf_${modelNotes}_asdf";
assertEquals("asdf_tag, foo, bar_asdf", placeHolderAwarePp.fillInPlaceHolders(input, rec, config)); assertEquals("asdf_tag,_foo,_bar_asdf", placeHolderAwarePp.fillInPlaceHolders(input, rec, config));
} }
} }