Skip to content

Commit

Permalink
FEAT: Report blank namespaces
Browse files Browse the repository at this point in the history
- blank namespace prefixes are now reported as `<no-prefix>` in the `DOC-8` message`;
- altered the `DOC-8` message to emphasise that prefixes are reported;
- refactored out collection of namespaces into a Uitls class; and
- removed trailing newline from `README` and template.
  • Loading branch information
carlwilson committed Sep 26, 2024
1 parent f04a783 commit 923a725
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 7 deletions.
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.

0 comments on commit 923a725

Please sign in to comment.