diff --git a/odf-apps/src/main/java/org/openpreservation/odf/apps/BuildVersionProvider.java b/odf-apps/src/main/java/org/openpreservation/odf/apps/BuildVersionProvider.java index db36a9b4..5c67f452 100644 --- a/odf-apps/src/main/java/org/openpreservation/odf/apps/BuildVersionProvider.java +++ b/odf-apps/src/main/java/org/openpreservation/odf/apps/BuildVersionProvider.java @@ -6,7 +6,6 @@ import java.text.SimpleDateFormat; import java.util.Date; import java.util.Properties; -import java.util.logging.Level; import picocli.CommandLine.IVersionProvider; diff --git a/odf-core/src/main/java/org/openpreservation/odf/validation/ValidatingParserImpl.java b/odf-core/src/main/java/org/openpreservation/odf/validation/ValidatingParserImpl.java index d094b340..3f6bcd67 100644 --- a/odf-core/src/main/java/org/openpreservation/odf/validation/ValidatingParserImpl.java +++ b/odf-core/src/main/java/org/openpreservation/odf/validation/ValidatingParserImpl.java @@ -11,12 +11,10 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Objects; -import java.util.stream.Collectors; import javax.xml.parsers.ParserConfigurationException; import javax.xml.validation.Schema; -import org.openpreservation.format.xml.Namespace; import org.openpreservation.format.xml.ParseResult; import org.openpreservation.format.xml.ValidationResult; import org.openpreservation.format.xml.XmlValidator; @@ -124,8 +122,9 @@ private final List validateOdfXmlDocument(final OdfPackage odfPackage, List messageList = new ArrayList<>(); OdfNamespaces ns = OdfNamespaces.fromId(parseResult.getRootNamespace().getId()); if (OdfXmlDocuments.odfXmlDocumentOf(parseResult).isExtended()) { - messageList.add(FACTORY.getError("DOC-8", Utils.collectNsPrefixes(OdfXmlDocuments.odfXmlDocumentOf(parseResult) - .getForeignNamespaces()))); + messageList + .add(FACTORY.getError("DOC-8", Utils.collectNsPrefixes(OdfXmlDocuments.odfXmlDocumentOf(parseResult) + .getForeignNamespaces()))); return messageList; } Schema schema = (ns == null) ? null diff --git a/odf-core/src/main/java/org/openpreservation/odf/validation/Validator.java b/odf-core/src/main/java/org/openpreservation/odf/validation/Validator.java index e530119d..75063069 100644 --- a/odf-core/src/main/java/org/openpreservation/odf/validation/Validator.java +++ b/odf-core/src/main/java/org/openpreservation/odf/validation/Validator.java @@ -6,12 +6,10 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.Objects; -import java.util.stream.Collectors; import javax.xml.parsers.ParserConfigurationException; import javax.xml.validation.Schema; -import org.openpreservation.format.xml.Namespace; import org.openpreservation.format.xml.ParseResult; import org.openpreservation.format.xml.XmlParser; import org.openpreservation.format.xml.XmlValidator; diff --git a/odf-core/src/main/java/org/openpreservation/odf/validation/rules/EncryptionRule.java b/odf-core/src/main/java/org/openpreservation/odf/validation/rules/EncryptionRule.java index 23b90d85..ea7ac050 100644 --- a/odf-core/src/main/java/org/openpreservation/odf/validation/rules/EncryptionRule.java +++ b/odf-core/src/main/java/org/openpreservation/odf/validation/rules/EncryptionRule.java @@ -14,7 +14,7 @@ final class EncryptionRule extends AbstractRule { static final EncryptionRule getInstance(final Severity severity) { return new EncryptionRule("POL_1", "Encryption", - "The package MUST NOT contain any encrypted entries.", severity, true); + "The package MUST NOT contain any encrypted entries.", severity, false); } private EncryptionRule(final String id, final String name, final String description, final Severity severity, diff --git a/odf-core/src/main/java/org/openpreservation/odf/validation/rules/ProfileImpl.java b/odf-core/src/main/java/org/openpreservation/odf/validation/rules/ProfileImpl.java index d7bb9369..70a5a85d 100644 --- a/odf-core/src/main/java/org/openpreservation/odf/validation/rules/ProfileImpl.java +++ b/odf-core/src/main/java/org/openpreservation/odf/validation/rules/ProfileImpl.java @@ -1,7 +1,12 @@ package org.openpreservation.odf.validation.rules; +import java.util.Collection; import java.util.Set; +import java.util.Map; +import java.util.List; +import java.util.stream.Collectors; +import org.openpreservation.messages.Message; import org.openpreservation.messages.MessageLog; import org.openpreservation.messages.Messages; import org.openpreservation.odf.pkg.OdfPackage; @@ -11,6 +16,8 @@ import org.openpreservation.odf.validation.ValidationReport; final class ProfileImpl extends AbstractProfile { + private ValidationReport report = null; + static final ProfileImpl of(final String id, final String name, final String description, final Set rules) { return new ProfileImpl(id, name, description, rules); } @@ -18,31 +25,29 @@ static final ProfileImpl of(final String id, final String name, final String des private ProfileImpl(final String id, final String name, final String description, final Set rules) { super(id, name, description, rules); } - + @Override public ProfileResult check(final OdfPackage odfPackage) throws ParseException { - ValidationReport report = null; final MessageLog messages = Messages.messageLogInstance(); - for (final Rule rule : this.rules) { - if (!rule.isPrerequisite()) { - continue; - } + messages.add(getRulesetMessages(odfPackage, + this.rules.stream().filter(Rule::isPrerequisite).collect(Collectors.toList()))); + if (!messages.hasErrors()) { + messages.add(getRulesetMessages(odfPackage, + this.rules.stream().filter(rule -> !rule.isPrerequisite()).collect(Collectors.toList()))); + } + return ProfileResultImpl.of(odfPackage.getName(), report, messages); + } + + private final Map> getRulesetMessages(final OdfPackage odfPackage, + final Collection rules) throws ParseException { + final MessageLog messages = Messages.messageLogInstance(); + for (final Rule rule : rules) { final MessageLog ruleMessages = rule.check(odfPackage); if (rule instanceof ValidPackageRule) { report = ((ValidPackageRule) rule).getValidationReport(); } - if (ruleMessages.hasErrors()) { - return ProfileResultImpl.of(odfPackage.getName(), report, ruleMessages); - } messages.add(ruleMessages.getMessages()); } - for (final Rule rule : this.rules) { - if (rule.isPrerequisite()) { - continue; - } - final MessageLog ruleMessages = rule.check(odfPackage); - messages.add(ruleMessages.getMessages()); - } - return ProfileResultImpl.of(odfPackage.getName(), report, messages); + return messages.getMessages(); } } diff --git a/odf-core/src/main/java/org/openpreservation/odf/validation/rules/ValidPackageRule.java b/odf-core/src/main/java/org/openpreservation/odf/validation/rules/ValidPackageRule.java index 1d40756e..ae3487e3 100644 --- a/odf-core/src/main/java/org/openpreservation/odf/validation/rules/ValidPackageRule.java +++ b/odf-core/src/main/java/org/openpreservation/odf/validation/rules/ValidPackageRule.java @@ -27,7 +27,7 @@ static final ValidPackageRule getInstance(final Severity severity) throws ParserConfigurationException, SAXException { return new ValidPackageRule("POL_2", "Standard Compliance", "The file MUST comply with the standard \"OASIS Open Document Format for Office Applications (OpenDocument) v1.3\".", - severity, true); + severity, false); } private final ValidatingParser validatingParser = Validators.getValidatingParser(); diff --git a/odf-core/src/test/java/org/openpreservation/odf/validation/rules/ProfileImplTest.java b/odf-core/src/test/java/org/openpreservation/odf/validation/rules/ProfileImplTest.java index 97d70f64..1a76a48f 100644 --- a/odf-core/src/test/java/org/openpreservation/odf/validation/rules/ProfileImplTest.java +++ b/odf-core/src/test/java/org/openpreservation/odf/validation/rules/ProfileImplTest.java @@ -1,6 +1,5 @@ package org.openpreservation.odf.validation.rules; -import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue;