From 4510a44238595adfb3e47f495842c1ea8a46c3b1 Mon Sep 17 00:00:00 2001 From: Thomas Ledoux Date: Fri, 8 Mar 2024 12:20:02 +0100 Subject: [PATCH] Checks the range of the orientation tag to be 1-9, and forces value 9 (unknown) in XML and JSON output to remind valid. Fixes #913 --- .../harvard/hul/ois/jhove/NisoImageMetadata.java | 4 ++-- .../hul/ois/jhove/handler/JsonHandler.java | 10 +++++----- .../harvard/hul/ois/jhove/handler/XmlHandler.java | 15 +++++++++++---- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/jhove-core/src/main/java/edu/harvard/hul/ois/jhove/NisoImageMetadata.java b/jhove-core/src/main/java/edu/harvard/hul/ois/jhove/NisoImageMetadata.java index bc2eb388b..113ac5b79 100644 --- a/jhove-core/src/main/java/edu/harvard/hul/ois/jhove/NisoImageMetadata.java +++ b/jhove-core/src/main/java/edu/harvard/hul/ois/jhove/NisoImageMetadata.java @@ -185,8 +185,8 @@ public class NisoImageMetadata /** 6.2.4 orientation value labels. */ public static final String [] ORIENTATION = { "", "normal", "reflected horiz", "rotated 180 deg", "reflected vert", - "left top", "rotated cw 90 deg", "Right bottom", "Rotated ccw 90 deg", - "Unknown" + "left top", "rotated cw 90 deg", "right bottom", "rotated ccw 90 deg", + "unknown" }; /** 6.1.6 planar configuration value labels. */ diff --git a/jhove-core/src/main/java/edu/harvard/hul/ois/jhove/handler/JsonHandler.java b/jhove-core/src/main/java/edu/harvard/hul/ois/jhove/handler/JsonHandler.java index eebd23059..497983268 100644 --- a/jhove-core/src/main/java/edu/harvard/hul/ois/jhove/handler/JsonHandler.java +++ b/jhove-core/src/main/java/edu/harvard/hul/ois/jhove/handler/JsonHandler.java @@ -1648,19 +1648,19 @@ protected JsonObjectBuilder showNisoImageCaptureMetadata( n = niso.getOrientation(); if (n != NisoImageMetadata.NULL) { + if (n > 9 || n < 1) { + n = 9; // force "unknown" for reserved value + } if (bMix10) { mixBuilder.add("mix:orientation", n); } else { - final String[] orient = { "unknown", "normal*", + final String[] orient = { "", "normal*", "normal, image flipped", "normal, rotated 180\u00B0", "normal, image flipped, rotated 180\u00B0", "normal, image flipped, rotated cw 90\u00B0", "normal, rotated ccw 90\u00B0", "normal, image flipped, rotated ccw 90\u00B0", - "normal, rotated cw 90\u00B0" }; - if (n > 8 || n < 0) { - n = 0; // force "unknown" for bad value - } + "normal, rotated cw 90\u00B0", "unknown" }; mixBuilder.add("mix:orientation", orient[n]); } hasBuilder = true; diff --git a/jhove-core/src/main/java/edu/harvard/hul/ois/jhove/handler/XmlHandler.java b/jhove-core/src/main/java/edu/harvard/hul/ois/jhove/handler/XmlHandler.java index cd98de9fb..68b565e00 100644 --- a/jhove-core/src/main/java/edu/harvard/hul/ois/jhove/handler/XmlHandler.java +++ b/jhove-core/src/main/java/edu/harvard/hul/ois/jhove/handler/XmlHandler.java @@ -1311,6 +1311,9 @@ protected void showNisoBasicImageParameters02(NisoImageMetadata niso, } n = niso.getOrientation(); if (n != NisoImageMetadata.NULL) { + if (n > 9 || n < 1) { + n = 9; // force "unknown" for reserved value + } fileBuf.append(margn4 + element("mix:Orientation", Integer.toString(n)) + EOL); useFileBuf = true; @@ -2717,6 +2720,9 @@ protected void showNisoImageCaptureMetadata10(NisoImageMetadata niso, n = niso.getOrientation(); if (n != NisoImageMetadata.NULL) { + if (n > 9 || n < 1) { + n = 9; // force "unknown" for reserved value + } captureBuffer.append(margn3 + element("mix:orientation", Integer.toString(n)) + EOL); useCaptureBuffer = true; @@ -3780,15 +3786,16 @@ protected void showNisoImageCaptureMetadata20(NisoImageMetadata niso, n = niso.getOrientation(); if (n != NisoImageMetadata.NULL) { - final String[] orient = { "unknown", "normal*", + // Values defined in the MIX 2.0 schema + final String[] orient = { "", "normal*", "normal, image flipped", "normal, rotated 180\u00B0", "normal, image flipped, rotated 180\u00B0", "normal, image flipped, rotated cw 90\u00B0", "normal, rotated ccw 90\u00B0", "normal, image flipped, rotated ccw 90\u00B0", - "normal, rotated cw 90\u00B0" }; - if (n > 8 || n < 0) { - n = 0; // force "unknown" for bad value + "normal, rotated cw 90\u00B0", "unknown" }; + if (n > 9 || n < 1) { + n = 9; // force "unknown" for reserved value } captureBuffer.append(margn3 + element("mix:orientation", orient[n]) + EOL);