diff --git a/jhove-apps/src/main/java/edu/harvard/hul/ois/jhove/Jhove.java b/jhove-apps/src/main/java/edu/harvard/hul/ois/jhove/Jhove.java index fbb42ee40..43e342dff 100644 --- a/jhove-apps/src/main/java/edu/harvard/hul/ois/jhove/Jhove.java +++ b/jhove-apps/src/main/java/edu/harvard/hul/ois/jhove/Jhove.java @@ -1,5 +1,3 @@ -package edu.harvard.hul.ois.jhove; - /********************************************************************** * Jhove - JSTOR/Harvard Object Validation Environment * Copyright 2004-2007 by the President and Fellows of Harvard College @@ -19,13 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA **********************************************************************/ - -import edu.harvard.hul.ois.jhove.App; -import edu.harvard.hul.ois.jhove.ExitCode; -import edu.harvard.hul.ois.jhove.CoreMessageConstants; -import edu.harvard.hul.ois.jhove.JhoveBase; -import edu.harvard.hul.ois.jhove.Module; -import edu.harvard.hul.ois.jhove.OutputHandler; +package edu.harvard.hul.ois.jhove; import java.util.ArrayList; import java.util.List; @@ -38,14 +30,15 @@ public class Jhove { /** Logger for this class. */ private static final Logger LOGGER = Logger.getLogger(Jhove.class.getCanonicalName()); - private Jhove() { - throw new AssertionError("Should never enter private constructor"); - } - private static final String C_CONFIG_OPTION = "-c"; private static final String X_CONFIG_OPTION = "-x"; - private static final String NOT_FOUND = "' not found"; + private static final String NOT_FOUND = "not found"; private static final String HANDLER = "Handler '"; + private static final String MODULE = "Module"; + + private Jhove() { + throw new AssertionError("Should never enter private constructor"); + } /** * MAIN ENTRY POINT. @@ -233,17 +226,17 @@ public static void main(String[] args) { } Module module = je.getModule(moduleName); if (module == null && moduleName != null) { - LOGGER.log(Level.SEVERE, "Module '" + moduleName + NOT_FOUND); + LOGGER.log(Level.SEVERE, notFoundMessage(MODULE, moduleName)); System.exit(ExitCode.ERROR.getReturnCode()); } OutputHandler about = je.getHandler(aboutHandler); if (about == null && aboutHandler != null) { - LOGGER.log(Level.SEVERE, HANDLER + aboutHandler + NOT_FOUND); + LOGGER.log(Level.SEVERE, notFoundMessage(HANDLER, aboutHandler)); System.exit(ExitCode.ERROR.getReturnCode()); } OutputHandler handler = je.getHandler(handlerName); if (handler == null && handlerName != null) { - LOGGER.log(Level.SEVERE, HANDLER + handlerName + NOT_FOUND); + LOGGER.log(Level.SEVERE, notFoundMessage(HANDLER, handlerName)); System.exit(ExitCode.ERROR.getReturnCode()); } String[] dirFileOrUri = null; @@ -264,9 +257,13 @@ public static void main(String[] args) { je.setSignatureFlag(signature); je.dispatch(app, module, about, handler, outputFile, dirFileOrUri); } catch (Exception e) { - LOGGER.log(Level.SEVERE, e.getMessage()); + LOGGER.log(Level.SEVERE, e.getMessage(), e); e.printStackTrace(System.err); System.exit(ExitCode.ERROR.getReturnCode()); } } + + private static final String notFoundMessage(final String notFoundType, final String notFoundName) { + return String.format("%s '%s' %s", notFoundType, notFoundName, NOT_FOUND); + } } diff --git a/jhove-bbt/scripts/create-1.33-target.sh b/jhove-bbt/scripts/create-1.33-target.sh index 0191c69e3..f3148cf38 100755 --- a/jhove-bbt/scripts/create-1.33-target.sh +++ b/jhove-bbt/scripts/create-1.33-target.sh @@ -56,3 +56,16 @@ echo "TEST BASELINE: Creating baseline" echo " - copying ${baselineRoot} baseline to ${targetRoot}" cp -R "${baselineRoot}" "${targetRoot}" +# Insert new PDF-2.x signature nodes into the PDF audit XML files +find "${targetRoot}" -type f -name "audit-PDF-hul.jhove.xml" -exec sed -i 's/<\/signatures>/ \n Magic number<\/type>\n %PDF-2.<\/value>\n 0x0<\/offset>\n Mandatory<\/use>\n <\/signature>\n <\/signatures>/' {} \; + +# Copy the two new version regression test files, where handling of PDF version declaration has been improved/changed +declare -a pdf_version_affected=("errors/modules/PDF-hul/pdf-hul-61-CERN-2005-009.pdf.jhove.xml" + "regression/modules/PDF-hul/PDF-HUL-137.pdf.jhove.xml" + "regression/modules/PDF-hul/PDF-HUL-137_fixed.pdf.jhove.xml") +for filename in "${pdf_version_affected[@]}" +do + if [[ -f "${candidateRoot}/${filename}" ]]; then + cp "${candidateRoot}/${filename}" "${targetRoot}/${filename}" + fi +done diff --git a/jhove-core/src/main/java/edu/harvard/hul/ois/jhove/messages/JhoveMessages.java b/jhove-core/src/main/java/edu/harvard/hul/ois/jhove/messages/JhoveMessages.java index 95fbacbda..291664904 100644 --- a/jhove-core/src/main/java/edu/harvard/hul/ois/jhove/messages/JhoveMessages.java +++ b/jhove-core/src/main/java/edu/harvard/hul/ois/jhove/messages/JhoveMessages.java @@ -48,7 +48,11 @@ public static JhoveMessage getMessageInstance(final String id, return getMessageInstance(id, message, EMPTY_MESSAGE); } - /** + public static JhoveMessage getMessageInstance(final JhoveMessage message, final String subMessage) { + return getMessageInstance(message.getId(), message.getMessage(), subMessage); + } + + /** * Create a new JhoveMessage instance with the given id, message and * sub-message * diff --git a/jhove-core/src/test/java/edu/harvard/hul/ois/jhove/messages/JhoveMessagesTest.java b/jhove-core/src/test/java/edu/harvard/hul/ois/jhove/messages/JhoveMessagesTest.java index 1d4171d56..f884bab0a 100644 --- a/jhove-core/src/test/java/edu/harvard/hul/ois/jhove/messages/JhoveMessagesTest.java +++ b/jhove-core/src/test/java/edu/harvard/hul/ois/jhove/messages/JhoveMessagesTest.java @@ -61,10 +61,11 @@ public void testMessageInstanceEmptyId() { @Test public void testMessageInstanceNullId() { + final String id = null; assertThrows("IllegalArgument exception expected", IllegalArgumentException.class, () -> { - JhoveMessages.getMessageInstance(null, "MSG"); + JhoveMessages.getMessageInstance(id, "MSG"); }); } diff --git a/jhove-modules/pdf-hul/src/main/java/edu/harvard/hul/ois/jhove/module/PdfModule.java b/jhove-modules/pdf-hul/src/main/java/edu/harvard/hul/ois/jhove/module/PdfModule.java index c3014d307..a1725807b 100644 --- a/jhove-modules/pdf-hul/src/main/java/edu/harvard/hul/ois/jhove/module/PdfModule.java +++ b/jhove-modules/pdf-hul/src/main/java/edu/harvard/hul/ois/jhove/module/PdfModule.java @@ -634,7 +634,9 @@ public PdfModule() { _signature.add(new ExternalSignature(EXT, SignatureType.EXTENSION, SignatureUseType.OPTIONAL)); - _signature.add(new InternalSignature(PdfHeader.PDF_SIG_HEADER, + _signature.add(new InternalSignature(PdfHeader.PDF_1_SIG_HEADER, + SignatureType.MAGIC, SignatureUseType.MANDATORY, 0)); + _signature.add(new InternalSignature(PdfHeader.PDF_2_SIG_HEADER, SignatureType.MAGIC, SignatureUseType.MANDATORY, 0)); doc = new Document( @@ -1043,24 +1045,19 @@ protected final void initParse() { _nFonts = 0; } - protected boolean parseHeader(RepInfo info) throws IOException { + protected boolean parseHeader(RepInfo info) { PdfHeader header = null; try { header = PdfHeader.parseHeader(_parser); - } catch (PdfMalformedException e) { - info.setWellFormed(false); - info.setMessage(new ErrorMessage(MessageConstants.PDF_HUL_155, 0L)); // PDF-HUL-155 - return false; - } - if (header == null) { - info.setWellFormed(false); - info.setMessage(new ErrorMessage(MessageConstants.PDF_HUL_137, 0L)); // PDF-HUL-137 + } catch (PdfException e) { + if (e instanceof PdfInvalidException) { + info.setValid(false); + } else { + info.setWellFormed(false); + } + info.setMessage(new ErrorMessage(e.getJhoveMessage(), 0L)); // PDF-HUL-155 return false; } - if (!header.isVersionValid()) { - info.setValid(false); - info.setMessage(new ErrorMessage(MessageConstants.PDF_HUL_148, 0L)); // PDF-HUL-148 - } _version = header.getVersionString(); _pdfACompliant = header.isPdfACompliant(); info.setSigMatch(_name); diff --git a/jhove-modules/pdf-hul/src/main/java/edu/harvard/hul/ois/jhove/module/pdf/MessageConstants.java b/jhove-modules/pdf-hul/src/main/java/edu/harvard/hul/ois/jhove/module/pdf/MessageConstants.java index e8cea88e4..f518d618b 100644 --- a/jhove-modules/pdf-hul/src/main/java/edu/harvard/hul/ois/jhove/module/pdf/MessageConstants.java +++ b/jhove-modules/pdf-hul/src/main/java/edu/harvard/hul/ois/jhove/module/pdf/MessageConstants.java @@ -33,185 +33,188 @@ */ public enum MessageConstants { - INSTANCE; + INSTANCE; public static final JhoveMessageFactory messageFactory = JhoveMessages .getInstance("edu.harvard.hul.ois.jhove.module.pdf.ErrorMessages"); - public static final JhoveMessage PDF_HUL_1 = messageFactory.getMessage("PDF-HUL-1"); - public static final JhoveMessage PDF_HUL_2 = messageFactory.getMessage("PDF-HUL-2"); - public static final JhoveMessage PDF_HUL_3 = messageFactory.getMessage("PDF-HUL-3"); - public static final JhoveMessage PDF_HUL_4 = messageFactory.getMessage("PDF-HUL-4"); - public static final JhoveMessage PDF_HUL_5 = messageFactory.getMessage("PDF-HUL-5"); - public static final JhoveMessage PDF_HUL_6 = messageFactory.getMessage("PDF-HUL-6"); - public static final JhoveMessage PDF_HUL_7 = messageFactory.getMessage("PDF-HUL-7"); - public static final JhoveMessage PDF_HUL_8 = messageFactory.getMessage("PDF-HUL-8"); - public static final JhoveMessage PDF_HUL_9 = messageFactory.getMessage("PDF-HUL-9"); - public static final JhoveMessage PDF_HUL_10 = messageFactory.getMessage("PDF-HUL-10"); - public static final JhoveMessage PDF_HUL_11 = messageFactory.getMessage("PDF-HUL-11"); - public static final JhoveMessage PDF_HUL_12 = messageFactory.getMessage("PDF-HUL-12"); - public static final JhoveMessage PDF_HUL_13 = messageFactory.getMessage("PDF-HUL-13"); - public static final JhoveMessage PDF_HUL_14 = messageFactory.getMessage("PDF-HUL-14"); - public static final JhoveMessage PDF_HUL_15 = messageFactory.getMessage("PDF-HUL-15"); - public static final JhoveMessage PDF_HUL_16 = messageFactory.getMessage("PDF-HUL-16"); - public static final JhoveMessage PDF_HUL_17 = messageFactory.getMessage("PDF-HUL-17"); - public static final JhoveMessage PDF_HUL_18 = messageFactory.getMessage("PDF-HUL-18"); - public static final JhoveMessage PDF_HUL_19 = messageFactory.getMessage("PDF-HUL-19"); - public static final JhoveMessage PDF_HUL_20 = messageFactory.getMessage("PDF-HUL-20"); - public static final JhoveMessage PDF_HUL_21 = messageFactory.getMessage("PDF-HUL-21"); - public static final JhoveMessage PDF_HUL_22 = messageFactory.getMessage("PDF-HUL-22"); - public static final JhoveMessage PDF_HUL_23 = messageFactory.getMessage("PDF-HUL-23"); - public static final JhoveMessage PDF_HUL_24 = messageFactory.getMessage("PDF-HUL-24"); - public static final JhoveMessage PDF_HUL_25 = messageFactory.getMessage("PDF-HUL-25"); - public static final JhoveMessage PDF_HUL_26 = messageFactory.getMessage("PDF-HUL-26"); - public static final JhoveMessage PDF_HUL_27 = messageFactory.getMessage("PDF-HUL-27"); - public static final JhoveMessage PDF_HUL_28 = messageFactory.getMessage("PDF-HUL-28"); - public static final JhoveMessage PDF_HUL_29 = messageFactory.getMessage("PDF-HUL-29"); - public static final JhoveMessage PDF_HUL_30 = messageFactory.getMessage("PDF-HUL-30"); - public static final JhoveMessage PDF_HUL_31 = messageFactory.getMessage("PDF-HUL-31"); - public static final JhoveMessage PDF_HUL_32 = messageFactory.getMessage("PDF-HUL-32"); - public static final JhoveMessage PDF_HUL_33 = messageFactory.getMessage("PDF-HUL-33"); - public static final JhoveMessage PDF_HUL_34 = messageFactory.getMessage("PDF-HUL-34"); - public static final JhoveMessage PDF_HUL_35 = messageFactory.getMessage("PDF-HUL-35"); - public static final JhoveMessage PDF_HUL_36 = messageFactory.getMessage("PDF-HUL-36"); - public static final JhoveMessage PDF_HUL_37 = messageFactory.getMessage("PDF-HUL-37"); - public static final JhoveMessage PDF_HUL_38 = messageFactory.getMessage("PDF-HUL-38"); - public static final JhoveMessage PDF_HUL_39 = messageFactory.getMessage("PDF-HUL-39"); - public static final JhoveMessage PDF_HUL_40 = messageFactory.getMessage("PDF-HUL-40"); - public static final JhoveMessage PDF_HUL_41 = messageFactory.getMessage("PDF-HUL-41"); - public static final JhoveMessage PDF_HUL_42 = messageFactory.getMessage("PDF-HUL-42"); - public static final JhoveMessage PDF_HUL_43 = messageFactory.getMessage("PDF-HUL-43"); - public static final JhoveMessage PDF_HUL_44 = messageFactory.getMessage("PDF-HUL-44"); - public static final JhoveMessage PDF_HUL_45 = messageFactory.getMessage("PDF-HUL-45"); - public static final JhoveMessage PDF_HUL_46 = messageFactory.getMessage("PDF-HUL-46"); - public static final JhoveMessage PDF_HUL_47 = messageFactory.getMessage("PDF-HUL-47"); - public static final JhoveMessage PDF_HUL_48 = messageFactory.getMessage("PDF-HUL-48"); - public static final JhoveMessage PDF_HUL_49 = messageFactory.getMessage("PDF-HUL-49"); - public static final JhoveMessage PDF_HUL_50 = messageFactory.getMessage("PDF-HUL-50"); - public static final JhoveMessage PDF_HUL_51 = messageFactory.getMessage("PDF-HUL-51"); - public static final JhoveMessage PDF_HUL_52 = messageFactory.getMessage("PDF-HUL-52"); - public static final JhoveMessage PDF_HUL_53 = messageFactory.getMessage("PDF-HUL-53"); - public static final JhoveMessage PDF_HUL_54 = messageFactory.getMessage("PDF-HUL-54"); - public static final JhoveMessage PDF_HUL_55 = messageFactory.getMessage("PDF-HUL-55"); - public static final JhoveMessage PDF_HUL_56 = messageFactory.getMessage("PDF-HUL-56"); - public static final JhoveMessage PDF_HUL_57 = messageFactory.getMessage("PDF-HUL-57"); - public static final JhoveMessage PDF_HUL_58 = messageFactory.getMessage("PDF-HUL-58"); - public static final JhoveMessage PDF_HUL_59 = messageFactory.getMessage("PDF-HUL-59"); - public static final JhoveMessage PDF_HUL_60 = messageFactory.getMessage("PDF-HUL-60"); - public static final JhoveMessage PDF_HUL_61 = messageFactory.getMessage("PDF-HUL-61"); - public static final JhoveMessage PDF_HUL_62 = messageFactory.getMessage("PDF-HUL-62"); - public static final JhoveMessage PDF_HUL_63 = messageFactory.getMessage("PDF-HUL-63"); - public static final JhoveMessage PDF_HUL_64 = messageFactory.getMessage("PDF-HUL-64"); - public static final JhoveMessage PDF_HUL_65 = messageFactory.getMessage("PDF-HUL-65"); - public static final JhoveMessage PDF_HUL_66 = messageFactory.getMessage("PDF-HUL-66"); - public static final JhoveMessage PDF_HUL_67 = messageFactory.getMessage("PDF-HUL-67"); - public static final JhoveMessage PDF_HUL_68 = messageFactory.getMessage("PDF-HUL-68"); - public static final JhoveMessage PDF_HUL_69 = messageFactory.getMessage("PDF-HUL-69"); - public static final JhoveMessage PDF_HUL_70 = messageFactory.getMessage("PDF-HUL-70"); - public static final JhoveMessage PDF_HUL_71 = messageFactory.getMessage("PDF-HUL-71"); - public static final JhoveMessage PDF_HUL_72 = messageFactory.getMessage("PDF-HUL-72"); - public static final JhoveMessage PDF_HUL_73 = messageFactory.getMessage("PDF-HUL-73"); - public static final JhoveMessage PDF_HUL_74 = messageFactory.getMessage("PDF-HUL-74"); - public static final JhoveMessage PDF_HUL_75 = messageFactory.getMessage("PDF-HUL-75"); - public static final JhoveMessage PDF_HUL_76 = messageFactory.getMessage("PDF-HUL-76"); - public static final JhoveMessage PDF_HUL_77 = messageFactory.getMessage("PDF-HUL-77"); - public static final JhoveMessage PDF_HUL_78 = messageFactory.getMessage("PDF-HUL-78"); - public static final JhoveMessage PDF_HUL_79 = messageFactory.getMessage("PDF-HUL-79"); - public static final JhoveMessage PDF_HUL_80 = messageFactory.getMessage("PDF-HUL-80"); - public static final JhoveMessage PDF_HUL_81 = messageFactory.getMessage("PDF-HUL-81"); - public static final JhoveMessage PDF_HUL_82 = messageFactory.getMessage("PDF-HUL-82"); - public static final JhoveMessage PDF_HUL_83 = messageFactory.getMessage("PDF-HUL-83"); - public static final JhoveMessage PDF_HUL_84 = messageFactory.getMessage("PDF-HUL-84"); - public static final JhoveMessage PDF_HUL_85 = messageFactory.getMessage("PDF-HUL-85"); - public static final JhoveMessage PDF_HUL_86 = messageFactory.getMessage("PDF-HUL-86"); - public static final JhoveMessage PDF_HUL_87 = messageFactory.getMessage("PDF-HUL-87"); - public static final JhoveMessage PDF_HUL_88 = messageFactory.getMessage("PDF-HUL-88"); - public static final JhoveMessage PDF_HUL_89 = messageFactory.getMessage("PDF-HUL-89"); - public static final JhoveMessage PDF_HUL_90 = messageFactory.getMessage("PDF-HUL-90"); - public static final JhoveMessage PDF_HUL_91 = messageFactory.getMessage("PDF-HUL-91"); - public static final JhoveMessage PDF_HUL_92 = messageFactory.getMessage("PDF-HUL-92"); - public static final JhoveMessage PDF_HUL_93 = messageFactory.getMessage("PDF-HUL-93"); - public static final JhoveMessage PDF_HUL_94 = messageFactory.getMessage("PDF-HUL-94"); - public static final JhoveMessage PDF_HUL_95 = messageFactory.getMessage("PDF-HUL-95"); - public static final JhoveMessage PDF_HUL_96 = messageFactory.getMessage("PDF-HUL-96"); - public static final JhoveMessage PDF_HUL_97 = messageFactory.getMessage("PDF-HUL-97"); - public static final JhoveMessage PDF_HUL_98 = messageFactory.getMessage("PDF-HUL-98"); - public static final JhoveMessage PDF_HUL_99 = messageFactory.getMessage("PDF-HUL-99"); - public static final JhoveMessage PDF_HUL_100 = messageFactory.getMessage("PDF-HUL-100"); - public static final JhoveMessage PDF_HUL_101 = messageFactory.getMessage("PDF-HUL-101"); - public static final JhoveMessage PDF_HUL_102 = messageFactory.getMessage("PDF-HUL-102"); - public static final JhoveMessage PDF_HUL_103 = messageFactory.getMessage("PDF-HUL-103"); - public static final JhoveMessage PDF_HUL_104 = messageFactory.getMessage("PDF-HUL-104"); - public static final JhoveMessage PDF_HUL_105 = messageFactory.getMessage("PDF-HUL-105"); - public static final JhoveMessage PDF_HUL_106 = messageFactory.getMessage("PDF-HUL-106"); - public static final JhoveMessage PDF_HUL_107 = messageFactory.getMessage("PDF-HUL-107"); - public static final JhoveMessage PDF_HUL_108 = messageFactory.getMessage("PDF-HUL-108"); - public static final JhoveMessage PDF_HUL_109 = messageFactory.getMessage("PDF-HUL-109"); - public static final JhoveMessage PDF_HUL_110 = messageFactory.getMessage("PDF-HUL-110"); - public static final JhoveMessage PDF_HUL_111 = messageFactory.getMessage("PDF-HUL-111"); - public static final JhoveMessage PDF_HUL_112 = messageFactory.getMessage("PDF-HUL-112"); - public static final JhoveMessage PDF_HUL_113 = messageFactory.getMessage("PDF-HUL-113"); - public static final JhoveMessage PDF_HUL_114 = messageFactory.getMessage("PDF-HUL-114"); - public static final JhoveMessage PDF_HUL_115 = messageFactory.getMessage("PDF-HUL-115"); - public static final JhoveMessage PDF_HUL_116 = messageFactory.getMessage("PDF-HUL-116"); - public static final JhoveMessage PDF_HUL_117 = messageFactory.getMessage("PDF-HUL-117"); - public static final JhoveMessage PDF_HUL_118 = messageFactory.getMessage("PDF-HUL-118"); - public static final JhoveMessage PDF_HUL_119 = messageFactory.getMessage("PDF-HUL-119"); - public static final JhoveMessage PDF_HUL_120 = messageFactory.getMessage("PDF-HUL-120"); - public static final JhoveMessage PDF_HUL_121 = messageFactory.getMessage("PDF-HUL-121"); - public static final JhoveMessage PDF_HUL_122 = messageFactory.getMessage("PDF-HUL-122"); - public static final JhoveMessage PDF_HUL_123 = messageFactory.getMessage("PDF-HUL-123"); - public static final JhoveMessage PDF_HUL_124 = messageFactory.getMessage("PDF-HUL-124"); - public static final JhoveMessage PDF_HUL_125 = messageFactory.getMessage("PDF-HUL-125"); - public static final JhoveMessage PDF_HUL_126 = messageFactory.getMessage("PDF-HUL-126"); - public static final JhoveMessage PDF_HUL_127 = messageFactory.getMessage("PDF-HUL-127"); - public static final JhoveMessage PDF_HUL_128 = messageFactory.getMessage("PDF-HUL-128"); - public static final JhoveMessage PDF_HUL_129 = messageFactory.getMessage("PDF-HUL-129"); - public static final JhoveMessage PDF_HUL_130 = messageFactory.getMessage("PDF-HUL-130"); - public static final JhoveMessage PDF_HUL_131 = messageFactory.getMessage("PDF-HUL-131"); - public static final JhoveMessage PDF_HUL_132 = messageFactory.getMessage("PDF-HUL-132"); - public static final JhoveMessage PDF_HUL_133 = messageFactory.getMessage("PDF-HUL-133"); - public static final JhoveMessage PDF_HUL_134 = messageFactory.getMessage("PDF-HUL-134"); - public static final JhoveMessage PDF_HUL_135 = messageFactory.getMessage("PDF-HUL-135"); - public static final JhoveMessage PDF_HUL_136 = messageFactory.getMessage("PDF-HUL-136"); - public static final JhoveMessage PDF_HUL_136_SUB = messageFactory.getMessage("PDF-HUL-136-SUB"); - public static final JhoveMessage PDF_HUL_137 = messageFactory.getMessage("PDF-HUL-137"); - public static final JhoveMessage PDF_HUL_138 = messageFactory.getMessage("PDF-HUL-138"); - public static final JhoveMessage PDF_HUL_139 = messageFactory.getMessage("PDF-HUL-139"); - public static final JhoveMessage PDF_HUL_140 = messageFactory.getMessage("PDF-HUL-140"); - public static final JhoveMessage PDF_HUL_141 = messageFactory.getMessage("PDF-HUL-141"); - public static final JhoveMessage PDF_HUL_142 = messageFactory.getMessage("PDF-HUL-142"); - public static final JhoveMessage PDF_HUL_143 = messageFactory.getMessage("PDF-HUL-143"); - public static final JhoveMessage PDF_HUL_144 = messageFactory.getMessage("PDF-HUL-144"); - public static final JhoveMessage PDF_HUL_145 = messageFactory.getMessage("PDF-HUL-145"); - public static final JhoveMessage PDF_HUL_146 = messageFactory.getMessage("PDF-HUL-146"); - public static final JhoveMessage PDF_HUL_147 = messageFactory.getMessage("PDF-HUL-147"); - public static final JhoveMessage PDF_HUL_148 = messageFactory.getMessage("PDF-HUL-148"); - public static final JhoveMessage PDF_HUL_149 = messageFactory.getMessage("PDF-HUL-149"); - public static final JhoveMessage PDF_HUL_150 = messageFactory.getMessage("PDF-HUL-150"); + public static final JhoveMessage PDF_HUL_1 = messageFactory.getMessage("PDF-HUL-1"); + public static final JhoveMessage PDF_HUL_2 = messageFactory.getMessage("PDF-HUL-2"); + public static final JhoveMessage PDF_HUL_3 = messageFactory.getMessage("PDF-HUL-3"); + public static final JhoveMessage PDF_HUL_4 = messageFactory.getMessage("PDF-HUL-4"); + public static final JhoveMessage PDF_HUL_5 = messageFactory.getMessage("PDF-HUL-5"); + public static final JhoveMessage PDF_HUL_6 = messageFactory.getMessage("PDF-HUL-6"); + public static final JhoveMessage PDF_HUL_7 = messageFactory.getMessage("PDF-HUL-7"); + public static final JhoveMessage PDF_HUL_8 = messageFactory.getMessage("PDF-HUL-8"); + public static final JhoveMessage PDF_HUL_9 = messageFactory.getMessage("PDF-HUL-9"); + public static final JhoveMessage PDF_HUL_10 = messageFactory.getMessage("PDF-HUL-10"); + public static final JhoveMessage PDF_HUL_11 = messageFactory.getMessage("PDF-HUL-11"); + public static final JhoveMessage PDF_HUL_12 = messageFactory.getMessage("PDF-HUL-12"); + public static final JhoveMessage PDF_HUL_13 = messageFactory.getMessage("PDF-HUL-13"); + public static final JhoveMessage PDF_HUL_14 = messageFactory.getMessage("PDF-HUL-14"); + public static final JhoveMessage PDF_HUL_15 = messageFactory.getMessage("PDF-HUL-15"); + public static final JhoveMessage PDF_HUL_16 = messageFactory.getMessage("PDF-HUL-16"); + public static final JhoveMessage PDF_HUL_17 = messageFactory.getMessage("PDF-HUL-17"); + public static final JhoveMessage PDF_HUL_18 = messageFactory.getMessage("PDF-HUL-18"); + public static final JhoveMessage PDF_HUL_19 = messageFactory.getMessage("PDF-HUL-19"); + public static final JhoveMessage PDF_HUL_20 = messageFactory.getMessage("PDF-HUL-20"); + public static final JhoveMessage PDF_HUL_21 = messageFactory.getMessage("PDF-HUL-21"); + public static final JhoveMessage PDF_HUL_22 = messageFactory.getMessage("PDF-HUL-22"); + public static final JhoveMessage PDF_HUL_23 = messageFactory.getMessage("PDF-HUL-23"); + public static final JhoveMessage PDF_HUL_24 = messageFactory.getMessage("PDF-HUL-24"); + public static final JhoveMessage PDF_HUL_25 = messageFactory.getMessage("PDF-HUL-25"); + public static final JhoveMessage PDF_HUL_26 = messageFactory.getMessage("PDF-HUL-26"); + public static final JhoveMessage PDF_HUL_27 = messageFactory.getMessage("PDF-HUL-27"); + public static final JhoveMessage PDF_HUL_28 = messageFactory.getMessage("PDF-HUL-28"); + public static final JhoveMessage PDF_HUL_29 = messageFactory.getMessage("PDF-HUL-29"); + public static final JhoveMessage PDF_HUL_30 = messageFactory.getMessage("PDF-HUL-30"); + public static final JhoveMessage PDF_HUL_31 = messageFactory.getMessage("PDF-HUL-31"); + public static final JhoveMessage PDF_HUL_32 = messageFactory.getMessage("PDF-HUL-32"); + public static final JhoveMessage PDF_HUL_33 = messageFactory.getMessage("PDF-HUL-33"); + public static final JhoveMessage PDF_HUL_34 = messageFactory.getMessage("PDF-HUL-34"); + public static final JhoveMessage PDF_HUL_35 = messageFactory.getMessage("PDF-HUL-35"); + public static final JhoveMessage PDF_HUL_36 = messageFactory.getMessage("PDF-HUL-36"); + public static final JhoveMessage PDF_HUL_37 = messageFactory.getMessage("PDF-HUL-37"); + public static final JhoveMessage PDF_HUL_38 = messageFactory.getMessage("PDF-HUL-38"); + public static final JhoveMessage PDF_HUL_39 = messageFactory.getMessage("PDF-HUL-39"); + public static final JhoveMessage PDF_HUL_40 = messageFactory.getMessage("PDF-HUL-40"); + public static final JhoveMessage PDF_HUL_41 = messageFactory.getMessage("PDF-HUL-41"); + public static final JhoveMessage PDF_HUL_42 = messageFactory.getMessage("PDF-HUL-42"); + public static final JhoveMessage PDF_HUL_43 = messageFactory.getMessage("PDF-HUL-43"); + public static final JhoveMessage PDF_HUL_44 = messageFactory.getMessage("PDF-HUL-44"); + public static final JhoveMessage PDF_HUL_45 = messageFactory.getMessage("PDF-HUL-45"); + public static final JhoveMessage PDF_HUL_46 = messageFactory.getMessage("PDF-HUL-46"); + public static final JhoveMessage PDF_HUL_47 = messageFactory.getMessage("PDF-HUL-47"); + public static final JhoveMessage PDF_HUL_48 = messageFactory.getMessage("PDF-HUL-48"); + public static final JhoveMessage PDF_HUL_49 = messageFactory.getMessage("PDF-HUL-49"); + public static final JhoveMessage PDF_HUL_50 = messageFactory.getMessage("PDF-HUL-50"); + public static final JhoveMessage PDF_HUL_51 = messageFactory.getMessage("PDF-HUL-51"); + public static final JhoveMessage PDF_HUL_52 = messageFactory.getMessage("PDF-HUL-52"); + public static final JhoveMessage PDF_HUL_53 = messageFactory.getMessage("PDF-HUL-53"); + public static final JhoveMessage PDF_HUL_54 = messageFactory.getMessage("PDF-HUL-54"); + public static final JhoveMessage PDF_HUL_55 = messageFactory.getMessage("PDF-HUL-55"); + public static final JhoveMessage PDF_HUL_56 = messageFactory.getMessage("PDF-HUL-56"); + public static final JhoveMessage PDF_HUL_57 = messageFactory.getMessage("PDF-HUL-57"); + public static final JhoveMessage PDF_HUL_58 = messageFactory.getMessage("PDF-HUL-58"); + public static final JhoveMessage PDF_HUL_59 = messageFactory.getMessage("PDF-HUL-59"); + public static final JhoveMessage PDF_HUL_60 = messageFactory.getMessage("PDF-HUL-60"); + public static final JhoveMessage PDF_HUL_61 = messageFactory.getMessage("PDF-HUL-61"); + public static final JhoveMessage PDF_HUL_62 = messageFactory.getMessage("PDF-HUL-62"); + public static final JhoveMessage PDF_HUL_63 = messageFactory.getMessage("PDF-HUL-63"); + public static final JhoveMessage PDF_HUL_64 = messageFactory.getMessage("PDF-HUL-64"); + public static final JhoveMessage PDF_HUL_65 = messageFactory.getMessage("PDF-HUL-65"); + public static final JhoveMessage PDF_HUL_66 = messageFactory.getMessage("PDF-HUL-66"); + public static final JhoveMessage PDF_HUL_67 = messageFactory.getMessage("PDF-HUL-67"); + public static final JhoveMessage PDF_HUL_68 = messageFactory.getMessage("PDF-HUL-68"); + public static final JhoveMessage PDF_HUL_69 = messageFactory.getMessage("PDF-HUL-69"); + public static final JhoveMessage PDF_HUL_70 = messageFactory.getMessage("PDF-HUL-70"); + public static final JhoveMessage PDF_HUL_71 = messageFactory.getMessage("PDF-HUL-71"); + public static final JhoveMessage PDF_HUL_72 = messageFactory.getMessage("PDF-HUL-72"); + public static final JhoveMessage PDF_HUL_73 = messageFactory.getMessage("PDF-HUL-73"); + public static final JhoveMessage PDF_HUL_74 = messageFactory.getMessage("PDF-HUL-74"); + public static final JhoveMessage PDF_HUL_75 = messageFactory.getMessage("PDF-HUL-75"); + public static final JhoveMessage PDF_HUL_76 = messageFactory.getMessage("PDF-HUL-76"); + public static final JhoveMessage PDF_HUL_77 = messageFactory.getMessage("PDF-HUL-77"); + public static final JhoveMessage PDF_HUL_78 = messageFactory.getMessage("PDF-HUL-78"); + public static final JhoveMessage PDF_HUL_79 = messageFactory.getMessage("PDF-HUL-79"); + public static final JhoveMessage PDF_HUL_80 = messageFactory.getMessage("PDF-HUL-80"); + public static final JhoveMessage PDF_HUL_81 = messageFactory.getMessage("PDF-HUL-81"); + public static final JhoveMessage PDF_HUL_82 = messageFactory.getMessage("PDF-HUL-82"); + public static final JhoveMessage PDF_HUL_83 = messageFactory.getMessage("PDF-HUL-83"); + public static final JhoveMessage PDF_HUL_84 = messageFactory.getMessage("PDF-HUL-84"); + public static final JhoveMessage PDF_HUL_85 = messageFactory.getMessage("PDF-HUL-85"); + public static final JhoveMessage PDF_HUL_86 = messageFactory.getMessage("PDF-HUL-86"); + public static final JhoveMessage PDF_HUL_87 = messageFactory.getMessage("PDF-HUL-87"); + public static final JhoveMessage PDF_HUL_88 = messageFactory.getMessage("PDF-HUL-88"); + public static final JhoveMessage PDF_HUL_89 = messageFactory.getMessage("PDF-HUL-89"); + public static final JhoveMessage PDF_HUL_90 = messageFactory.getMessage("PDF-HUL-90"); + public static final JhoveMessage PDF_HUL_91 = messageFactory.getMessage("PDF-HUL-91"); + public static final JhoveMessage PDF_HUL_92 = messageFactory.getMessage("PDF-HUL-92"); + public static final JhoveMessage PDF_HUL_93 = messageFactory.getMessage("PDF-HUL-93"); + public static final JhoveMessage PDF_HUL_94 = messageFactory.getMessage("PDF-HUL-94"); + public static final JhoveMessage PDF_HUL_95 = messageFactory.getMessage("PDF-HUL-95"); + public static final JhoveMessage PDF_HUL_96 = messageFactory.getMessage("PDF-HUL-96"); + public static final JhoveMessage PDF_HUL_97 = messageFactory.getMessage("PDF-HUL-97"); + public static final JhoveMessage PDF_HUL_98 = messageFactory.getMessage("PDF-HUL-98"); + public static final JhoveMessage PDF_HUL_99 = messageFactory.getMessage("PDF-HUL-99"); + public static final JhoveMessage PDF_HUL_100 = messageFactory.getMessage("PDF-HUL-100"); + public static final JhoveMessage PDF_HUL_101 = messageFactory.getMessage("PDF-HUL-101"); + public static final JhoveMessage PDF_HUL_102 = messageFactory.getMessage("PDF-HUL-102"); + public static final JhoveMessage PDF_HUL_103 = messageFactory.getMessage("PDF-HUL-103"); + public static final JhoveMessage PDF_HUL_104 = messageFactory.getMessage("PDF-HUL-104"); + public static final JhoveMessage PDF_HUL_105 = messageFactory.getMessage("PDF-HUL-105"); + public static final JhoveMessage PDF_HUL_106 = messageFactory.getMessage("PDF-HUL-106"); + public static final JhoveMessage PDF_HUL_107 = messageFactory.getMessage("PDF-HUL-107"); + public static final JhoveMessage PDF_HUL_108 = messageFactory.getMessage("PDF-HUL-108"); + public static final JhoveMessage PDF_HUL_109 = messageFactory.getMessage("PDF-HUL-109"); + public static final JhoveMessage PDF_HUL_110 = messageFactory.getMessage("PDF-HUL-110"); + public static final JhoveMessage PDF_HUL_111 = messageFactory.getMessage("PDF-HUL-111"); + public static final JhoveMessage PDF_HUL_112 = messageFactory.getMessage("PDF-HUL-112"); + public static final JhoveMessage PDF_HUL_113 = messageFactory.getMessage("PDF-HUL-113"); + public static final JhoveMessage PDF_HUL_114 = messageFactory.getMessage("PDF-HUL-114"); + public static final JhoveMessage PDF_HUL_115 = messageFactory.getMessage("PDF-HUL-115"); + public static final JhoveMessage PDF_HUL_116 = messageFactory.getMessage("PDF-HUL-116"); + public static final JhoveMessage PDF_HUL_117 = messageFactory.getMessage("PDF-HUL-117"); + public static final JhoveMessage PDF_HUL_118 = messageFactory.getMessage("PDF-HUL-118"); + public static final JhoveMessage PDF_HUL_119 = messageFactory.getMessage("PDF-HUL-119"); + public static final JhoveMessage PDF_HUL_120 = messageFactory.getMessage("PDF-HUL-120"); + public static final JhoveMessage PDF_HUL_121 = messageFactory.getMessage("PDF-HUL-121"); + public static final JhoveMessage PDF_HUL_122 = messageFactory.getMessage("PDF-HUL-122"); + public static final JhoveMessage PDF_HUL_123 = messageFactory.getMessage("PDF-HUL-123"); + public static final JhoveMessage PDF_HUL_124 = messageFactory.getMessage("PDF-HUL-124"); + public static final JhoveMessage PDF_HUL_125 = messageFactory.getMessage("PDF-HUL-125"); + public static final JhoveMessage PDF_HUL_126 = messageFactory.getMessage("PDF-HUL-126"); + public static final JhoveMessage PDF_HUL_127 = messageFactory.getMessage("PDF-HUL-127"); + public static final JhoveMessage PDF_HUL_128 = messageFactory.getMessage("PDF-HUL-128"); + public static final JhoveMessage PDF_HUL_129 = messageFactory.getMessage("PDF-HUL-129"); + public static final JhoveMessage PDF_HUL_130 = messageFactory.getMessage("PDF-HUL-130"); + public static final JhoveMessage PDF_HUL_131 = messageFactory.getMessage("PDF-HUL-131"); + public static final JhoveMessage PDF_HUL_132 = messageFactory.getMessage("PDF-HUL-132"); + public static final JhoveMessage PDF_HUL_133 = messageFactory.getMessage("PDF-HUL-133"); + public static final JhoveMessage PDF_HUL_134 = messageFactory.getMessage("PDF-HUL-134"); + public static final JhoveMessage PDF_HUL_135 = messageFactory.getMessage("PDF-HUL-135"); + public static final JhoveMessage PDF_HUL_136 = messageFactory.getMessage("PDF-HUL-136"); + public static final JhoveMessage PDF_HUL_136_SUB = messageFactory.getMessage("PDF-HUL-136-SUB"); + public static final JhoveMessage PDF_HUL_137 = messageFactory.getMessage("PDF-HUL-137"); + public static final JhoveMessage PDF_HUL_138 = messageFactory.getMessage("PDF-HUL-138"); + public static final JhoveMessage PDF_HUL_139 = messageFactory.getMessage("PDF-HUL-139"); + public static final JhoveMessage PDF_HUL_140 = messageFactory.getMessage("PDF-HUL-140"); + public static final JhoveMessage PDF_HUL_141 = messageFactory.getMessage("PDF-HUL-141"); + public static final JhoveMessage PDF_HUL_142 = messageFactory.getMessage("PDF-HUL-142"); + public static final JhoveMessage PDF_HUL_143 = messageFactory.getMessage("PDF-HUL-143"); + public static final JhoveMessage PDF_HUL_144 = messageFactory.getMessage("PDF-HUL-144"); + public static final JhoveMessage PDF_HUL_145 = messageFactory.getMessage("PDF-HUL-145"); + public static final JhoveMessage PDF_HUL_146 = messageFactory.getMessage("PDF-HUL-146"); + public static final JhoveMessage PDF_HUL_147 = messageFactory.getMessage("PDF-HUL-147"); + public static final JhoveMessage PDF_HUL_148 = messageFactory.getMessage("PDF-HUL-148"); + public static final JhoveMessage PDF_HUL_149 = messageFactory.getMessage("PDF-HUL-149"); + public static final JhoveMessage PDF_HUL_150 = messageFactory.getMessage("PDF-HUL-150"); public static final JhoveMessage PDF_HUL_151 = messageFactory.getMessage("PDF-HUL-151"); - public static final JhoveMessage PDF_HUL_152 = messageFactory.getMessage("PDF-HUL-152"); - public static final JhoveMessage PDF_HUL_153 = messageFactory.getMessage("PDF-HUL-153"); - public static final JhoveMessage PDF_HUL_154 = messageFactory.getMessage("PDF-HUL-154"); - public static final JhoveMessage PDF_HUL_155 = messageFactory.getMessage("PDF-HUL-155"); - public static final JhoveMessage PDF_HUL_156 = messageFactory.getMessage("PDF-HUL-156"); + public static final JhoveMessage PDF_HUL_152 = messageFactory.getMessage("PDF-HUL-152"); + public static final JhoveMessage PDF_HUL_153 = messageFactory.getMessage("PDF-HUL-153"); + public static final JhoveMessage PDF_HUL_154 = messageFactory.getMessage("PDF-HUL-154"); + public static final JhoveMessage PDF_HUL_155 = messageFactory.getMessage("PDF-HUL-155"); + public static final JhoveMessage PDF_HUL_156 = messageFactory.getMessage("PDF-HUL-156"); public static final JhoveMessage PDF_HUL_157 = messageFactory.getMessage("PDF-HUL-157"); public static final JhoveMessage PDF_HUL_158 = messageFactory.getMessage("PDF-HUL-158"); - public static final JhoveMessage PDF_HUL_159 = messageFactory.getMessage("PDF-HUL-159"); + public static final JhoveMessage PDF_HUL_159 = messageFactory.getMessage("PDF-HUL-159"); + public static final JhoveMessage PDF_HUL_160 = messageFactory.getMessage("PDF-HUL-160"); + public static final JhoveMessage PDF_HUL_161 = messageFactory.getMessage("PDF-HUL-161"); + public static final JhoveMessage PDF_HUL_162 = messageFactory.getMessage("PDF-HUL-162"); - /** - * Logger Messages - */ - public static final String LOG_HINT_ARRY_CHK = "Checking hint array"; - public static final String LOG_IMAGE_XOBJ = "Image XObject"; - public static final String LOG_IMAGE_GET = "Getting image"; - public static final String LOG_K_ELEM_IS_ARRY = "Type K element is an array"; - public static final String LOG_K_ELEM_IS_DICT = "Type K element is dictionary"; - public static final String LOG_LIN_PROF_CHK = "Checking Linearized Profile"; - public static final String LOG_NAMES_DICT_EXCEP = "Exception on names dictionary: "; - public static final String LOG_NO_CHILD_STRUCT_ELEM = "No children are structure elements"; - public static final String LOG_NO_CHILD_OBJS = "No child objects, exiting"; - public static final String LOG_REVISION_NUM_RETRIEVAL_EXCEP = "Exception getting revision number: "; - public static final String LOG_SUBTREE_BUILDING = "Building subtree"; - public static final String LOG_XREF_TABLE_VERIFYING = "Verifying cross-reference table"; + /** + * Logger Messages + */ + public static final String LOG_HINT_ARRY_CHK = "Checking hint array"; + public static final String LOG_IMAGE_XOBJ = "Image XObject"; + public static final String LOG_IMAGE_GET = "Getting image"; + public static final String LOG_K_ELEM_IS_ARRY = "Type K element is an array"; + public static final String LOG_K_ELEM_IS_DICT = "Type K element is dictionary"; + public static final String LOG_LIN_PROF_CHK = "Checking Linearized Profile"; + public static final String LOG_NAMES_DICT_EXCEP = "Exception on names dictionary: "; + public static final String LOG_NO_CHILD_STRUCT_ELEM = "No children are structure elements"; + public static final String LOG_NO_CHILD_OBJS = "No child objects, exiting"; + public static final String LOG_REVISION_NUM_RETRIEVAL_EXCEP = "Exception getting revision number: "; + public static final String LOG_SUBTREE_BUILDING = "Building subtree"; + public static final String LOG_XREF_TABLE_VERIFYING = "Verifying cross-reference table"; } diff --git a/jhove-modules/pdf-hul/src/main/java/edu/harvard/hul/ois/jhove/module/pdf/Parser.java b/jhove-modules/pdf-hul/src/main/java/edu/harvard/hul/ois/jhove/module/pdf/Parser.java index 6c6dd89d2..1fa1ec5af 100644 --- a/jhove-modules/pdf-hul/src/main/java/edu/harvard/hul/ois/jhove/module/pdf/Parser.java +++ b/jhove-modules/pdf-hul/src/main/java/edu/harvard/hul/ois/jhove/module/pdf/Parser.java @@ -100,7 +100,7 @@ public Token getNext (long max) throws IOException, PdfException else if (tok instanceof DictionaryEnd) { --_dictDepth; if (_dictDepth < 0) { - throw new PdfMalformedException (MessageConstants.PDF_HUL_33); // PDF-HUL-33 + throw new PdfMalformedException(MessageConstants.PDF_HUL_33, getOffset()); // PDF-HUL-33 } } if (tok instanceof ArrayStart) { @@ -109,7 +109,7 @@ else if (tok instanceof DictionaryEnd) { else if (tok instanceof ArrayEnd) { --_arrayDepth; if (_arrayDepth < 0) { - throw new PdfMalformedException (MessageConstants.PDF_HUL_34); // PDF-HUL-34 + throw new PdfMalformedException(MessageConstants.PDF_HUL_34, getOffset()); // PDF-HUL-34 } } return tok; @@ -126,7 +126,7 @@ public Token getNext (Class clas, JhoveMessage errMsg) { Token tok = getNext (); if (!clas.isInstance (tok)) { - throw new PdfInvalidException (errMsg); + throw new PdfInvalidException(errMsg, getOffset()); } if (!tok.isPdfACompliant()) { _pdfACompliant = false; @@ -216,7 +216,7 @@ public PdfObject readObjectDef (Numeric objNumTok) Numeric genNumTok = (Numeric) getNext (Numeric.class, MessageConstants.PDF_HUL_36); // PDF-HUL-36 Keyword objKey = (Keyword) getNext (Keyword.class, MessageConstants.PDF_HUL_37); // PDF-HUL-37 if (!"obj".equals (objKey.getValue ())) { - throw new PdfMalformedException (MessageConstants.PDF_HUL_38); // PDF-HUL-38 + throw new PdfMalformedException(MessageConstants.PDF_HUL_38, getOffset()); // PDF-HUL-38 } if (_tokenizer.getWSString ().length () > 1) { _pdfACompliant = false; @@ -360,7 +360,7 @@ else if (obj instanceof PdfDictionaryEnd) { if ((vecSize % 2) != 0) { String mess = MessageFormat.format(MessageConstants.PDF_HUL_41.getMessage(), Integer.valueOf(vecSize)); JhoveMessage message = JhoveMessages.getMessageInstance(MessageConstants.PDF_HUL_41.getId(), mess); - throw new PdfMalformedException(message, getOffset ()); // PDF-HUL-41 + throw new PdfMalformedException(message, getOffset()); // PDF-HUL-41 } for (int i = 0; i < vecSize; i += 2) { try { @@ -370,7 +370,7 @@ else if (obj instanceof PdfDictionaryEnd) { dict.add (key.getValue (), value); } catch (Exception f) { - throw new PdfMalformedException (MessageConstants.PDF_HUL_42, getOffset ()); // PDF-HUL-42 + throw new PdfMalformedException (MessageConstants.PDF_HUL_42, getOffset()); // PDF-HUL-42 } } if (!dict.isPdfACompliant()) { @@ -430,8 +430,6 @@ private void collapseObjectVector (Vector v) throws PdfException int genNum = ntok.getIntegerValue (); v.set (i - 2, new PdfIndirectObj (objNum, genNum, _objectMap)); - //v.removeElementAt (i); - //v.removeElementAt (i - 1); // Put in null as placeholder, to be removed below v.set(i, null); v.set(i - 1, null); @@ -440,7 +438,7 @@ private void collapseObjectVector (Vector v) throws PdfException } catch (Exception e) { throw new PdfMalformedException - (MessageConstants.PDF_HUL_44); // PDF-HUL-44 + (MessageConstants.PDF_HUL_44, getOffset()); // PDF-HUL-44 } } } diff --git a/jhove-modules/pdf-hul/src/main/java/edu/harvard/hul/ois/jhove/module/pdf/PdfHeader.java b/jhove-modules/pdf-hul/src/main/java/edu/harvard/hul/ois/jhove/module/pdf/PdfHeader.java index 34a640abd..dc00026ca 100644 --- a/jhove-modules/pdf-hul/src/main/java/edu/harvard/hul/ois/jhove/module/pdf/PdfHeader.java +++ b/jhove-modules/pdf-hul/src/main/java/edu/harvard/hul/ois/jhove/module/pdf/PdfHeader.java @@ -2,7 +2,7 @@ import java.io.IOException; -import edu.harvard.hul.ois.jhove.ErrorMessage; +import edu.harvard.hul.ois.jhove.messages.JhoveMessages; /** * Simple class that is the a prototype of a proper header parser class. The aim @@ -16,183 +16,141 @@ */ public final class PdfHeader { - public static final String PDF_VER1_HEADER_PREFIX = "PDF-1."; //$NON-NLS-1$ - public static final String PDF_SIG_HEADER = "%" + PDF_VER1_HEADER_PREFIX; //$NON-NLS-1$ - public static final String POSTSCRIPT_HEADER_PREFIX = "!PS-Adobe-"; //$NON-NLS-1$ - public static final int MAX_VALID_MAJOR_VERSION = 7; - - private final String versionString; - private final boolean isPdfACompilant; - - /** - * - */ - private PdfHeader(final String versionString, - final boolean isPdfaCompliant) { - this.versionString = versionString; - this.isPdfACompilant = isPdfaCompliant; - } - - /** - * @return the version string parsed from the PDF Header - */ - public String getVersionString() { - return this.versionString; - } - - /** - * @return true if the header is considered PDF/A compliant, otherwise false - */ - public boolean isPdfACompliant() { - return this.isPdfACompilant; - } - - /** - * Performs a very simple version number validity check. Given version - * number is a String of form 1.x, x is the minor version number. This - * method parses the minor version number from the version String and tests - * whether it is less than or equal to - * {@link PdfHeader#MAX_VALID_MAJOR_VERSION}. - * - * @return true if an integer minor version number can be parsed from the - * version string AND it is less than or equal to - * {@link PdfHeader#MAX_VALID_MAJOR_VERSION}. Otherwise false. - */ - public boolean isVersionValid() { - // Set minor version to one larger than maximum so invalid if parse - // fails - int minorVersion = MAX_VALID_MAJOR_VERSION + 1; - try { - minorVersion = getMinorVersion(this.versionString); - } catch (NumberFormatException nfe) { - // TODO : This currently catches non-numbers and - // returns false. This marks the version number - // as invalid and ensured existing JHOVE behaviour - // changed as little as possible for v1.20 March 2018. - // Really this should be thrown as it's own validation - // exception and be assigned its own message - // Version numbers need better handling as PDF1. is - // baked into JHOVE's header signature rather than - // as part of version parsing and validation. - // The arrival of PDF 2.0 in summer 2017 leaves - // this looking very dubious behaviour. - } - return minorVersion <= MAX_VALID_MAJOR_VERSION; - } - - /** - * Creates a new {@link PdfHeader} instance using the passed parameters. - * - * @param versionString - * the version number from the PDF Header, should be of form - * 1.x where x should be of the range 0-7. - * @param isPdfaCompliant - * boolean flag indicating if the PDF/A is compliant or non - * compliant with JHOVE's PDF/A profile. - * @return a {@link PdfHeader} instance initialised using - * versionString and isPdfaCompliant. - * @throws NullPointerException - * when parameter versionString is null. - */ - static PdfHeader fromValues(final String versionString, - final boolean isPdfaCompliant) { - if (versionString == null) - throw new NullPointerException( - "Parameter versionString can not be null."); - return new PdfHeader(versionString, isPdfaCompliant); - } - - /** - * Factory method for {@link PdfHeader} that parses a new instance using the - * supplied {@link Parser} instance. - * - * @param parser - * the {@link Parser} instance that will be used to parse header - * details - * @return a new {@link PdfHeader} instance derived using the supplied - * {@link Parser} or null when no header could be found - * and parsed. - * @throws PdfMalformedException - */ - public static PdfHeader parseHeader(final Parser parser) throws PdfMalformedException { - Token token = null; - String value = null; - boolean isPdfACompliant = false; - String version = null; - - /* Parse file header. */ - for (;;) { - if (parser.getOffset() > 1024) { - return null; - } - try { - token = null; - token = parser.getNext(1024L); - } catch (IOException ee) { - return null; - } catch (Exception e) { - // fall through - } - - if (token == null) { - return null; - } - if (token instanceof Comment) { - value = ((Comment) token).getValue(); - if (value.indexOf(PDF_VER1_HEADER_PREFIX) == 0) { - try { - version = value.substring(4, 7); - } catch (IndexOutOfBoundsException e ){ - throw new PdfMalformedException(MessageConstants.PDF_HUL_155); // PDF-HUL-155 - } - isPdfACompliant = true; - break; - } - // The implementation notes (though not the spec) - // allow an alternative signature of %!PS-Adobe-N.n PDF-M.m - if (value.indexOf(POSTSCRIPT_HEADER_PREFIX) == 0) { - // But be careful: that much by itself is the standard - // PostScript signature. - int n = value.indexOf(PDF_VER1_HEADER_PREFIX); - if (n >= 11) { - version = value.substring(n + 4); - break; - } - } - } - } - - if (version == null) { - return null; - } - - try { - isPdfACompliant = isTokenPdfACompliant(parser.getNext()); - } catch (Exception excep) { - // Most likely a ClassCastException on a non-comment - isPdfACompliant = false; - } - // Check for PDF/A conformance. The next item must be - // a comment with four characters, each greater than 127 - return new PdfHeader(version, isPdfACompliant); - } - - private static int getMinorVersion(final String version) { - double doubleVer = Double.parseDouble(version); - double fractPart = doubleVer % 1; - int minor = (int) (10L * fractPart); - return minor; - } - - private static boolean isTokenPdfACompliant(final Token token) { - String cmt = ((Comment) token).getValue(); - char[] cmtArray = cmt.toCharArray(); - int ctlcnt = 0; - for (int i = 0; i < 4; i++) { - if (cmtArray[i] > 127) { - ctlcnt++; - } - } - return (ctlcnt > 3); - } + public static final String PDF_HEADER_PREFIX = "PDF-"; //$NON-NLS-1$ + public static final String PDF_VER1_HEADER_PREFIX = PDF_HEADER_PREFIX + "1."; //$NON-NLS-1$ + public static final String PDF_VER2_HEADER_PREFIX = PDF_HEADER_PREFIX + "2."; //$NON-NLS-1$ + public static final String PDF_1_SIG_HEADER = "%" + PDF_VER1_HEADER_PREFIX; //$NON-NLS-1$ + public static final String PDF_2_SIG_HEADER = "%" + PDF_VER2_HEADER_PREFIX; //$NON-NLS-1$ + public static final String POSTSCRIPT_HEADER_PREFIX = "!PS-Adobe-"; //$NON-NLS-1$ + + public static final int MAX_VALID_MAJOR_VERSION = 2; + + private final PdfVersion version; + private final boolean isPdfACompilant; + + /** + * Factory method for {@link PdfHeader} that parses a new instance using the + * supplied {@link Parser} instance. + * + * @param parser + * the {@link Parser} instance that will be used to parse header + * details + * @return a new {@link PdfHeader} instance derived using the supplied + * {@link Parser} or null when no header could be found + * and parsed. + * @throws PdfException + */ + public static PdfHeader parseHeader(final Parser parser) throws PdfException { + Token token = null; + String value = null; + boolean isPdfACompliant = false; + PdfVersion version = null; + + /* Parse file header. */ + for (;;) { + final long offset = parser.getOffset(); + if (offset > 1024) { + throw new PdfMalformedException( + JhoveMessages.getMessageInstance(MessageConstants.PDF_HUL_137, + "Header not found in first 1024 bytes"), + offset); // PDF-HUL-137 + } + + try { + token = parser.getNext(1024L); + } catch (final IOException ee) { + throw new PdfMalformedException( + JhoveMessages.getMessageInstance(MessageConstants.PDF_HUL_160, ee.getMessage()), + offset); // PDF-HUL-137 + } catch (PdfException e) { + throw new PdfMalformedException( + MessageConstants.PDF_HUL_137, + offset); // PDF-HUL-137 + } + + if (token == null) { + throw new PdfMalformedException( + JhoveMessages.getMessageInstance(MessageConstants.PDF_HUL_137, "Header not found"), + offset); // PDF-HUL-137 + } + + if (token instanceof Comment) { + value = ((Comment) token).getValue(); + if ((value.indexOf(PDF_HEADER_PREFIX) == 0) || (value.indexOf(POSTSCRIPT_HEADER_PREFIX) == 0)) { + version = PdfVersion.fromHeaderLine(value, offset); + break; + } + } + } + + try { + isPdfACompliant = isTokenPdfACompliant(parser.getNext()); + } catch (final Exception excep) { + // Most likely a ClassCastException on a non-comment + isPdfACompliant = false; + } + // Check for PDF/A conformance. The next item must be + // a comment with four characters, each greater than 127 + return new PdfHeader(version, isPdfACompliant); + } + + /** + * Creates a new {@link PdfHeader} instance using the passed parameters. + * + * @param versionString + * the version number from the PDF Header, should be of + * form + * 1.x where x should be of the range 0-7. + * @param isPdfaCompliant + * boolean flag indicating if the PDF/A is compliant or + * non + * compliant with JHOVE's PDF/A profile. + * @return a {@link PdfHeader} instance initialised using + * versionString and isPdfaCompliant. + * @throws NullPointerException + * when parameter versionString is + * null. + */ + static PdfHeader fromValues(final PdfVersion version, + final boolean isPdfaCompliant) { + if (version == null) + throw new NullPointerException( + "Parameter version can not be null."); + return new PdfHeader(version, isPdfaCompliant); + } + + private static boolean isTokenPdfACompliant(final Token token) { + final String cmt = ((Comment) token).getValue(); + final char[] cmtArray = cmt.toCharArray(); + int ctlcnt = 0; + for (int i = 0; i < 4; i++) { + if (cmtArray[i] > 127) { + ctlcnt++; + } + } + return (ctlcnt > 3); + } + + /** + * + */ + private PdfHeader(final PdfVersion version, + final boolean isPdfaCompliant) { + this.version = version; + this.isPdfACompilant = isPdfaCompliant; + } + + /** + * @return the version string parsed from the PDF Header + */ + public String getVersionString() { + return this.version.toString(); + } + + /** + * @return true if the header is considered PDF/A compliant, otherwise false + */ + public boolean isPdfACompliant() { + return this.isPdfACompilant; + } } diff --git a/jhove-modules/pdf-hul/src/main/java/edu/harvard/hul/ois/jhove/module/pdf/PdfVersion.java b/jhove-modules/pdf-hul/src/main/java/edu/harvard/hul/ois/jhove/module/pdf/PdfVersion.java new file mode 100644 index 000000000..a4b4faceb --- /dev/null +++ b/jhove-modules/pdf-hul/src/main/java/edu/harvard/hul/ois/jhove/module/pdf/PdfVersion.java @@ -0,0 +1,115 @@ +package edu.harvard.hul.ois.jhove.module.pdf; + +import java.text.MessageFormat; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import edu.harvard.hul.ois.jhove.messages.JhoveMessages; + +final class PdfVersion { + final PdfVersion.PdfMajorVersions majorVersion; + final int minorVersion; + + enum PdfMajorVersions { + PDF_2(2, 0, 0), + PDF_1(1, 0, 7); + + final int version; + final int maxMinorVersion; + final int minMinorVersion; + + static final String getMajorVersionRange() { + return String.format("[%d-%d]", PDF_1.version, PDF_2.version); + } + + static final PdfVersion.PdfMajorVersions fromMajorVersion(final int majorVersion) throws PdfInvalidException { + for (final PdfVersion.PdfMajorVersions version : PdfMajorVersions.values()) { + if (version.version == majorVersion) { + return version; + } + } + throw new PdfInvalidException(JhoveMessages.getMessageInstance(MessageConstants.PDF_HUL_161, + String.format("PDF major version must be in the range %s, major version number: %d detected", + getMajorVersionRange(), majorVersion))); + } + + private PdfMajorVersions(final int version, final int minMinorVersion, final int maxMinorVersion) { + this.version = version; + this.minMinorVersion = minMinorVersion; + this.maxMinorVersion = maxMinorVersion; + } + + final String getMinorVersionRange() { + return String.format("%d.[%d-%d]", this.version, this.minMinorVersion, this.maxMinorVersion); + } + + final boolean isMinorValid(final int minorVersion) { + return minorVersion >= this.minMinorVersion && minorVersion <= this.maxMinorVersion; + } + } + + static final Pattern versionPattern = Pattern.compile("(\\d)\\.(\\d)"); + + static final PdfVersion fromVersionString(final String version) throws PdfInvalidException { + final Matcher matcher = versionPattern.matcher(version); + try { + if (matcher.find()) { + final PdfVersion.PdfMajorVersions majorVersion = PdfVersion.PdfMajorVersions + .fromMajorVersion(Integer.parseInt(matcher.group(1))); + final int minorVersion = Integer.parseInt(matcher.group(2)); + checkMinorVersion(majorVersion, minorVersion); + return new PdfVersion(majorVersion, minorVersion); + } + } catch (final NumberFormatException nfe) { + /** + * Fall throuh to throw the below, same as if the regex didn't match + */ + } + throw new PdfInvalidException( + JhoveMessages.getMessageInstance(MessageConstants.PDF_HUL_162, "Invalid: " + version)); + } + + static final void checkMinorVersion(final PdfVersion.PdfMajorVersions majorVersion, final int minorVersion) + throws PdfInvalidException { + if (!majorVersion.isMinorValid(minorVersion)) { + throw new PdfInvalidException(JhoveMessages.getMessageInstance(MessageConstants.PDF_HUL_148, + String.format("PDF %d has legal minor version range: %s, minor version number %d detected", + majorVersion.version, majorVersion.getMinorVersionRange(), minorVersion))); + } + } + + static final PdfVersion fromHeaderLine(final String headerLine, final long offset) + throws PdfMalformedException, PdfInvalidException { + String version = headerLine; + if ((headerLine.indexOf(PdfHeader.POSTSCRIPT_HEADER_PREFIX) == 0) + && headerLine.indexOf(PdfHeader.PDF_HEADER_PREFIX) >= PdfHeader.POSTSCRIPT_HEADER_PREFIX.length()) { + version = headerLine.substring(headerLine.indexOf(PdfHeader.PDF_HEADER_PREFIX)); + } + if (version.indexOf(PdfHeader.PDF_HEADER_PREFIX) == 0) { + version = parseSubstring(headerLine, 4, 7, offset); + } + return fromVersionString(version); + } + + static final String parseSubstring(final String toParse, final int begin, final int end, final long offset) + throws PdfMalformedException { + try { + return toParse.substring(begin, end); + } catch (final IndexOutOfBoundsException e) { + throw new PdfMalformedException( + JhoveMessages.getMessageInstance(MessageConstants.PDF_HUL_155.getId(), + MessageFormat.format(MessageConstants.PDF_HUL_155.getMessage(), toParse)), + offset); // PDF-HUL-155 + } + } + + private PdfVersion(final PdfVersion.PdfMajorVersions majorVersion, final int minorVersion) { + this.majorVersion = majorVersion; + this.minorVersion = minorVersion; + } + + @Override + public String toString() { + return String.format("%d.%d", this.majorVersion.version, this.minorVersion); + } +} \ No newline at end of file diff --git a/jhove-modules/pdf-hul/src/main/resources/edu/harvard/hul/ois/jhove/module/pdf/ErrorMessages.properties b/jhove-modules/pdf-hul/src/main/resources/edu/harvard/hul/ois/jhove/module/pdf/ErrorMessages.properties index 71544d09d..771258307 100644 --- a/jhove-modules/pdf-hul/src/main/resources/edu/harvard/hul/ois/jhove/module/pdf/ErrorMessages.properties +++ b/jhove-modules/pdf-hul/src/main/resources/edu/harvard/hul/ois/jhove/module/pdf/ErrorMessages.properties @@ -138,7 +138,7 @@ PDF-HUL-131 = Invalid outline dictionary item PDF-HUL-133 = Improperly formed date PDF-HUL-134 = Cross-reference tables are broken PDF-HUL-135 = Unexpected error in parsing font property -PDF-HUL-137 = No PDF header +PDF-HUL-137 = No PDF header found PDF-HUL-138 = No PDF trailer PDF-HUL-139 = Missing startxref keyword or value PDF-HUL-140 = Document catalog dictionary object number and trailer root ref number are inconsistent. @@ -149,15 +149,18 @@ PDF-HUL-144 = Pages dictionary has no Type key or it has a null value. PDF-HUL-145 = Pages dictionary Type key does not have a simple String value. PDF-HUL-146 = Pages dictionary Type key must have value /Pages. PDF-HUL-147 = Page tree node not found. -PDF-HUL-148 = PDF minor version number is greater than 7. +PDF-HUL-148 = PDF minor version number is out of valid range. PDF-HUL-149 = Invalid indirect destination - referenced object ''{0}'' cannot be found PDF-HUL-150 = Cross-reference stream must be a stream PDF-HUL-151 = Unexpected error occurred while attempting to read the cross-reference table PDF-HUL-152 = Encrypt dictionary has no OE key or it has a null value PDF-HUL-153 = Encrypt dictionary has no UE key or it has a null value PDF-HUL-154 = Unknown Developer Prefix: -PDF-HUL-155 = Error parsing mandatory version number from PDF header. +PDF-HUL-155 = Error parsing mandatory version number, PDF header too short: "{0}" PDF-HUL-156 = Extension can't be defined as an indirect reference PDF-HUL-157 = Unexpected exception {0} PDF-HUL-158 = Unexpected exception {0} -PDF-HUL-159 = Image height and width are manditory properties \ No newline at end of file +PDF-HUL-159 = Image height and width are manditory properties +PDF-HUL-160 = IO Exception reading PDF Header +PDF-HUL-161 = PDF major version number should be 1.x or 2.x +PDF-HUL-162 = Malformed PDF version number diff --git a/jhove-modules/pdf-hul/src/main/resources/edu/harvard/hul/ois/jhove/module/pdf/ErrorMessages_en.properties b/jhove-modules/pdf-hul/src/main/resources/edu/harvard/hul/ois/jhove/module/pdf/ErrorMessages_en.properties index 9858a72fd..771258307 100644 --- a/jhove-modules/pdf-hul/src/main/resources/edu/harvard/hul/ois/jhove/module/pdf/ErrorMessages_en.properties +++ b/jhove-modules/pdf-hul/src/main/resources/edu/harvard/hul/ois/jhove/module/pdf/ErrorMessages_en.properties @@ -138,7 +138,7 @@ PDF-HUL-131 = Invalid outline dictionary item PDF-HUL-133 = Improperly formed date PDF-HUL-134 = Cross-reference tables are broken PDF-HUL-135 = Unexpected error in parsing font property -PDF-HUL-137 = No PDF header +PDF-HUL-137 = No PDF header found PDF-HUL-138 = No PDF trailer PDF-HUL-139 = Missing startxref keyword or value PDF-HUL-140 = Document catalog dictionary object number and trailer root ref number are inconsistent. @@ -149,14 +149,18 @@ PDF-HUL-144 = Pages dictionary has no Type key or it has a null value. PDF-HUL-145 = Pages dictionary Type key does not have a simple String value. PDF-HUL-146 = Pages dictionary Type key must have value /Pages. PDF-HUL-147 = Page tree node not found. -PDF-HUL-148 = PDF minor version number is greater than 7. +PDF-HUL-148 = PDF minor version number is out of valid range. PDF-HUL-149 = Invalid indirect destination - referenced object ''{0}'' cannot be found PDF-HUL-150 = Cross-reference stream must be a stream PDF-HUL-151 = Unexpected error occurred while attempting to read the cross-reference table PDF-HUL-152 = Encrypt dictionary has no OE key or it has a null value PDF-HUL-153 = Encrypt dictionary has no UE key or it has a null value PDF-HUL-154 = Unknown Developer Prefix: -PDF-HUL-155 = Error parsing mandatory version number from PDF header. +PDF-HUL-155 = Error parsing mandatory version number, PDF header too short: "{0}" PDF-HUL-156 = Extension can't be defined as an indirect reference PDF-HUL-157 = Unexpected exception {0} PDF-HUL-158 = Unexpected exception {0} +PDF-HUL-159 = Image height and width are manditory properties +PDF-HUL-160 = IO Exception reading PDF Header +PDF-HUL-161 = PDF major version number should be 1.x or 2.x +PDF-HUL-162 = Malformed PDF version number diff --git a/jhove-modules/pdf-hul/src/test/java/edu/harvard/hul/ois/jhove/module/TestUtils.java b/jhove-modules/pdf-hul/src/test/java/edu/harvard/hul/ois/jhove/module/TestUtils.java index cacd6fabf..881e5f473 100644 --- a/jhove-modules/pdf-hul/src/test/java/edu/harvard/hul/ois/jhove/module/TestUtils.java +++ b/jhove-modules/pdf-hul/src/test/java/edu/harvard/hul/ois/jhove/module/TestUtils.java @@ -71,7 +71,7 @@ public static RepInfo testValidateResource(final Module module, * the expected well formed value * @param expctVld * the expected is valid value - * @param message + * @param messageId * a JHOVE validation string message expected to be found in the * list of validation messages. If this parameter is null the * test isn't performed. @@ -80,8 +80,8 @@ public static RepInfo testValidateResource(final Module module, */ public static RepInfo testValidateResource(final Module module, final String resToTest, final int expctWllFrmd, final int expctVld, - final String message) throws URISyntaxException { - return testValidateResource(module, resToTest, expctWllFrmd, expctVld, message, true); + final String messageId) throws URISyntaxException { + return testValidateResource(module, resToTest, expctWllFrmd, expctVld, messageId, true); } /** @@ -109,11 +109,11 @@ public static RepInfo testValidateResource(final Module module, */ public static RepInfo testValidateResource(final Module module, final String resToTest, final int expctWllFrmd, final int expctVld, - final String expctMessage, boolean messMustBePresent ) throws URISyntaxException { + final String expctMessageId, boolean messMustBePresent ) throws URISyntaxException { File toTest = new File(TestUtils.class.getResource(resToTest).toURI()); return testValidateFile(module, toTest, expctWllFrmd, expctVld, - expctMessage, messMustBePresent); + expctMessageId, messMustBePresent); } /** @@ -141,40 +141,40 @@ public static RepInfo testValidateFile(final Module module, public static RepInfo testValidateFile(final Module module, final File fileToTest, final int expctWllFrmd, final int expctVld, - final String message) { - return testValidateFile(module, fileToTest, expctWllFrmd, expctVld, message, true); + final String messageId) { + return testValidateFile(module, fileToTest, expctWllFrmd, expctVld, messageId, true); } public static RepInfo testValidateFile(final Module module, final File fileToTest, final int expctWllFrmd, final int expctVld, - final String message, boolean messMustBePresent) { + final String messageId, boolean messMustBePresent) { RepInfo info = parseTestFile(module, fileToTest); - testResult(info, expctWllFrmd, expctVld, message, messMustBePresent); + testResult(info, expctWllFrmd, expctVld, messageId, messMustBePresent); return info; } private static void testResult(final RepInfo info, final int expctWllFrmd, - final int expctVld, final String message, boolean messMustBePresent) { + final int expctVld, final String messageId, boolean messMustBePresent) { testWellFormed(info, expctWllFrmd); testIsValid(info, expctVld); - if (message == null) { + if (messageId == null) { return; } - Message jhoveMessage = getMessageIfPresent(info, message); + Message jhoveMessage = getMessageIfPresent(info, messageId); if (messMustBePresent) { if (jhoveMessage == null) { System.out.println(String.format( - "Expected message: %s, not found.", message)); + "Expected message ID: %s, not found.", messageId)); outputMessages(info); } - assertTrue("Expected message: " + message, jhoveMessage != null); + assertTrue("Expected message ID: " + messageId, jhoveMessage != null); } else { if (jhoveMessage != null) { System.out.println(String.format( - "Unexpected message: %s, found.", jhoveMessage.getMessage())); + "Unexpected message ID: %s, found.", jhoveMessage.getMessage())); outputMessages(info); } - assertTrue("Unexpected message: " + message, jhoveMessage == null); + assertTrue("Unexpected message ID: " + messageId, jhoveMessage == null); } } @@ -238,9 +238,9 @@ private static void testIsValid(final RepInfo info, final int expctVld) { assertEquals(message, expctVld, info.getValid()); } - private static Message getMessageIfPresent(final RepInfo info, final String expctMessage) { + private static Message getMessageIfPresent(final RepInfo info, final String expectedId) { for (Message message : info.getMessage()) { - if (message.getMessage().equals(expctMessage)) { + if (message.getId().equals(expectedId)) { return message; } } diff --git a/jhove-modules/pdf-hul/src/test/java/edu/harvard/hul/ois/jhove/module/pdf/DocCatTests.java b/jhove-modules/pdf-hul/src/test/java/edu/harvard/hul/ois/jhove/module/pdf/DocCatTests.java index 9339c74c3..6ace1a23d 100644 --- a/jhove-modules/pdf-hul/src/test/java/edu/harvard/hul/ois/jhove/module/pdf/DocCatTests.java +++ b/jhove-modules/pdf-hul/src/test/java/edu/harvard/hul/ois/jhove/module/pdf/DocCatTests.java @@ -17,123 +17,123 @@ */ public class DocCatTests { - private static final String pdfResourcePath = "/edu/harvard/hul/ois/jhove/module/pdf/"; - private static final String docCatResourcePath = pdfResourcePath + "doc-cat/"; - - private static final String minimalPdfPath = pdfResourcePath - + "T00_000_minimal-valid.pdf"; - private static final String oneByteMissingPath = pdfResourcePath - + "corruptionOneByteMissing.pdf"; - - private static final String catNoCat = docCatResourcePath - + "T02-01_001_document-catalog-No-document-catalog.pdf"; - private static final String catWrongObjNumberPath = docCatResourcePath - + "T02-01_002_document-catalog-wrong-object-number.pdf"; - private static final String catPagRefMissPath = docCatResourcePath - + "T02-01_003_document-catalog-indirecte-pages-reference-missing.pdf"; - private static final String catPageRefIncorrectPath = docCatResourcePath - + "T02-01_004_document-catalog-incorrect-pages-reference.pdf"; - private static final String catTypeKyMissPath = docCatResourcePath - + "T02-01_005_document-catalog-type-key-missing.pdf"; - private static final String catTypeValNotCatalogPath = docCatResourcePath - + "T02-01_006_document-catalog-wrong-type-key.pdf"; - private static final String catTypeKyValPairMissPath = docCatResourcePath - + "T02-01_007_document-catalog-type-key-value-pair-missing.pdf"; - - private PdfModule module; - - @Before - public void setUp() throws Exception { - this.module = new PdfModule(); - JhoveBase je = new JhoveBase(); - this.module.setBase(je); - } - - /** - * Test method for {@link PdfModule}. - */ - @Test - public final void testValidCatType() throws URISyntaxException { - TestUtils.testValidateResource(this.module, minimalPdfPath, - RepInfo.TRUE, RepInfo.TRUE, null); - } - - /** - * Test method for {@link PdfModule}. - */ - @Test - public final void testNoCat() throws URISyntaxException { - TestUtils.testValidateResource(this.module, catNoCat, RepInfo.FALSE, - RepInfo.FALSE, MessageConstants.PDF_HUL_85.getMessage()); - } - - /** - * Test method for {@link PdfModule}. - */ - @Test - public final void testCatWrongObjNum() throws URISyntaxException { - TestUtils.testValidateResource(this.module, catWrongObjNumberPath, - RepInfo.FALSE, RepInfo.FALSE, - MessageConstants.PDF_HUL_140.getMessage()); - } - - /** - * Test method for {@link PdfModule}. - */ - @Test - public final void testPagRefMiss() throws URISyntaxException { - TestUtils.testValidateResource(this.module, catPagRefMissPath, - RepInfo.FALSE, RepInfo.FALSE, - MessageConstants.PDF_HUL_35.getMessage()); - } - - /** - * Test method for {@link PdfModule}. - */ - @Test - public final void testPageRefIncorrect() throws URISyntaxException { - TestUtils.testValidateResource(this.module, catPageRefIncorrectPath, - RepInfo.FALSE, RepInfo.FALSE, - MessageConstants.PDF_HUL_96.getMessage()); - } - - /** - * Test method for {@link PdfModule}. - */ - @Test - public final void testCatTypeKeyMiss() throws URISyntaxException { - TestUtils.testValidateResource(this.module, catTypeKyMissPath, - RepInfo.FALSE, RepInfo.FALSE, - MessageConstants.PDF_HUL_85.getMessage()); - } - - /** - * Test method for {@link PdfModule}. - */ - @Test - public final void testCatTypeVal() throws URISyntaxException { - TestUtils.testValidateResource(this.module, catTypeValNotCatalogPath, - RepInfo.FALSE, RepInfo.FALSE, - MessageConstants.PDF_HUL_141.getMessage()); - } - - /** - * Test method for {@link PdfModule}. - */ - @Test - public final void testCatTypeKeyValMiss() throws URISyntaxException { - TestUtils.testValidateResource(this.module, catTypeKyValPairMissPath, - RepInfo.FALSE, RepInfo.FALSE, - MessageConstants.PDF_HUL_36.getMessage()); - } - - /** - * Test method for {@link PdfModule}. - */ - @Test - public final void testOneByteMiss() throws URISyntaxException { - TestUtils.testValidateResource(this.module, oneByteMissingPath, - RepInfo.FALSE, RepInfo.FALSE, - MessageConstants.PDF_HUL_140.getMessage()); - } + private static final String pdfResourcePath = "/edu/harvard/hul/ois/jhove/module/pdf/"; + private static final String docCatResourcePath = pdfResourcePath + "doc-cat/"; + + private static final String minimalPdfPath = pdfResourcePath + + "T00_000_minimal-valid.pdf"; + private static final String oneByteMissingPath = pdfResourcePath + + "corruptionOneByteMissing.pdf"; + + private static final String catNoCat = docCatResourcePath + + "T02-01_001_document-catalog-No-document-catalog.pdf"; + private static final String catWrongObjNumberPath = docCatResourcePath + + "T02-01_002_document-catalog-wrong-object-number.pdf"; + private static final String catPagRefMissPath = docCatResourcePath + + "T02-01_003_document-catalog-indirecte-pages-reference-missing.pdf"; + private static final String catPageRefIncorrectPath = docCatResourcePath + + "T02-01_004_document-catalog-incorrect-pages-reference.pdf"; + private static final String catTypeKyMissPath = docCatResourcePath + + "T02-01_005_document-catalog-type-key-missing.pdf"; + private static final String catTypeValNotCatalogPath = docCatResourcePath + + "T02-01_006_document-catalog-wrong-type-key.pdf"; + private static final String catTypeKyValPairMissPath = docCatResourcePath + + "T02-01_007_document-catalog-type-key-value-pair-missing.pdf"; + + private PdfModule module; + + @Before + public void setUp() throws Exception { + this.module = new PdfModule(); + JhoveBase je = new JhoveBase(); + this.module.setBase(je); + } + + /** + * Test method for {@link PdfModule}. + */ + @Test + public final void testValidCatType() throws URISyntaxException { + TestUtils.testValidateResource(this.module, minimalPdfPath, + RepInfo.TRUE, RepInfo.TRUE, null); + } + + /** + * Test method for {@link PdfModule}. + */ + @Test + public final void testNoCat() throws URISyntaxException { + TestUtils.testValidateResource(this.module, catNoCat, RepInfo.FALSE, + RepInfo.FALSE, MessageConstants.PDF_HUL_86.getId()); + } + + /** + * Test method for {@link PdfModule}. + */ + @Test + public final void testCatWrongObjNum() throws URISyntaxException { + TestUtils.testValidateResource(this.module, catWrongObjNumberPath, + RepInfo.FALSE, RepInfo.FALSE, + MessageConstants.PDF_HUL_140.getId()); + } + + /** + * Test method for {@link PdfModule}. + */ + @Test + public final void testPagRefMiss() throws URISyntaxException { + TestUtils.testValidateResource(this.module, catPagRefMissPath, + RepInfo.FALSE, RepInfo.FALSE, + MessageConstants.PDF_HUL_38.getId()); + } + + /** + * Test method for {@link PdfModule}. + */ + @Test + public final void testPageRefIncorrect() throws URISyntaxException { + TestUtils.testValidateResource(this.module, catPageRefIncorrectPath, + RepInfo.FALSE, RepInfo.FALSE, + MessageConstants.PDF_HUL_96.getId()); + } + + /** + * Test method for {@link PdfModule}. + */ + @Test + public final void testCatTypeKeyMiss() throws URISyntaxException { + TestUtils.testValidateResource(this.module, catTypeKyMissPath, + RepInfo.FALSE, RepInfo.FALSE, + MessageConstants.PDF_HUL_85.getId()); + } + + /** + * Test method for {@link PdfModule}. + */ + @Test + public final void testCatTypeVal() throws URISyntaxException { + TestUtils.testValidateResource(this.module, catTypeValNotCatalogPath, + RepInfo.FALSE, RepInfo.FALSE, + MessageConstants.PDF_HUL_141.getId()); + } + + /** + * Test method for {@link PdfModule}. + */ + @Test + public final void testCatTypeKeyValMiss() throws URISyntaxException { + TestUtils.testValidateResource(this.module, catTypeKyValPairMissPath, + RepInfo.FALSE, RepInfo.FALSE, + MessageConstants.PDF_HUL_38.getId()); + } + + /** + * Test method for {@link PdfModule}. + */ + @Test + public final void testOneByteMiss() throws URISyntaxException { + TestUtils.testValidateResource(this.module, oneByteMissingPath, + RepInfo.FALSE, RepInfo.FALSE, + MessageConstants.PDF_HUL_140.getId()); + } } diff --git a/jhove-modules/pdf-hul/src/test/java/edu/harvard/hul/ois/jhove/module/pdf/HeaderTests.java b/jhove-modules/pdf-hul/src/test/java/edu/harvard/hul/ois/jhove/module/pdf/HeaderTests.java index 8c33f6f1d..4d7da74fb 100644 --- a/jhove-modules/pdf-hul/src/test/java/edu/harvard/hul/ois/jhove/module/pdf/HeaderTests.java +++ b/jhove-modules/pdf-hul/src/test/java/edu/harvard/hul/ois/jhove/module/pdf/HeaderTests.java @@ -20,121 +20,121 @@ */ public class HeaderTests { - private static final String pdfResourcePath = "/edu/harvard/hul/ois/jhove/module/pdf/"; - private static final String headerResourcePath = pdfResourcePath + "header/"; - private static final String minimalPdfPath = pdfResourcePath - + "T00_000_minimal-valid.pdf"; - - private static final String invalidMajorPath = headerResourcePath - + "T01_001_header-invalid-major-version.pdf"; - private static final String invalidMinorPath = headerResourcePath - + "T01_002_header-invalid-minor-version.pdf"; - private static final String noMinorPath = headerResourcePath - + "T01_003_header-no-minor-version.pdf"; - private static final String noHeaderDashPath = headerResourcePath - + "T01_004_header_invalid-syntax-no-dash.pdf"; - private static final String invalidSyntaxRepPath = headerResourcePath - + "T01_005_header-invalid-syntax-replace-char.pdf"; - private static final String invalidSyntaxNoPdfPath = headerResourcePath - + "T01_006_header-invalid-syntax-no-pdf.pdf"; - private static final String noVersionInfoPath = headerResourcePath - + "T01_007_header-no-version-info.pdf"; - - private PdfModule module; - - @Before - public void setUp() throws Exception { - this.module = new PdfModule(); - JhoveBase je = new JhoveBase(); - this.module.setBase(je); - } - - /** - * Test method for {@link PdfHeader}. - * Ensures that a valid PDF passes. - */ - @Test - public final void testMinorVersion() throws URISyntaxException { - TestUtils.testValidateResource(this.module, minimalPdfPath, - RepInfo.TRUE, RepInfo.TRUE); - } - - /** - * Test method for {@link PdfModule}. - * Ensures that a file with a major version > 1 (%PDF-2.4) is not well-formed. - * TODO: This currently makes all PDF 2.0 files invalid. - */ - @Test - public final void testInvalidMajorVersion() throws URISyntaxException { - TestUtils.testValidateResource(this.module, invalidMajorPath, - RepInfo.FALSE, RepInfo.FALSE, - MessageConstants.PDF_HUL_137.getMessage()); - } - - /** - * Test method for {@link PdfHeader}. - * Ensures that a file with a minor version > 7 (%PDF-1.9) is invalid. - */ - @Test - public final void testInvalidMinorVersion() throws URISyntaxException { - TestUtils.testValidateResource(this.module, invalidMinorPath, - RepInfo.TRUE, RepInfo.FALSE, - MessageConstants.PDF_HUL_148.getMessage()); - } - - /** - * Test method for {@link PdfHeader#getVersionString()}. - * Ensures that a file missing a minor version (%PDF-14) is not well-formed. - */ - @Test - public final void testNoMinor() throws URISyntaxException { - TestUtils.testValidateResource(this.module, noMinorPath, - RepInfo.FALSE, RepInfo.FALSE, - MessageConstants.PDF_HUL_137.getMessage()); - } - - /** - * Test method for {@link PdfModule}. - * Ensures that a file with no dash in header (%PDF1.4) is invalid. - */ - @Test - public final void testNoheaderDash() throws URISyntaxException { - TestUtils.testValidateResource(this.module, noHeaderDashPath, - RepInfo.FALSE, RepInfo.FALSE, - MessageConstants.PDF_HUL_137.getMessage()); - } - - /** - * Test method for {@link PdfModule}. - * Ensures that a file with no dash replaced by period in - * header (%PDF.1.4) is not well-formed. - */ - @Test - public final void testInvalidSyntaxRep() throws URISyntaxException { - TestUtils.testValidateResource(this.module, invalidSyntaxRepPath, - RepInfo.FALSE, RepInfo.FALSE, - MessageConstants.PDF_HUL_137.getMessage()); - } - - /** - * Test method for {@link PdfModule}. - * Ensures that a file with no PDF in header (%1.4) is not well-formed. - */ - @Test - public final void testInvalidSyntaxNoPdf() throws URISyntaxException { - TestUtils.testValidateResource(this.module, invalidSyntaxNoPdfPath, - RepInfo.FALSE, RepInfo.FALSE, - MessageConstants.PDF_HUL_137.getMessage()); - } - - /** - * Test method for {@link PdfModule}. - * Ensures that a file missing a header is not well-formed. - */ - @Test - public final void testNoVersionInfo() throws URISyntaxException { - TestUtils.testValidateResource(this.module, noVersionInfoPath, - RepInfo.FALSE, RepInfo.FALSE, - MessageConstants.PDF_HUL_137.getMessage()); - } + private static final String pdfResourcePath = "/edu/harvard/hul/ois/jhove/module/pdf/"; + private static final String headerResourcePath = pdfResourcePath + "header/"; + private static final String minimalPdfPath = pdfResourcePath + + "T00_000_minimal-valid.pdf"; + + private static final String invalidMajorPath = headerResourcePath + + "T01_001_header-invalid-major-version.pdf"; + private static final String invalidMinorPath = headerResourcePath + + "T01_002_header-invalid-minor-version.pdf"; + private static final String noMinorPath = headerResourcePath + + "T01_003_header-no-minor-version.pdf"; + private static final String noHeaderDashPath = headerResourcePath + + "T01_004_header_invalid-syntax-no-dash.pdf"; + private static final String invalidSyntaxRepPath = headerResourcePath + + "T01_005_header-invalid-syntax-replace-char.pdf"; + private static final String invalidSyntaxNoPdfPath = headerResourcePath + + "T01_006_header-invalid-syntax-no-pdf.pdf"; + private static final String noVersionInfoPath = headerResourcePath + + "T01_007_header-no-version-info.pdf"; + + private PdfModule module; + + @Before + public void setUp() throws Exception { + this.module = new PdfModule(); + JhoveBase je = new JhoveBase(); + this.module.setBase(je); + } + + /** + * Test method for {@link PdfHeader}. + * Ensures that a valid PDF passes. + */ + @Test + public final void testMinorVersion() throws URISyntaxException { + TestUtils.testValidateResource(this.module, minimalPdfPath, + RepInfo.TRUE, RepInfo.TRUE); + } + + /** + * Test method for {@link PdfModule}. + * Ensures that a file with a major version > 1 (%PDF-2.4) is not + * well-formed. + */ + @Test + public final void testInvalidMajorVersion() throws URISyntaxException { + TestUtils.testValidateResource(this.module, invalidMajorPath, + RepInfo.TRUE, RepInfo.FALSE, + MessageConstants.PDF_HUL_148.getId()); + } + + /** + * Test method for {@link PdfHeader}. + * Ensures that a file with a minor version > 7 (%PDF-1.9) is invalid. + */ + @Test + public final void testInvalidMinorVersion() throws URISyntaxException { + TestUtils.testValidateResource(this.module, invalidMinorPath, + RepInfo.TRUE, RepInfo.FALSE, + MessageConstants.PDF_HUL_148.getId()); + } + + /** + * Test method for {@link PdfHeader#getVersionString()}. + * Ensures that a file missing a minor version (%PDF-14) is not well-formed. + */ + @Test + public final void testNoMinor() throws URISyntaxException { + TestUtils.testValidateResource(this.module, noMinorPath, + RepInfo.FALSE, RepInfo.FALSE, + MessageConstants.PDF_HUL_155.getId()); + } + + /** + * Test method for {@link PdfModule}. + * Ensures that a file with no dash in header (%PDF1.4) is invalid. + */ + @Test + public final void testNoheaderDash() throws URISyntaxException { + TestUtils.testValidateResource(this.module, noHeaderDashPath, + RepInfo.FALSE, RepInfo.FALSE, + MessageConstants.PDF_HUL_137.getId()); + } + + /** + * Test method for {@link PdfModule}. + * Ensures that a file with no dash replaced by period in + * header (%PDF.1.4) is not well-formed. + */ + @Test + public final void testInvalidSyntaxRep() throws URISyntaxException { + TestUtils.testValidateResource(this.module, invalidSyntaxRepPath, + RepInfo.FALSE, RepInfo.FALSE, + MessageConstants.PDF_HUL_137.getId()); + } + + /** + * Test method for {@link PdfModule}. + * Ensures that a file with no PDF in header (%1.4) is not well-formed. + */ + @Test + public final void testInvalidSyntaxNoPdf() throws URISyntaxException { + TestUtils.testValidateResource(this.module, invalidSyntaxNoPdfPath, + RepInfo.FALSE, RepInfo.FALSE, + MessageConstants.PDF_HUL_137.getId()); + } + + /** + * Test method for {@link PdfModule}. + * Ensures that a file missing a header is not well-formed. + */ + @Test + public final void testNoVersionInfo() throws URISyntaxException { + TestUtils.testValidateResource(this.module, noVersionInfoPath, + RepInfo.FALSE, RepInfo.FALSE, + MessageConstants.PDF_HUL_137.getId()); + } } diff --git a/jhove-modules/pdf-hul/src/test/java/edu/harvard/hul/ois/jhove/module/pdf/PageTreeTests.java b/jhove-modules/pdf-hul/src/test/java/edu/harvard/hul/ois/jhove/module/pdf/PageTreeTests.java index 759245e4b..23ac5f539 100644 --- a/jhove-modules/pdf-hul/src/test/java/edu/harvard/hul/ois/jhove/module/pdf/PageTreeTests.java +++ b/jhove-modules/pdf-hul/src/test/java/edu/harvard/hul/ois/jhove/module/pdf/PageTreeTests.java @@ -11,143 +11,143 @@ import edu.harvard.hul.ois.jhove.module.TestUtils; /** - * @author Carl Wilson - * carlwilson AT github + * @author Carl Wilson + * carlwilson AT github * * @version 0.1 * - * Created 19 Mar 2018:02:03:50 + * Created 19 Mar 2018:02:03:50 */ public class PageTreeTests { - private static final String pdfResourcePath = "/edu/harvard/hul/ois/jhove/module/pdf/"; - private static final String pageTreeResourcePath = pdfResourcePath + "page-tree/"; - - private static final String minimalPdfPath = pdfResourcePath - + "T00_000_minimal-valid.pdf"; - - private static final String noPageTreeNodePath = pageTreeResourcePath - + "T02-02_001_no-page-tree-node.pdf"; - private static final String rcrsPageTreeKidsPath = pageTreeResourcePath - + "T02-02_002_page-tree-kids-links-recursive.pdf"; - private static final String diffPageTreeKidsPath = pageTreeResourcePath - + "T02-02_003_page-tree-different-kids.pdf"; - private static final String ntExstPageTreeChldPath = pageTreeResourcePath - + "T02-02_004_page-tree-non-existing-object-as-kid.pdf"; - private static final String noPageTreeKidsPath = pageTreeResourcePath - + "T02-02_005_page-tree-no-kids.pdf"; - private static final String noTypePageTreePath = pageTreeResourcePath - + "T02-02_006_page-tree-no-type.pdf"; - private static final String wrngPageTreeCountPath = pageTreeResourcePath - + "T02-02_007_page-tree-wrong-count.pdf"; - private static final String noPageTreeCountPath = pageTreeResourcePath - + "T02-02_008_page-tree-node-no-count.pdf"; - private static final String wrngPageTreeTypePath = pageTreeResourcePath - + "T02-02_009_page-tree-wrong-type.pdf"; - private PdfModule module; - - @Before - public void setUp() throws Exception { - this.module = new PdfModule(); - JhoveBase je = new JhoveBase(); - this.module.setBase(je); - } - - /** - * Test method for {@link PdfModule#getCatalogDict()}. - */ - @Test - public final void testValidCatType() throws URISyntaxException { - TestUtils.testValidateResource(this.module, minimalPdfPath, - RepInfo.TRUE, RepInfo.TRUE, null); - } - - /** - * Test method for {@link PdfModule#getCatalogDict()}. - */ - @Test - public final void testNoPageTreeNode() throws URISyntaxException { - TestUtils.testValidateResource(this.module, noPageTreeNodePath, - RepInfo.FALSE, RepInfo.FALSE, - MessageConstants.PDF_HUL_37.getMessage()); - } - - /** - * Test method for {@link PdfModule#getCatalogDict()}. - */ - @Test - public final void testRcrsPageTreeKids() throws URISyntaxException { - TestUtils.testValidateResource(this.module, rcrsPageTreeKidsPath, - RepInfo.FALSE, RepInfo.FALSE, - MessageConstants.PDF_HUL_32.getMessage()); - } - - /** - * Test method for {@link PdfModule#getCatalogDict()}. - */ - @Test - public final void testDiffPageTreeKids() throws URISyntaxException { - TestUtils.testValidateResource(this.module, diffPageTreeKidsPath, - RepInfo.FALSE, RepInfo.FALSE, - MessageConstants.PDF_HUL_33.getMessage()); - } - - /** - * Test method for {@link PdfModule#getCatalogDict()}. - */ - @Test - public final void testNtExstPageTreeChldPath() throws URISyntaxException { - TestUtils.testValidateResource(this.module, ntExstPageTreeChldPath, - RepInfo.TRUE, RepInfo.FALSE, - MessageConstants.PDF_HUL_147.getMessage()); - } - - /** - * Test method for {@link PdfModule#getCatalogDict()}. - */ - @Test - public final void testNoPageTreeKids() throws URISyntaxException { - TestUtils.testValidateResource(this.module, noPageTreeKidsPath, - RepInfo.FALSE, RepInfo.FALSE, - MessageConstants.PDF_HUL_37.getMessage()); - } - - /** - * Test method for {@link PdfModule#getCatalogDict()}. - */ - @Test - public final void testNoTypePageTree() throws URISyntaxException { - TestUtils.testValidateResource(this.module, noTypePageTreePath, - RepInfo.FALSE, RepInfo.FALSE, - MessageConstants.PDF_HUL_38.getMessage()); - } - - /** - * Test method for {@link PdfModule#getCatalogDict()}. - */ - @Test - public final void testWrngPageTreeCount() throws URISyntaxException { - TestUtils.testValidateResource(this.module, wrngPageTreeCountPath, - RepInfo.TRUE, RepInfo.TRUE, null); - } - - /** - * Test method for {@link PdfModule#getCatalogDict()}. - */ - @Test - public final void testNoPageTreeCount() throws URISyntaxException { - TestUtils.testValidateResource(this.module, noPageTreeCountPath, - RepInfo.FALSE, RepInfo.FALSE, - MessageConstants.PDF_HUL_37.getMessage()); - } - - /** - * Test method for {@link PdfModule#getCatalogDict()}. - */ - @Test - public final void testWrngPageTreeType() throws URISyntaxException { - TestUtils.testValidateResource(this.module, wrngPageTreeTypePath, - RepInfo.FALSE, RepInfo.FALSE, - MessageConstants.PDF_HUL_146.getMessage()); - } + private static final String pdfResourcePath = "/edu/harvard/hul/ois/jhove/module/pdf/"; + private static final String pageTreeResourcePath = pdfResourcePath + "page-tree/"; + + private static final String minimalPdfPath = pdfResourcePath + + "T00_000_minimal-valid.pdf"; + + private static final String noPageTreeNodePath = pageTreeResourcePath + + "T02-02_001_no-page-tree-node.pdf"; + private static final String rcrsPageTreeKidsPath = pageTreeResourcePath + + "T02-02_002_page-tree-kids-links-recursive.pdf"; + private static final String diffPageTreeKidsPath = pageTreeResourcePath + + "T02-02_003_page-tree-different-kids.pdf"; + private static final String ntExstPageTreeChldPath = pageTreeResourcePath + + "T02-02_004_page-tree-non-existing-object-as-kid.pdf"; + private static final String noPageTreeKidsPath = pageTreeResourcePath + + "T02-02_005_page-tree-no-kids.pdf"; + private static final String noTypePageTreePath = pageTreeResourcePath + + "T02-02_006_page-tree-no-type.pdf"; + private static final String wrngPageTreeCountPath = pageTreeResourcePath + + "T02-02_007_page-tree-wrong-count.pdf"; + private static final String noPageTreeCountPath = pageTreeResourcePath + + "T02-02_008_page-tree-node-no-count.pdf"; + private static final String wrngPageTreeTypePath = pageTreeResourcePath + + "T02-02_009_page-tree-wrong-type.pdf"; + private PdfModule module; + + @Before + public void setUp() throws Exception { + this.module = new PdfModule(); + JhoveBase je = new JhoveBase(); + this.module.setBase(je); + } + + /** + * Test method for {@link PdfModule#getCatalogDict()}. + */ + @Test + public final void testValidCatType() throws URISyntaxException { + TestUtils.testValidateResource(this.module, minimalPdfPath, + RepInfo.TRUE, RepInfo.TRUE, null); + } + + /** + * Test method for {@link PdfModule#getCatalogDict()}. + */ + @Test + public final void testNoPageTreeNode() throws URISyntaxException { + TestUtils.testValidateResource(this.module, noPageTreeNodePath, + RepInfo.FALSE, RepInfo.FALSE, + MessageConstants.PDF_HUL_38.getId()); + } + + /** + * Test method for {@link PdfModule#getCatalogDict()}. + */ + @Test + public final void testRcrsPageTreeKids() throws URISyntaxException { + TestUtils.testValidateResource(this.module, rcrsPageTreeKidsPath, + RepInfo.FALSE, RepInfo.FALSE, + MessageConstants.PDF_HUL_32.getId()); + } + + /** + * Test method for {@link PdfModule#getCatalogDict()}. + */ + @Test + public final void testDiffPageTreeKids() throws URISyntaxException { + TestUtils.testValidateResource(this.module, diffPageTreeKidsPath, + RepInfo.FALSE, RepInfo.FALSE, + MessageConstants.PDF_HUL_33.getId()); + } + + /** + * Test method for {@link PdfModule#getCatalogDict()}. + */ + @Test + public final void testNtExstPageTreeChldPath() throws URISyntaxException { + TestUtils.testValidateResource(this.module, ntExstPageTreeChldPath, + RepInfo.TRUE, RepInfo.FALSE, + MessageConstants.PDF_HUL_147.getId()); + } + + /** + * Test method for {@link PdfModule#getCatalogDict()}. + */ + @Test + public final void testNoPageTreeKids() throws URISyntaxException { + TestUtils.testValidateResource(this.module, noPageTreeKidsPath, + RepInfo.FALSE, RepInfo.FALSE, + MessageConstants.PDF_HUL_38.getId()); + } + + /** + * Test method for {@link PdfModule#getCatalogDict()}. + */ + @Test + public final void testNoTypePageTree() throws URISyntaxException { + TestUtils.testValidateResource(this.module, noTypePageTreePath, + RepInfo.FALSE, RepInfo.FALSE, + MessageConstants.PDF_HUL_38.getId()); + } + + /** + * Test method for {@link PdfModule#getCatalogDict()}. + */ + @Test + public final void testWrngPageTreeCount() throws URISyntaxException { + TestUtils.testValidateResource(this.module, wrngPageTreeCountPath, + RepInfo.TRUE, RepInfo.TRUE, null); + } + + /** + * Test method for {@link PdfModule#getCatalogDict()}. + */ + @Test + public final void testNoPageTreeCount() throws URISyntaxException { + TestUtils.testValidateResource(this.module, noPageTreeCountPath, + RepInfo.FALSE, RepInfo.FALSE, + MessageConstants.PDF_HUL_38.getId()); + } + + /** + * Test method for {@link PdfModule#getCatalogDict()}. + */ + @Test + public final void testWrngPageTreeType() throws URISyntaxException { + TestUtils.testValidateResource(this.module, wrngPageTreeTypePath, + RepInfo.FALSE, RepInfo.FALSE, + MessageConstants.PDF_HUL_146.getId()); + } } diff --git a/test-root/corpora/regression/modules/PDF-hul/PDF-HUL-137.pdf b/test-root/corpora/regression/modules/PDF-hul/PDF-HUL-137.pdf new file mode 100644 index 000000000..35d09a31a Binary files /dev/null and b/test-root/corpora/regression/modules/PDF-hul/PDF-HUL-137.pdf differ diff --git a/test-root/corpora/regression/modules/PDF-hul/PDF-HUL-137_fixed.pdf b/test-root/corpora/regression/modules/PDF-hul/PDF-HUL-137_fixed.pdf new file mode 100644 index 000000000..474eade0e Binary files /dev/null and b/test-root/corpora/regression/modules/PDF-hul/PDF-HUL-137_fixed.pdf differ