Moved Autoload to validator
This commit is contained in:
@@ -65,6 +65,7 @@ public class PDFValidator extends Validator {
|
|||||||
private String Signature;
|
private String Signature;
|
||||||
|
|
||||||
private String zfXML = null;
|
private String zfXML = null;
|
||||||
|
protected boolean autoload=true;
|
||||||
|
|
||||||
protected static boolean stringArrayContains(String[] arr, String targetValue) {
|
protected static boolean stringArrayContains(String[] arr, String targetValue) {
|
||||||
return Arrays.asList(arr).contains(targetValue);
|
return Arrays.asList(arr).contains(targetValue);
|
||||||
@@ -319,13 +320,13 @@ public class PDFValidator extends Validator {
|
|||||||
@Override
|
@Override
|
||||||
public void setFilename(String filename) throws IrrecoverableValidationError {
|
public void setFilename(String filename) throws IrrecoverableValidationError {
|
||||||
this.pdfFilename = filename;
|
this.pdfFilename = filename;
|
||||||
try {
|
if(autoload) {
|
||||||
fileContents=Files.readAllBytes(Paths.get(pdfFilename));
|
try {
|
||||||
} catch (IOException ex) {
|
fileContents=Files.readAllBytes(Paths.get(pdfFilename));
|
||||||
throw new IrrecoverableValidationError("Could not read file");
|
} catch (IOException ex) {
|
||||||
|
throw new IrrecoverableValidationError("Could not read file");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFileContents(byte[] fileContents) {
|
public void setFileContents(byte[] fileContents) {
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ public abstract class Validator {
|
|||||||
private static final Logger LOGGER = LoggerFactory.getLogger(Validator.class.getCanonicalName()); // log output
|
private static final Logger LOGGER = LoggerFactory.getLogger(Validator.class.getCanonicalName()); // log output
|
||||||
|
|
||||||
protected ValidationContext context;
|
protected ValidationContext context;
|
||||||
|
protected boolean autoload=true;
|
||||||
|
|
||||||
public Validator(ValidationContext ctx){
|
public Validator(ValidationContext ctx){
|
||||||
this.context=ctx;
|
this.context=ctx;
|
||||||
@@ -77,6 +78,10 @@ public abstract class Validator {
|
|||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setAutoload(boolean autoload) {
|
||||||
|
this.autoload = autoload;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ public class XMLValidator extends Validator {
|
|||||||
|
|
||||||
protected String zfXML = "";
|
protected String zfXML = "";
|
||||||
protected String filename = "";
|
protected String filename = "";
|
||||||
protected boolean autoload=true;
|
|
||||||
int firedRules = 0;
|
int firedRules = 0;
|
||||||
int failedRules = 0;
|
int failedRules = 0;
|
||||||
boolean disableNotices = false;
|
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
|
* manually set the xml content
|
||||||
* @param xml the xml to be checked
|
* @param xml the xml to be checked
|
||||||
|
|||||||
@@ -257,6 +257,7 @@ public class ZUGFeRDValidator {
|
|||||||
isPDF = ByteArraySearcher.contains(content, new byte[]{'%', 'P', 'D', 'F'});
|
isPDF = ByteArraySearcher.contains(content, new byte[]{'%', 'P', 'D', 'F'});
|
||||||
XMLValidator xv = new XMLValidator(context);
|
XMLValidator xv = new XMLValidator(context);
|
||||||
if (isPDF) {
|
if (isPDF) {
|
||||||
|
pdfv.setAutoload(false);
|
||||||
pdfv.setFilename(fileNameOfInputStream);
|
pdfv.setFilename(fileNameOfInputStream);
|
||||||
pdfv.setFileContents(content);
|
pdfv.setFileContents(content);
|
||||||
|
|
||||||
@@ -296,7 +297,7 @@ public class ZUGFeRDValidator {
|
|||||||
if (isXML) {
|
if (isXML) {
|
||||||
pdfValidity = true;
|
pdfValidity = true;
|
||||||
optionsRecognized = true;
|
optionsRecognized = true;
|
||||||
xv.disableAutoload();
|
xv.setAutoload(false);
|
||||||
xv.setFilename(fileNameOfInputStream);
|
xv.setFilename(fileNameOfInputStream);
|
||||||
sha1Checksum = calcSHA1(inputStream);
|
sha1Checksum = calcSHA1(inputStream);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user