support multiple possible interactive filename extensions

This commit is contained in:
Jochen Stärk
2020-07-26 12:07:30 +02:00
parent 67bddba154
commit 2778af34fd
2 changed files with 20 additions and 14 deletions

View File

@@ -10,6 +10,8 @@
- be able to disable "source pdf set to timeout" - be able to disable "source pdf set to timeout"
- automated tests zuv/verapdf validate created library test files - automated tests zuv/verapdf validate created library test files
- unify loggers - unify loggers
- xmp errors may not show correctly in log
- switch for no log and no notices
- merge readmes and history.md s - merge readmes and history.md s
done done
- remove jaxb - remove jaxb

View File

@@ -168,7 +168,7 @@ public class Main {
* *
* @param prompt the text the user is asked * @param prompt the text the user is asked
* @param defaultFilename a default Filename * @param defaultFilename a default Filename
* @param expectedExtension will warn if filename does not match expected file extension * @param expectedExtension will warn if filename does not match expected file extension, "or" possible with e.g. pdf|xml
* @param ensureFileExists will warn if file does NOT exist (for input files) * @param ensureFileExists will warn if file does NOT exist (for input files)
* @param ensureFileNotExists will warn if file DOES exist (for output files) * @param ensureFileNotExists will warn if file DOES exist (for output files)
* @return String * @return String
@@ -194,8 +194,23 @@ public class Main {
selectedName = defaultFilename; selectedName = defaultFilename;
} }
boolean hasCorrectExtension=false;
String[] expectedExtensions=expectedExtension.split("\\|");
for (String currentExtension: expectedExtensions) {
if (selectedName.toLowerCase().endsWith(expectedExtension.toLowerCase())) {
hasCorrectExtension=true;
}
}
// error cases // error cases
if (!selectedName.toLowerCase().endsWith(expectedExtension.toLowerCase())) { if (ensureFileExists) {
if (fileExists(selectedName)) {
fileExistenceOK = true;
} else {
System.out.println("File does not exist, try again or CTRL+C to cancel");
// discard the input, a scanner.reset is not sufficient
fileExistenceOK = false;
}
} else if (!hasCorrectExtension) {
System.err.println("Expected " + expectedExtension System.err.println("Expected " + expectedExtension
+ " extension, this may corrupt your file. Do you still want to continue?(Y|N)"); + " extension, this may corrupt your file. Do you still want to continue?(Y|N)");
String selectedAnswer = ""; String selectedAnswer = "";
@@ -209,14 +224,6 @@ public class Main {
System.exit(-1); System.exit(-1);
} }
} else if (ensureFileExists) {
if (fileExists(selectedName)) {
fileExistenceOK = true;
} else {
System.out.println("File does not exist, try again or CTRL+C to cancel");
// discard the input, a scanner.reset is not sufficient
fileExistenceOK = false;
}
} else { } else {
fileExistenceOK = true; fileExistenceOK = true;
@@ -341,11 +348,8 @@ public class Main {
private static boolean performValidate(String sourceName) { private static boolean performValidate(String sourceName) {
boolean optionsRecognized; boolean optionsRecognized;
if (sourceName == null) { if (sourceName == null) {
sourceName = getFilenameFromUser("Source PDF", "invoice.pdf", "pdf", true, false); sourceName = getFilenameFromUser("Source PDF or XML", "invoice.pdf", "pdf|xml", true, false);
} else {
System.out.println("Source PDF set to " + sourceName);
} }
ZUGFeRDValidator zfv=new ZUGFeRDValidator(); ZUGFeRDValidator zfv=new ZUGFeRDValidator();
System.out.println(zfv.validate(sourceName)); System.out.println(zfv.validate(sourceName));
optionsRecognized = !zfv.hasOptionsError(); optionsRecognized = !zfv.hasOptionsError();