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

FEAT: ODF_10 Sub Document detection #109

Merged
merged 1 commit into from
Nov 26, 2023
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 @@ -39,7 +39,7 @@ public interface FileEntry {

/**
* Is the file entry encrypted?
*
*
* @return true if the file entry is encrypted, otherwise false.
*/
public boolean isEncrypted();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public MessageLog check(OdfXmlDocument document) {
public MessageLog check(OdfPackage odfPackage) throws IOException {
Objects.requireNonNull(odfPackage, "odfPackage must not be null");
MessageLog messageLog = Messages.messageLogInstance();
if (!odfPackage.hasManifest()) {
return messageLog;
}
for (FileEntry entry : odfPackage.getManifest().getEntries()) {
if (entry.isEncrypted()) {
messageLog.add(Messages.getMessageInstance(this.id, Message.Severity.ERROR, this.getName(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@ public static final Rule odf4() {
public static final Rule odf9() {
return DigitalSignaturesRule.getInstance();
}

public static final Rule odf10() {
return SubDocumentRule.getInstance();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.openpreservation.odf.validation.rules;

import java.io.IOException;
import java.util.Objects;

import org.openpreservation.messages.Message;
import org.openpreservation.messages.MessageLog;
import org.openpreservation.messages.Messages;
import org.openpreservation.odf.pkg.OdfPackage;
import org.openpreservation.odf.xml.OdfXmlDocument;

final class SubDocumentRule extends AbstractRule {

private SubDocumentRule(String id, String name, String description) {
super(id, name, description);
}

@Override
public MessageLog check(OdfXmlDocument document) {
throw new UnsupportedOperationException("Unimplemented method 'check'");
}

@Override
public MessageLog check(OdfPackage odfPackage) throws IOException {
Objects.requireNonNull(odfPackage, "odfPackage must not be null");
MessageLog messageLog = Messages.messageLogInstance();
if (odfPackage.hasManifest() && odfPackage.getManifest().getDocumentEntries().size() > 1) {
messageLog.add(Messages.getMessageInstance(this.id, Message.Severity.ERROR, this.getName(),
this.getDescription()));
}
return messageLog;
}

static final SubDocumentRule getInstance() {
return new SubDocumentRule("ODF_10", "Sub Documents",
"The package MUST NOT contain sub documents.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,3 @@ XML-1 = SaxException: %s
XML-2 = Root element of XML file %s, must be %s but found value %s.
XML-3 = Not a well formed XML document. XML parsing exception at line %d and column %d: %s.
XML-4 = Not a valid XML document. Validation exception at line %d and column %d: %s.