Allow for better contextual file reference handling

This commit is contained in:
crschnick 2024-01-09 01:33:38 +00:00
parent 277f7f8c04
commit f454e6d905

View file

@ -9,6 +9,7 @@ import lombok.NonNull;
import java.nio.file.InvalidPathException;
import java.nio.file.Path;
import java.util.Optional;
import java.util.regex.Matcher;
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@ -36,6 +37,24 @@ public class ContextualFileReference {
}
}
public static Optional<ContextualFileReference> parseIfInDataDirectory(String s) {
var cf = of(s);
if (cf.serialize().contains("<DATA>")) {
return Optional.of(cf);
} else {
return Optional.empty();
}
}
public static Optional<String> resolveIfInDataDirectory(ShellControl shellControl, String s) {
if (s.contains("<DATA>")) {
var cf = of(s);
return Optional.of(cf.toFilePath(shellControl));
} else {
return Optional.empty();
}
}
public static ContextualFileReference of(String s) {
if (s == null) {
return null;