From d28e20f209f68647c35eb368593c7f3ace7c932c Mon Sep 17 00:00:00 2001 From: Romain Deltour Date: Mon, 23 Dec 2024 03:02:04 +0100 Subject: [PATCH] fix: report the container creation date Fix #1532 --- .../com/adobe/epubcheck/ocf/OCFChecker.java | 21 +++++++------------ .../adobe/epubcheck/ocf/OCFZipResources.java | 7 ++++++- .../resources/reporting/xml-report.feature | 5 +++++ 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/adobe/epubcheck/ocf/OCFChecker.java b/src/main/java/com/adobe/epubcheck/ocf/OCFChecker.java index 1461b3f86..cb2a3ada6 100755 --- a/src/main/java/com/adobe/epubcheck/ocf/OCFChecker.java +++ b/src/main/java/com/adobe/epubcheck/ocf/OCFChecker.java @@ -250,16 +250,6 @@ private boolean checkContainerFile(OCFCheckerState state) } return false; } - // FIXME 2022 - report container info - // long l = container.getTimeEntry(OCFData.containerEntry); - // if (l > 0) - // { - // Date d = new Date(l); - // String formattedDate = new - // SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").format(d); - // report.info(OCFData.containerEntry, FeatureEnum.CREATION_DATE, - // formattedDate); - // } ValidationContext containerFileContext = state.context() .url(OCFMetaFile.CONTAINER.asURL(container)).mimetype("application/xml").build(); @@ -559,9 +549,14 @@ private void reportFeatures(OCFResource resource) { for (FeatureEnum feature : resource.getProperties().keySet()) { - // report.info(context.path, feature, - // resource.getProperties().get(feature)); - report.info(resource.getPath(), feature, resource.getProperties().get(feature)); + if (feature == FeatureEnum.CREATION_DATE + && !OCFMetaFile.CONTAINER.asPath().equals(resource.getPath())) + { + // we only report the creation date once + continue; + } + report.info(resource.getPath(), feature, + resource.getProperties().get(feature)); } } diff --git a/src/main/java/com/adobe/epubcheck/ocf/OCFZipResources.java b/src/main/java/com/adobe/epubcheck/ocf/OCFZipResources.java index 6ee1bf75c..170c170ff 100644 --- a/src/main/java/com/adobe/epubcheck/ocf/OCFZipResources.java +++ b/src/main/java/com/adobe/epubcheck/ocf/OCFZipResources.java @@ -5,6 +5,8 @@ import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.security.MessageDigest; +import java.text.SimpleDateFormat; +import java.util.Date; import java.util.Enumeration; import java.util.Iterator; import java.util.Map; @@ -48,11 +50,14 @@ public OCFResource next() throws NoSuchElementException { final ZipEntry entry = entries.nextElement(); + final Map properties = ImmutableMap. builder() .put(FeatureEnum.SIZE, String.valueOf(entry.getSize())) .put(FeatureEnum.COMPRESSED_SIZE, String.valueOf(entry.getCompressedSize())) .put(FeatureEnum.COMPRESSION_METHOD, getCompressionMethod(entry)) .put(FeatureEnum.SHA_256, getSHAHash(entry, zip)) + .put(FeatureEnum.CREATION_DATE, + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").format(new Date(entry.getTime()))) .build(); return new OCFResource() @@ -87,7 +92,7 @@ public String getPath() { return entry.getName(); } - + @Override public String toString() { diff --git a/src/test/resources/reporting/xml-report.feature b/src/test/resources/reporting/xml-report.feature index 53b26b9d0..7606676d5 100644 --- a/src/test/resources/reporting/xml-report.feature +++ b/src/test/resources/reporting/xml-report.feature @@ -14,3 +14,8 @@ Then the XML report is well-formed And XPath '//repInfo' exists + Scenario: Creation date is set + When checking EPUB 'minimal' + And XPath '//repInfo/created' exists + +