EpubModule extends ModuleBase { @Override public int parse(InputStream stream, RepInfo info, int parseIndex) throws IOException { initParse(); info.setModule(this); info.setFormat(_format[0]); info.setWellFormed(false); info.setValid(false); _propList = new LinkedList<>(); _metadata = new Property(PROPNAME_EPUB_METADATA, PropertyType.PROPERTY, PropertyArity.LIST, _propList); _ckSummer = null; setupDataStream(stream, info); try { JhoveRepInfoReport report = new JhoveRepInfoReport(info.getUri()); EpubCheck epubCheck = new EpubCheck(_dstream, report, info.getUri()); epubCheck.doValidate(); info.setCreated(report.getCreationDate()); info.setLastModified(report.getLastModifiedDate()); info.setVersion(report.getVersion()); List<CheckMessage> epubMessages = report.getAllMessages(); int notWellFormedErrors = epubMessages.stream().filter(c -> triggerNotWellFormed(c)) .collect(Collectors.toSet()).size(); info.setWellFormed(report.getFatalErrorCount() == 0 && notWellFormedErrors == 0); info.setValid(info.getWellFormed() == RepInfo.TRUE && report.getErrorCount() == 0); Set<Message> msgs = new TreeSet<Message>(new MessageComparator()); for (CheckMessage msg : report.getAllMessages()) { msgs.addAll(toJhoveMessages(msg)); } msgs.forEach(jhoveMsg -> info.setMessage(jhoveMsg)); info.setMimeType(report.getFormat()); generateProperties(report).forEach(prop -> _propList.add(prop)); } catch (Exception f) { f.printStackTrace(); if (f.getMessage() != null) { info.setMessage(new ErrorMessage(f.getMessage())); } else { info.setMessage(new ErrorMessage(MessageConstants.ERR_UNKNOWN)); } info.setWellFormed(false); return 0; } if (_je != null && _je.getAbort()) { return 0; } info.setProperty(_metadata); setChecksums(_ckSummer, info); return 0; } EpubModule();  EpubModule(String name, String release, int[] date,
            String[] format, String coverage,
            String[] mimetype, String wellformedNote,
            String validityNote, String repinfoNote, String note,
            String rights, boolean isRandomAccess, Agent moduleAgent); @Override void checkSignatures(File file, InputStream stream, RepInfo info); @Override int parse(InputStream stream, RepInfo info, int parseIndex); @Override void parse(RandomAccessFile file, RepInfo info); static String toUtf8(String inputString); static final String[] NOTWELLFORMED_ERRCODES; }
@Test public void parseValidEpub3ChecksumTest() throws Exception { File epubFile = new File(CHILDRENSLIT_SRC_FILEPATH); EpubModule em = new EpubModule(); JhoveBase je = new JhoveBase(); je.setChecksumFlag(true); em.setBase(je); RepInfo info = new RepInfo(epubFile.getAbsolutePath()); em.parse(new FileInputStream(epubFile), info, 0); Map<ChecksumType, String> checksums = new HashMap<ChecksumType, String>(); info.getChecksum().forEach(cs -> checksums.put(cs.getType(), cs.getValue())); assertEquals("da79cb9b", checksums.get(ChecksumType.CRC32)); assertEquals("4c2dee43162e40690ba05926b9f42522", checksums.get(ChecksumType.MD5)); assertEquals("72bcf1b71f4dd9b902a5fcd614601d5e488003a0", checksums.get(ChecksumType.SHA1)); assertEquals("a1da72ef94de43a70a97538d5e789f74bf7c29bd99f8059697ae75a6b85a75f7", checksums.get(ChecksumType.SHA256)); final int expectedNumChecksums = 4; assertEquals(expectedNumChecksums, info.getChecksum().size()); }
@Test public void parseValidEpub2ChecksumTest() throws Exception { File epubFile = new File(MINIMAL_EPUB_FILEPATH); EpubModule em = new EpubModule(); JhoveBase je = new JhoveBase(); je.setChecksumFlag(true); em.setBase(je); RepInfo info = new RepInfo(epubFile.getAbsolutePath()); em.parse(new FileInputStream(epubFile), info, 0); Map<ChecksumType, String> checksums = new HashMap<ChecksumType, String>(); info.getChecksum().forEach(cs -> checksums.put(cs.getType(), cs.getValue())); assertEquals("8b80b526", checksums.get(ChecksumType.CRC32)); assertEquals("b2110219d62c3c6ef1683c645636fd38", checksums.get(ChecksumType.MD5)); assertEquals("79f20f6a499a640019a9bb0334652edbb954c3c9", checksums.get(ChecksumType.SHA1)); assertEquals("4776bb33b1cce8598b31996ed0b4daf36e4b74e379b811a27e51efa15315744a", checksums.get(ChecksumType.SHA256)); final int expectedNumChecksum = 4; assertEquals(expectedNumChecksum, info.getChecksum().size()); }