From 923a7255afea123ee86fa57ff390cefff29a7ace Mon Sep 17 00:00:00 2001 From: Carl Wilson Date: Thu, 26 Sep 2024 10:09:55 +0100 Subject: [PATCH] FEAT: Report blank namespaces - blank namespace prefixes are now reported as `` 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. --- README.md | 1 - .../openpreservation/odf/validation/Utils.java | 18 ++++++++++++++++++ .../odf/validation/ValidatingParserImpl.java | 4 ++-- .../odf/validation/Validator.java | 4 ++-- .../odf/messages/Messages.properties | 2 +- .../org/openpreservation/odf/docs/README.md | 1 - 6 files changed, 23 insertions(+), 7 deletions(-) create mode 100644 odf-core/src/main/java/org/openpreservation/odf/validation/Utils.java diff --git a/README.md b/README.md index f4e2a3d4..a81cd223 100644 --- a/README.md +++ b/README.md @@ -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. - diff --git a/odf-core/src/main/java/org/openpreservation/odf/validation/Utils.java b/odf-core/src/main/java/org/openpreservation/odf/validation/Utils.java new file mode 100644 index 00000000..61507ecf --- /dev/null +++ b/odf-core/src/main/java/org/openpreservation/odf/validation/Utils.java @@ -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 namespaces) { + return namespaces.stream().map(Namespace::getPrefix).map(s -> { + return s.isEmpty() ? "" : s; + }).collect(Collectors.joining()); + } +} 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 0ace6edf..d094b340 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 @@ -124,8 +124,8 @@ 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", 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 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 4d056744..e530119d 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 @@ -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); diff --git a/odf-core/src/main/resources/org/openpreservation/odf/messages/Messages.properties b/odf-core/src/main/resources/org/openpreservation/odf/messages/Messages.properties index 2b9b4a15..c02a5728 100644 --- a/odf-core/src/main/resources/org/openpreservation/odf/messages/Messages.properties +++ b/odf-core/src/main/resources/org/openpreservation/odf/messages/Messages.properties @@ -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". diff --git a/src/main/resources/org/openpreservation/odf/docs/README.md b/src/main/resources/org/openpreservation/odf/docs/README.md index 3264fd55..c6c1ab71 100644 --- a/src/main/resources/org/openpreservation/odf/docs/README.md +++ b/src/main/resources/org/openpreservation/odf/docs/README.md @@ -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. -