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: Report blank namespaces #187

Merged
merged 1 commit into from
Sep 26, 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
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ Latest version is 0.14.0-SNAPSHOT.
## About

[Open Preservation Foundation](https://openpreservation.org/)'s OpenDocument Format Validator (OPF ODF Validator) enables your organisation to validate the file format standard and a set of file format policy rules created for improving the preservation effort of any files saved in the OpenDocument Format.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.openpreservation.odf.validation;

import java.util.Set;
import java.util.stream.Collectors;

import org.openpreservation.format.xml.Namespace;

class Utils {
private Utils() {
throw new UnsupportedOperationException("Utility class");
}

public static String collectNsPrefixes(final Set<Namespace> namespaces) {
return namespaces.stream().map(Namespace::getPrefix).map(s -> {
return s.isEmpty() ? "<no-prefix>" : s;
}).collect(Collectors.joining());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ private final List<Message> validateOdfXmlDocument(final OdfPackage odfPackage,
List<Message> messageList = new ArrayList<>();
OdfNamespaces ns = OdfNamespaces.fromId(parseResult.getRootNamespace().getId());
if (OdfXmlDocuments.odfXmlDocumentOf(parseResult).isExtended()) {
messageList.add(FACTORY.getError("DOC-8", OdfXmlDocuments.odfXmlDocumentOf(parseResult)
.getForeignNamespaces().stream().map(Namespace::getPrefix).collect(Collectors.joining(","))));
messageList.add(FACTORY.getError("DOC-8", Utils.collectNsPrefixes(OdfXmlDocuments.odfXmlDocumentOf(parseResult)
.getForeignNamespaces())));
return messageList;
}
Schema schema = (ns == null) ? null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ private ValidationReport validateOpenDocumentXml(final Path toValidate)
}
if (doc.isExtended()) {
report.add(toValidate.toString(),
FACTORY.getError("DOC-8", OdfXmlDocuments.odfXmlDocumentOf(parseResult).getForeignNamespaces()
.stream().map(Namespace::getPrefix).collect(Collectors.joining(", "))));
FACTORY.getError("DOC-8", Utils.collectNsPrefixes(
OdfXmlDocuments.odfXmlDocumentOf(parseResult).getForeignNamespaces())));
} else {
Schema schema = new OdfSchemaFactory().getSchema(OdfNamespaces.OFFICE, version);
parseResult = validator.validate(parseResult, Files.newInputStream(toValidate), schema);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ DOC-4 = Invalid MIMETYPE declaration %s detected.
DOC-5 = No MIMETYPE declaration detected.
DOC-6 = OpenDocument document SHALL be format %s, no format was detected.
DOC-7 = OpenDocument document SHALL be format %s, but format %s was detected.
DOC-8 = This XML OpenDocument uses the following extended namespaces %s.
DOC-8 = This XML OpenDocument uses the following extended namespace prefixes %s.
PKG-1 = An OpenDocument Package SHALL be a well formed Zip Archive.
PKG-2 = All files contained in the Zip file shall be non compressed (STORED) or compressed using the "deflate" (DEFLATED) algorithm. Zip entry %s is compressed with an unknown algorithm.
PKG-3 = An OpenDocument Package SHALL contain a file "META-INF/manifest.xml".
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/org/openpreservation/odf/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ Latest version is ${project.version}.
## About

[Open Preservation Foundation](https://openpreservation.org/)'s OpenDocument Format Validator (OPF ODF Validator) enables your organisation to validate the file format standard and a set of file format policy rules created for improving the preservation effort of any files saved in the OpenDocument Format.

Loading