Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Policy crash when document unparsable #203

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import org.openpreservation.messages.Message.Severity;
import org.openpreservation.messages.MessageLog;
import org.openpreservation.messages.Messages;
import org.openpreservation.odf.pkg.PackageParser.ParseException;
import org.openpreservation.odf.validation.Rule;
import org.openpreservation.odf.validation.ValidationReport;
Expand Down Expand Up @@ -52,7 +53,11 @@ public boolean isPrerequisite() {

@Override
public MessageLog check(ValidationReport report) throws ParseException {
return report.document.isPackage() ? check(report.document.getPackage()) : check(report.document.getDocument().getXmlDocument());
if (report.document == null) {
return Messages.messageLogInstance();
}
return report.document.isPackage() ? check(report.document.getPackage())
: check(report.document.getDocument().getXmlDocument());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,21 @@ public ProfileResult check(final OdfPackage odfPackage) throws ParseException {
@Override
public ProfileResult check(final ValidationReport report) throws ParseException {
final MessageLog messages = Messages.messageLogInstance();
messages.add(getRulesetMessages(report.document.getPackage(),
messages.add(getRulesetMessages(report,
this.rules.stream().filter(Rule::isPrerequisite).collect(Collectors.toList())));
if (!messages.hasErrors()) {
messages.add(getRulesetMessages(report.document.getPackage(),
messages.add(getRulesetMessages(report,
this.rules.stream().filter(rule -> !rule.isPrerequisite()).collect(Collectors.toList())));
}
return ProfileResultImpl.of(report.document.getPackage().getName(), this.name, report, messages);
return ProfileResultImpl.of(report.document == null ? "" : report.document.getPackage().getName(), this.name,
report, messages);
}

private final Map<String, List<Message>> getRulesetMessages(final OdfPackage odfPackage,
private final Map<String, List<Message>> getRulesetMessages(final ValidationReport report,
final Collection<Rule> rules) throws ParseException {
final MessageLog messages = Messages.messageLogInstance();
for (final Rule rule : rules) {
final MessageLog ruleMessages = rule.check(odfPackage);
final MessageLog ruleMessages = rule.check(report);
messages.add(ruleMessages.getMessages());
}
return messages.getMessages();
Expand Down
Loading