make it possible to disable loading from specified filename if a stream is validated
This commit is contained in:
@@ -36,6 +36,7 @@ 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;
|
||||||
@@ -55,19 +56,27 @@ public class XMLValidator extends Validator {
|
|||||||
public void setFilename(String name) throws IrrecoverableValidationError { // from XML Filename
|
public void setFilename(String name) throws IrrecoverableValidationError { // from XML Filename
|
||||||
filename = name;
|
filename = name;
|
||||||
// file existence must have been checked before
|
// file existence must have been checked before
|
||||||
|
if (autoload) {
|
||||||
|
try {
|
||||||
|
zfXML = new String(XMLTools.removeBOM(Files.readAllBytes(Paths.get(filename))), StandardCharsets.UTF_8);
|
||||||
|
} catch (final IOException e) {
|
||||||
|
|
||||||
try {
|
final ValidationResultItem vri = new ValidationResultItem(ESeverity.exception, e.getMessage()).setSection(9)
|
||||||
zfXML = new String(XMLTools.removeBOM(Files.readAllBytes(Paths.get(name))), StandardCharsets.UTF_8);
|
|
||||||
} catch (final IOException e) {
|
|
||||||
|
|
||||||
final ValidationResultItem vri = new ValidationResultItem(ESeverity.exception, e.getMessage()).setSection(9)
|
|
||||||
.setPart(EPart.fx);
|
.setPart(EPart.fx);
|
||||||
final StringWriter sw = new StringWriter();
|
final StringWriter sw = new StringWriter();
|
||||||
final PrintWriter pw = new PrintWriter(sw);
|
final PrintWriter pw = new PrintWriter(sw);
|
||||||
e.printStackTrace(pw);
|
e.printStackTrace(pw);
|
||||||
vri.setStacktrace(sw.toString());
|
vri.setStacktrace(sw.toString());
|
||||||
context.addResultItem(vri);
|
context.addResultItem(vri);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void disableAutoload() {
|
||||||
|
// for streaming, which sets a fake filename
|
||||||
|
autoload=false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/***
|
/***
|
||||||
|
|||||||
@@ -296,6 +296,7 @@ public class ZUGFeRDValidator {
|
|||||||
if (isXML) {
|
if (isXML) {
|
||||||
pdfValidity = true;
|
pdfValidity = true;
|
||||||
optionsRecognized = true;
|
optionsRecognized = true;
|
||||||
|
xv.disableAutoload();
|
||||||
xv.setFilename(fileNameOfInputStream);
|
xv.setFilename(fileNameOfInputStream);
|
||||||
sha1Checksum = calcSHA1(inputStream);
|
sha1Checksum = calcSHA1(inputStream);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user