Skip to content

Commit

Permalink
make it possible to disable loading from specified filename if a stre…
Browse files Browse the repository at this point in the history
…am is validated
  • Loading branch information
jstaerk committed Jul 8, 2024
1 parent 3904caf commit fb7fe28
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ 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 All @@ -55,19 +56,27 @@ public XMLValidator(ValidationContext ctx) {
public void setFilename(String name) throws IrrecoverableValidationError { // from XML Filename
filename = name;
// 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 {
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)
final ValidationResultItem vri = new ValidationResultItem(ESeverity.exception, e.getMessage()).setSection(9)
.setPart(EPart.fx);
final StringWriter sw = new StringWriter();
final PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
vri.setStacktrace(sw.toString());
context.addResultItem(vri);
final StringWriter sw = new StringWriter();
final PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
vri.setStacktrace(sw.toString());
context.addResultItem(vri);
}

}

}

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

/***
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ public String validate(InputStream inputStream, String fileNameOfInputStream) {
if (isXML) {
pdfValidity = true;
optionsRecognized = true;
xv.disableAutoload();
xv.setFilename(fileNameOfInputStream);
sha1Checksum = calcSHA1(inputStream);

Expand Down

0 comments on commit fb7fe28

Please sign in to comment.