Moved Autoload to validator

This commit is contained in:
Dominik Röschke
2024-07-09 07:12:13 +02:00
parent fb7fe28eca
commit 94b7b75de7
4 changed files with 14 additions and 13 deletions

View File

@@ -65,6 +65,7 @@ public class PDFValidator extends Validator {
private String Signature;
private String zfXML = null;
protected boolean autoload=true;
protected static boolean stringArrayContains(String[] arr, String targetValue) {
return Arrays.asList(arr).contains(targetValue);
@@ -319,13 +320,13 @@ public class PDFValidator extends Validator {
@Override
public void setFilename(String filename) throws IrrecoverableValidationError {
this.pdfFilename = filename;
try {
fileContents=Files.readAllBytes(Paths.get(pdfFilename));
} catch (IOException ex) {
throw new IrrecoverableValidationError("Could not read file");
if(autoload) {
try {
fileContents=Files.readAllBytes(Paths.get(pdfFilename));
} catch (IOException ex) {
throw new IrrecoverableValidationError("Could not read file");
}
}
}
public void setFileContents(byte[] fileContents) {

View File

@@ -19,6 +19,7 @@ public abstract class Validator {
private static final Logger LOGGER = LoggerFactory.getLogger(Validator.class.getCanonicalName()); // log output
protected ValidationContext context;
protected boolean autoload=true;
public Validator(ValidationContext ctx){
this.context=ctx;
@@ -77,6 +78,10 @@ public abstract class Validator {
return context;
}
public void setAutoload(boolean autoload) {
this.autoload = autoload;
}
}

View File

@@ -36,7 +36,6 @@ public class XMLValidator extends Validator {
protected String zfXML = "";
protected String filename = "";
protected boolean autoload=true;
int firedRules = 0;
int failedRules = 0;
boolean disableNotices = false;
@@ -74,11 +73,6 @@ public class XMLValidator extends Validator {
}
public void disableAutoload() {
// for streaming, which sets a fake filename
autoload=false;
}
/***
* manually set the xml content
* @param xml the xml to be checked

View File

@@ -257,6 +257,7 @@ public class ZUGFeRDValidator {
isPDF = ByteArraySearcher.contains(content, new byte[]{'%', 'P', 'D', 'F'});
XMLValidator xv = new XMLValidator(context);
if (isPDF) {
pdfv.setAutoload(false);
pdfv.setFilename(fileNameOfInputStream);
pdfv.setFileContents(content);
@@ -296,7 +297,7 @@ public class ZUGFeRDValidator {
if (isXML) {
pdfValidity = true;
optionsRecognized = true;
xv.disableAutoload();
xv.setAutoload(false);
xv.setFilename(fileNameOfInputStream);
sha1Checksum = calcSHA1(inputStream);