Skip to content

Commit

Permalink
Merge pull request #405 from Sarenor/autoload-in-validator
Browse files Browse the repository at this point in the history
Moved Autoload to validator
  • Loading branch information
jstaerk authored Jul 10, 2024
2 parents fb7fe28 + 94b7b75 commit 56b0749
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public PDFValidator(ValidationContext ctx) {
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);
Expand Down Expand Up @@ -319,13 +320,13 @@ public void validate() throws IrrecoverableValidationError {
@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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -77,6 +78,10 @@ public ValidationContext getValidationContext() {
return context;
}

public void setAutoload(boolean autoload) {
this.autoload = autoload;
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -74,11 +73,6 @@ public void setFilename(String name) throws IrrecoverableValidationError { // fr

}

public void disableAutoload() {
// for streaming, which sets a fake filename
autoload=false;
}

/***
* manually set the xml content
* @param xml the xml to be checked
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ public String validate(InputStream inputStream, String fileNameOfInputStream) {
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);

Expand Down Expand Up @@ -296,7 +297,7 @@ public String validate(InputStream inputStream, String fileNameOfInputStream) {
if (isXML) {
pdfValidity = true;
optionsRecognized = true;
xv.disableAutoload();
xv.setAutoload(false);
xv.setFilename(fileNameOfInputStream);
sha1Checksum = calcSHA1(inputStream);

Expand Down

0 comments on commit 56b0749

Please sign in to comment.