From 39888e2421db0f7eda96554ee87c2c0d9d8024ab Mon Sep 17 00:00:00 2001 From: Romain Deltour Date: Fri, 29 Oct 2021 01:29:00 +0200 Subject: [PATCH] feat: **reword** internal refactoring - unify ContentChecker/DocumentValidator into Checker - refactor Checkers into AbstractChecker + PublicationResourceChecker --- .../com/adobe/epubcheck/api/EpubCheck.java | 16 +-- .../adobe/epubcheck/api/EpubCheckFactory.java | 8 +- .../adobe/epubcheck/bitmap/BitmapChecker.java | 88 +++++--------- .../bitmap/BitmapCheckerFactory.java | 41 ------- .../com/adobe/epubcheck/css/CSSChecker.java | 44 ++++--- .../epubcheck/css/CSSCheckerFactory.java | 55 --------- .../com/adobe/epubcheck/ctc/CheckManager.java | 36 +++--- .../adobe/epubcheck/ctc/ContentValidator.java | 5 +- .../epubcheck/ctc/Epub3StructureCheck.java | 8 +- .../com/adobe/epubcheck/ctc/EpubCSSCheck.java | 7 +- .../com/adobe/epubcheck/ctc/EpubCfiCheck.java | 9 +- .../ctc/EpubCheckContentFactory.java | 5 +- .../epubcheck/ctc/EpubExtLinksCheck.java | 8 +- .../ctc/EpubHTML5StructureCheck.java | 8 +- .../adobe/epubcheck/ctc/EpubLangCheck.java | 8 +- .../epubcheck/ctc/EpubMetaDataV2Check.java | 12 +- .../epubcheck/ctc/EpubMetaDataV3Check.java | 12 +- .../com/adobe/epubcheck/ctc/EpubNCXCheck.java | 7 +- .../com/adobe/epubcheck/ctc/EpubNavCheck.java | 8 +- .../epubcheck/ctc/EpubRenditionCheck.java | 20 ++-- .../com/adobe/epubcheck/ctc/EpubSVGCheck.java | 7 +- .../adobe/epubcheck/ctc/EpubScriptCheck.java | 8 +- .../adobe/epubcheck/ctc/EpubSpanCheck.java | 8 +- .../adobe/epubcheck/ctc/EpubSpineCheck.java | 20 ++-- .../epubcheck/ctc/EpubStyleSheetsCheck.java | 8 +- .../epubcheck/ctc/EpubTextContentCheck.java | 8 +- .../com/adobe/epubcheck/ctc/EpubTocCheck.java | 8 +- .../epubcheck/dict/SearchKeyMapChecker.java | 47 ++------ .../dict/SearchKeyMapCheckerFactory.java | 43 ------- .../adobe/epubcheck/dtbook/DTBookChecker.java | 41 ++----- .../dtbook/DTBookCheckerFactory.java | 42 ------- .../com/adobe/epubcheck/nav/NavChecker.java | 54 +++------ .../epubcheck/nav/NavCheckerFactory.java | 43 ------- .../com/adobe/epubcheck/ncx/NCXChecker.java | 77 ++++++------ .../epubcheck/ncx/NCXCheckerFactory.java | 42 ------- .../com/adobe/epubcheck/ocf/OCFChecker.java | 27 +++-- .../com/adobe/epubcheck/ocf/OCFPackage.java | 4 +- .../adobe/epubcheck/opf/ContentChecker.java | 28 ----- .../epubcheck/opf/ContentCheckerFactory.java | 29 ----- .../epubcheck/opf/DocumentValidator.java | 28 ----- .../opf/DocumentValidatorFactory.java | 36 ------ .../epubcheck/opf/GenericContentChecker.java | 54 --------- .../opf/GenericContentCheckerFactory.java | 38 ------ .../com/adobe/epubcheck/opf/OPFChecker.java | 113 +++++++----------- .../com/adobe/epubcheck/opf/OPFChecker30.java | 43 ++----- .../epubcheck/opf/OPFCheckerFactory.java | 47 -------- .../java/com/adobe/epubcheck/opf/OPFData.java | 1 - .../opf/PublicationResourceChecker.java | 97 +++++++++++++++ .../epubcheck/opf/ValidationContext.java | 5 +- .../com/adobe/epubcheck/ops/OPSChecker.java | 53 +++----- .../epubcheck/ops/OPSCheckerFactory.java | 44 ------- .../com/adobe/epubcheck/ops/OPSHandler.java | 10 +- .../epubcheck/overlay/OverlayChecker.java | 44 ++----- .../overlay/OverlayCheckerFactory.java | 44 ------- .../com/adobe/epubcheck/tool/EpubChecker.java | 80 +++++++------ .../com/adobe/epubcheck/util/OPSType.java | 4 +- .../org/w3c/epubcheck/constants/MIMEType.java | 55 +++++++++ .../w3c/epubcheck/core/AbstractChecker.java | 19 +++ .../java/org/w3c/epubcheck/core/Checker.java | 6 + .../w3c/epubcheck/core/CheckerFactory.java | 69 +++++++++++ .../adobe/epubcheck/stress/StressTest.java | 2 +- .../w3c/epubcheck/test/ExecutionSteps.java | 23 ++-- 62 files changed, 647 insertions(+), 1217 deletions(-) delete mode 100755 src/main/java/com/adobe/epubcheck/bitmap/BitmapCheckerFactory.java delete mode 100644 src/main/java/com/adobe/epubcheck/css/CSSCheckerFactory.java delete mode 100644 src/main/java/com/adobe/epubcheck/dict/SearchKeyMapCheckerFactory.java delete mode 100755 src/main/java/com/adobe/epubcheck/dtbook/DTBookCheckerFactory.java delete mode 100644 src/main/java/com/adobe/epubcheck/nav/NavCheckerFactory.java delete mode 100755 src/main/java/com/adobe/epubcheck/ncx/NCXCheckerFactory.java delete mode 100755 src/main/java/com/adobe/epubcheck/opf/ContentChecker.java delete mode 100755 src/main/java/com/adobe/epubcheck/opf/ContentCheckerFactory.java delete mode 100644 src/main/java/com/adobe/epubcheck/opf/DocumentValidator.java delete mode 100644 src/main/java/com/adobe/epubcheck/opf/DocumentValidatorFactory.java delete mode 100755 src/main/java/com/adobe/epubcheck/opf/GenericContentChecker.java delete mode 100755 src/main/java/com/adobe/epubcheck/opf/GenericContentCheckerFactory.java delete mode 100644 src/main/java/com/adobe/epubcheck/opf/OPFCheckerFactory.java create mode 100755 src/main/java/com/adobe/epubcheck/opf/PublicationResourceChecker.java delete mode 100755 src/main/java/com/adobe/epubcheck/ops/OPSCheckerFactory.java delete mode 100644 src/main/java/com/adobe/epubcheck/overlay/OverlayCheckerFactory.java create mode 100644 src/main/java/org/w3c/epubcheck/constants/MIMEType.java create mode 100644 src/main/java/org/w3c/epubcheck/core/AbstractChecker.java create mode 100644 src/main/java/org/w3c/epubcheck/core/Checker.java create mode 100644 src/main/java/org/w3c/epubcheck/core/CheckerFactory.java diff --git a/src/main/java/com/adobe/epubcheck/api/EpubCheck.java b/src/main/java/com/adobe/epubcheck/api/EpubCheck.java index 57fff6318..3c5ca47c8 100644 --- a/src/main/java/com/adobe/epubcheck/api/EpubCheck.java +++ b/src/main/java/com/adobe/epubcheck/api/EpubCheck.java @@ -32,13 +32,14 @@ import java.util.Properties; import java.util.zip.ZipFile; +import org.w3c.epubcheck.constants.MIMEType; +import org.w3c.epubcheck.core.Checker; + import com.adobe.epubcheck.ctc.CheckManager; import com.adobe.epubcheck.messages.MessageId; import com.adobe.epubcheck.ocf.OCFChecker; import com.adobe.epubcheck.ocf.OCFPackage; import com.adobe.epubcheck.ocf.OCFZipPackage; -import com.adobe.epubcheck.opf.DocumentValidator; -import com.adobe.epubcheck.opf.OPFData; import com.adobe.epubcheck.opf.ValidationContext.ValidationContextBuilder; import com.adobe.epubcheck.util.DefaultReportImpl; import com.adobe.epubcheck.util.EPUBVersion; @@ -48,7 +49,7 @@ /** * Public interface to epub validator. */ -public class EpubCheck implements DocumentValidator +public class EpubCheck implements Checker { private static String VERSION = null; private static String BUILD_DATE = null; @@ -199,10 +200,9 @@ public void setLocale(Locale locale) /** * Validate the file. Return true if no errors or warnings found. */ - public boolean validate() + public void check() { - int validateResult = doValidate(); - return validateResult == 0; + doValidate(); } public int doValidate() @@ -221,7 +221,7 @@ public int doValidate() OCFPackage ocf = new OCFZipPackage(zip); OCFChecker checker = new OCFChecker(new ValidationContextBuilder() .path(epubFile.getAbsolutePath()).ocf(ocf).report(report).profile(profile).build()); - checker.runChecks(); + checker.check(); String extension = ResourceUtil.getExtension(epubFile.getName()); checkExtension(ocf, extension); @@ -267,7 +267,7 @@ void checkExtension(OCFPackage ocf, String extension) } else { - List opfPaths = ocf.getOcfData().getEntries(OPFData.OPF_MIME_TYPE); + List opfPaths = ocf.getOcfData().getEntries(MIMEType.PACKAGE_DOC.toString()); if (!opfPaths.isEmpty()) { if(ocf.getOpfData().get(opfPaths.get(0)).getVersion() == EPUBVersion.VERSION_3) { report.message(MessageId.PKG_024, EPUBLocation.create(epubFile.getName(), extension)); diff --git a/src/main/java/com/adobe/epubcheck/api/EpubCheckFactory.java b/src/main/java/com/adobe/epubcheck/api/EpubCheckFactory.java index eea752b4a..22999c443 100644 --- a/src/main/java/com/adobe/epubcheck/api/EpubCheckFactory.java +++ b/src/main/java/com/adobe/epubcheck/api/EpubCheckFactory.java @@ -25,11 +25,11 @@ import java.io.File; import java.io.IOException; -import com.adobe.epubcheck.opf.DocumentValidator; -import com.adobe.epubcheck.opf.DocumentValidatorFactory; +import org.w3c.epubcheck.core.Checker; + import com.adobe.epubcheck.opf.ValidationContext; -public class EpubCheckFactory implements DocumentValidatorFactory +public class EpubCheckFactory { static private final EpubCheckFactory instance = new EpubCheckFactory(); @@ -38,7 +38,7 @@ static public EpubCheckFactory getInstance() return instance; } - public DocumentValidator newInstance(ValidationContext context) + public Checker newInstance(ValidationContext context) { if (context.path.startsWith("http://") || context.path.startsWith("https://")) { diff --git a/src/main/java/com/adobe/epubcheck/bitmap/BitmapChecker.java b/src/main/java/com/adobe/epubcheck/bitmap/BitmapChecker.java index 2550fa901..29828bcf5 100755 --- a/src/main/java/com/adobe/epubcheck/bitmap/BitmapChecker.java +++ b/src/main/java/com/adobe/epubcheck/bitmap/BitmapChecker.java @@ -34,33 +34,27 @@ import javax.imageio.stream.ImageInputStream; import com.adobe.epubcheck.api.EPUBLocation; -import com.adobe.epubcheck.api.Report; import com.adobe.epubcheck.messages.MessageId; import com.adobe.epubcheck.ocf.OCFPackage; import com.adobe.epubcheck.ocf.OCFZipPackage; -import com.adobe.epubcheck.opf.ContentChecker; +import com.adobe.epubcheck.opf.PublicationResourceChecker; +import com.adobe.epubcheck.opf.ValidationContext; import com.adobe.epubcheck.util.CheckUtil; -public class BitmapChecker implements ContentChecker +public class BitmapChecker extends PublicationResourceChecker { - private final OCFPackage ocf; - private final Report report; - private final String path; - private final String mimeType; private static final int HEIGHT_MAX = 2 * 1080; private static final int WIDTH_MAX = 2 * 1920; private static final long IMAGESIZE_MAX = 4 * 1024 * 1024; - BitmapChecker(OCFPackage ocf, Report report, String path, String mimeType) + public BitmapChecker(ValidationContext context) { - this.ocf = ocf; - this.report = report; - this.path = path; - this.mimeType = mimeType; + super(context); } private void checkHeader(byte[] header) { + String mimeType = context.mimeType; boolean passed; if (mimeType.equals("image/jpeg")) { @@ -77,7 +71,7 @@ else if (mimeType.equals("image/gif")) } if (!passed) { - report.message(MessageId.OPF_029, EPUBLocation.create(this.ocf.getName()), path, mimeType); + report.message(MessageId.OPF_029, EPUBLocation.create(context.ocf.get().getName()), context.path, mimeType); } } @@ -92,6 +86,7 @@ else if (mimeType.equals("image/gif")) public ImageHeuristics getImageSizes(String imgFileName) throws IOException { + OCFPackage ocf = context.ocf.get(); int pos = imgFileName.lastIndexOf("."); if (pos == -1) { @@ -186,7 +181,7 @@ public ImageHeuristics getImageSizes(String imgFileName) throws } } - private File getImageFile(OCFPackage ocf, String imgFileName) throws IOException + private static File getImageFile(OCFPackage ocf, String imgFileName) throws IOException { if (ocf.getClass() == OCFZipPackage.class) { @@ -212,7 +207,7 @@ public ImageHeuristics(int width, int height, long length) } } - private File getTempImageFile(OCFZipPackage ocf, String imgFileName) throws IOException + private static File getTempImageFile(OCFZipPackage ocf, String imgFileName) throws IOException { File file = null; FileOutputStream os = null; @@ -283,56 +278,33 @@ private void checkImageDimensions(String imageFileName) } } - public void runChecks() + @Override + protected boolean checkContent() { - if (!ocf.hasEntry(path)) + try (InputStream in = context.resourceProvider.getInputStream(context.path)) { - report.message(MessageId.RSC_001, EPUBLocation.create(this.ocf.getName()), path); - } - else if (!ocf.canDecrypt(path)) - { - report.message(MessageId.RSC_004, EPUBLocation.create(this.ocf.getName()), path); - } - else - { - InputStream in = null; - try + if (in == null) { - in = ocf.getInputStream(path); - if (in == null) - { - report.message(MessageId.RSC_001, EPUBLocation.create(this.ocf.getName()), path); - } - byte[] header = new byte[4]; - int rd = CheckUtil.readBytes(in, header, 0, 4); - if (rd < 4) - { - report.message(MessageId.MED_004, EPUBLocation.create(path)); - } - else - { - checkHeader(header); - } - checkImageDimensions(path); + report.message(MessageId.RSC_001, EPUBLocation.create(context.path)); + return false; } - catch (IOException e) + byte[] header = new byte[4]; + int rd = CheckUtil.readBytes(in, header, 0, 4); + if (rd < 4) { - report.message(MessageId.PKG_021, EPUBLocation.create(path, path)); + report.message(MessageId.MED_004, EPUBLocation.create(context.path)); } - finally + else { - try - { - if (in != null) - { - in.close(); - } - } - catch (IOException ignored) - { - // eat it - } + checkHeader(header); } + checkImageDimensions(context.path); + return true; } - } + catch (IOException e) + { + report.message(MessageId.PKG_021, EPUBLocation.create(context.path, context.path)); + return false; + } + } } diff --git a/src/main/java/com/adobe/epubcheck/bitmap/BitmapCheckerFactory.java b/src/main/java/com/adobe/epubcheck/bitmap/BitmapCheckerFactory.java deleted file mode 100755 index 8eb962e53..000000000 --- a/src/main/java/com/adobe/epubcheck/bitmap/BitmapCheckerFactory.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2007 Adobe Systems Incorporated - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - */ - -package com.adobe.epubcheck.bitmap; - -import com.adobe.epubcheck.opf.ContentCheckerFactory; -import com.adobe.epubcheck.opf.ValidationContext; - -public class BitmapCheckerFactory implements ContentCheckerFactory -{ - static private final BitmapCheckerFactory instance = new BitmapCheckerFactory(); - - public BitmapChecker newInstance(ValidationContext context) - { - return new BitmapChecker(context.ocf.get(), context.report, context.path, context.mimeType); - } - - static public BitmapCheckerFactory getInstance() - { - return instance; - } -} diff --git a/src/main/java/com/adobe/epubcheck/css/CSSChecker.java b/src/main/java/com/adobe/epubcheck/css/CSSChecker.java index 9a5f3b6b9..3a11dd1b9 100644 --- a/src/main/java/com/adobe/epubcheck/css/CSSChecker.java +++ b/src/main/java/com/adobe/epubcheck/css/CSSChecker.java @@ -32,17 +32,12 @@ import org.idpf.epubcheck.util.css.CssSource; import com.adobe.epubcheck.api.EPUBLocation; -import com.adobe.epubcheck.api.Report; import com.adobe.epubcheck.messages.MessageId; -import com.adobe.epubcheck.opf.ContentChecker; +import com.adobe.epubcheck.opf.PublicationResourceChecker; import com.adobe.epubcheck.opf.ValidationContext; -public class CSSChecker implements ContentChecker +public class CSSChecker extends PublicationResourceChecker { - private final ValidationContext context; - private final Report report; - private final String path; // css file path when Mode.FILE, host path when - // Mode.STRING private final Mode mode; // Below only used when checking css strings @@ -75,27 +70,29 @@ public CSSChecker(ValidationContext context, String value, int line, boolean isS private CSSChecker(ValidationContext context, Mode mode, String value, int line, boolean isStyleAttribute) { - this.context = context; - this.report = context.report; - this.path = context.path; + super(context); this.mode = mode; this.value = value; this.line = line; this.isStyleAttribute = isStyleAttribute; } + + @Override + protected boolean checkPublicationBeforeContent() + { + if (this.mode == Mode.FILE) { + return super.checkPublicationBeforeContent(); + } + return true; + } - public void runChecks() + @Override + protected boolean checkContent() { CssSource source = null; try { - if (this.mode == Mode.FILE && !context.ocf.get().hasEntry(path)) - { - report.message(MessageId.RSC_001, EPUBLocation.create(context.ocf.get().getName()), - path); - return; - } CSSHandler handler = new CSSHandler(context); if (this.mode == Mode.STRING && this.line > -1) @@ -109,7 +106,7 @@ public void runChecks() this.line = -1; } catch (Exception e) { - report.message(MessageId.PKG_008, EPUBLocation.create(path), e.getMessage()); + report.message(MessageId.PKG_008, EPUBLocation.create(context.path), e.getMessage()); } finally { if (source != null) @@ -127,6 +124,7 @@ public void runChecks() } } } + return true; } CssSource getCssSource() @@ -135,14 +133,14 @@ CssSource getCssSource() CssSource source = null; if (this.mode == Mode.FILE) { - source = new CssSource(this.path, context.resourceProvider.getInputStream(this.path)); + source = new CssSource(context.path, context.resourceProvider.getInputStream(context.path)); String charset; if (source.getInputStream().getBomCharset().isPresent()) { charset = source.getInputStream().getBomCharset().get().toLowerCase(Locale.ROOT); if (!charset.equals("utf-8") && !charset.startsWith("utf-16")) { - report.message(MessageId.CSS_004, EPUBLocation.create(path), charset); + report.message(MessageId.CSS_004, EPUBLocation.create(context.path), charset); } } if (source.getInputStream().getCssCharset().isPresent()) @@ -150,7 +148,7 @@ CssSource getCssSource() charset = source.getInputStream().getCssCharset().get().toLowerCase(Locale.ROOT); if (!charset.equals("utf-8") && !charset.startsWith("utf-16")) { - report.message(MessageId.CSS_003, EPUBLocation.create(path, ""), charset); + report.message(MessageId.CSS_003, EPUBLocation.create(context.path, ""), charset); } } } @@ -169,13 +167,13 @@ void parseItem(CssSource source, CSSHandler handler) } else { - new CssParser(context.locale).parse(new StringReader(this.value), this.path, handler, handler); + new CssParser(context.locale).parse(new StringReader(this.value), context.path, handler, handler); } } else { new CssParser(context.locale) - .parseStyleAttribute(new StringReader(this.value), this.path, handler, handler); + .parseStyleAttribute(new StringReader(this.value), context.path, handler, handler); } } } diff --git a/src/main/java/com/adobe/epubcheck/css/CSSCheckerFactory.java b/src/main/java/com/adobe/epubcheck/css/CSSCheckerFactory.java deleted file mode 100644 index 0f34e5105..000000000 --- a/src/main/java/com/adobe/epubcheck/css/CSSCheckerFactory.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2011 Adobe Systems Incorporated - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - */ -package com.adobe.epubcheck.css; - -import com.adobe.epubcheck.opf.ContentChecker; -import com.adobe.epubcheck.opf.ValidationContext; -import com.adobe.epubcheck.opf.ContentCheckerFactory; - -public class CSSCheckerFactory implements ContentCheckerFactory -{ - /* - * (non-Javadoc) - * @see com.adobe.epubcheck.opf.ContentCheckerFactory#newInstance(com.adobe.epubcheck.ocf.OCFPackage, com.adobe.epubcheck.api.Report, java.lang.String, java.lang.String, java.lang.String, com.adobe.epubcheck.opf.XRefChecker, com.adobe.epubcheck.util.EPUBVersion) - */ - public ContentChecker newInstance(ValidationContext context) - { - - return new CSSChecker(context); - } - - /** - * Additional constructor for validating CSS strings (style attributes and elements) - */ - public ContentChecker newInstance(ValidationContext context, String value, int line, - boolean isStyleAttribute) - { - return new CSSChecker(context, value, line, isStyleAttribute); - } - - static private final CSSCheckerFactory instance = new CSSCheckerFactory(); - - static public CSSCheckerFactory getInstance() - { - return instance; - } -} diff --git a/src/main/java/com/adobe/epubcheck/ctc/CheckManager.java b/src/main/java/com/adobe/epubcheck/ctc/CheckManager.java index 6f68d466b..b84b41d04 100644 --- a/src/main/java/com/adobe/epubcheck/ctc/CheckManager.java +++ b/src/main/java/com/adobe/epubcheck/ctc/CheckManager.java @@ -44,28 +44,28 @@ public void checkPackage() if (version != null && version.equals(EPUBVersion.VERSION_3)) { - factory.newInstance(report, ValidationType.RENDITION, epack).validate(); - factory.newInstance(report, ValidationType.CFI, epack).validate(); - factory.newInstance(report, ValidationType.METADATA_V3, epack).validate(); - factory.newInstance(report, ValidationType.NAV, epack).validate(); + factory.newInstance(report, ValidationType.RENDITION, epack).check(); + factory.newInstance(report, ValidationType.CFI, epack).check(); + factory.newInstance(report, ValidationType.METADATA_V3, epack).check(); + factory.newInstance(report, ValidationType.NAV, epack).check(); } else if (version != null && EPUBVersion.VERSION_2.equals(version)) { - factory.newInstance(report, ValidationType.EPUB3_STRUCTURE, epack).validate(); - factory.newInstance(report, ValidationType.METADATA_V2, epack).validate(); + factory.newInstance(report, ValidationType.EPUB3_STRUCTURE, epack).check(); + factory.newInstance(report, ValidationType.METADATA_V2, epack).check(); } - factory.newInstance(report, ValidationType.NCX, epack).validate(); - factory.newInstance(report, ValidationType.MULTIPLE_CSS, epack).validate(); - factory.newInstance(report, ValidationType.HTML_STRUCTURE, epack).validate(); - factory.newInstance(report, ValidationType.LINK, epack).validate(); - factory.newInstance(report, ValidationType.CSS_SEARCH, epack).validate(); - factory.newInstance(report, ValidationType.TOC, epack).validate(); - factory.newInstance(report, ValidationType.LANG, epack).validate(); - factory.newInstance(report, ValidationType.SPINE, epack).validate(); - factory.newInstance(report, ValidationType.TEXT, epack).validate(); - factory.newInstance(report, ValidationType.SCRIPT, epack).validate(); - factory.newInstance(report, ValidationType.SPAN, epack).validate(); - factory.newInstance(report, ValidationType.SVG, epack).validate(); + factory.newInstance(report, ValidationType.NCX, epack).check(); + factory.newInstance(report, ValidationType.MULTIPLE_CSS, epack).check(); + factory.newInstance(report, ValidationType.HTML_STRUCTURE, epack).check(); + factory.newInstance(report, ValidationType.LINK, epack).check(); + factory.newInstance(report, ValidationType.CSS_SEARCH, epack).check(); + factory.newInstance(report, ValidationType.TOC, epack).check(); + factory.newInstance(report, ValidationType.LANG, epack).check(); + factory.newInstance(report, ValidationType.SPINE, epack).check(); + factory.newInstance(report, ValidationType.TEXT, epack).check(); + factory.newInstance(report, ValidationType.SCRIPT, epack).check(); + factory.newInstance(report, ValidationType.SPAN, epack).check(); + factory.newInstance(report, ValidationType.SVG, epack).check(); } } diff --git a/src/main/java/com/adobe/epubcheck/ctc/ContentValidator.java b/src/main/java/com/adobe/epubcheck/ctc/ContentValidator.java index 5e239896b..f86bef8ae 100644 --- a/src/main/java/com/adobe/epubcheck/ctc/ContentValidator.java +++ b/src/main/java/com/adobe/epubcheck/ctc/ContentValidator.java @@ -1,8 +1,9 @@ package com.adobe.epubcheck.ctc; +import org.w3c.epubcheck.core.Checker; + import com.adobe.epubcheck.api.Report; import com.adobe.epubcheck.ctc.epubpackage.EpubPackage; -import com.adobe.epubcheck.opf.DocumentValidator; /** * === WARNING ==========================================
@@ -18,5 +19,5 @@ public enum ValidationType TEXT, CONTENT, SPINE, NCX, NAV, SCRIPT, SPAN, STYLE, METADATA_V3, METADATA_V2, LANG, CSS_SEARCH, LINK, RENDITION, CFI, HTML_STRUCTURE, MULTIPLE_CSS, EPUB3_STRUCTURE, TOC, SVG } - public DocumentValidator newInstance(Report report, ValidationType vt, EpubPackage epack); + public Checker newInstance(Report report, ValidationType vt, EpubPackage epack); } diff --git a/src/main/java/com/adobe/epubcheck/ctc/Epub3StructureCheck.java b/src/main/java/com/adobe/epubcheck/ctc/Epub3StructureCheck.java index d9d9cd8f8..fd5f0a868 100644 --- a/src/main/java/com/adobe/epubcheck/ctc/Epub3StructureCheck.java +++ b/src/main/java/com/adobe/epubcheck/ctc/Epub3StructureCheck.java @@ -2,12 +2,13 @@ import java.util.zip.ZipEntry; +import org.w3c.epubcheck.core.Checker; + import com.adobe.epubcheck.api.Report; import com.adobe.epubcheck.ctc.epubpackage.EpubPackage; import com.adobe.epubcheck.ctc.epubpackage.ManifestItem; import com.adobe.epubcheck.ctc.xml.Epub3StructureHandler; import com.adobe.epubcheck.ctc.xml.XMLContentDocParser; -import com.adobe.epubcheck.opf.DocumentValidator; import com.adobe.epubcheck.util.SearchDictionary; import com.adobe.epubcheck.util.SearchDictionary.DictionaryType; @@ -18,7 +19,7 @@ * Please keep changes minimal (bug fixes only) until then.
* ========================================================
*/ -public class Epub3StructureCheck implements DocumentValidator +public class Epub3StructureCheck implements Checker { private final Report report; private final EpubPackage epack; @@ -30,7 +31,7 @@ public Epub3StructureCheck(EpubPackage epack, Report report) } @Override - public boolean validate() + public void check() { boolean result = false; @@ -63,6 +64,5 @@ public boolean validate() } } } - return result; } } diff --git a/src/main/java/com/adobe/epubcheck/ctc/EpubCSSCheck.java b/src/main/java/com/adobe/epubcheck/ctc/EpubCSSCheck.java index cb3c8ad82..c13836417 100644 --- a/src/main/java/com/adobe/epubcheck/ctc/EpubCSSCheck.java +++ b/src/main/java/com/adobe/epubcheck/ctc/EpubCSSCheck.java @@ -13,6 +13,7 @@ import org.idpf.epubcheck.util.css.CssParser; import org.idpf.epubcheck.util.css.CssSource; +import org.w3c.epubcheck.core.Checker; import com.adobe.epubcheck.api.EPUBLocation; import com.adobe.epubcheck.api.LocalizableReport; @@ -24,7 +25,6 @@ import com.adobe.epubcheck.ctc.xml.XMLContentDocParser; import com.adobe.epubcheck.messages.MessageId; import com.adobe.epubcheck.ocf.EncryptionFilter; -import com.adobe.epubcheck.opf.DocumentValidator; import com.adobe.epubcheck.util.PathUtil; import com.adobe.epubcheck.util.SearchDictionary; import com.adobe.epubcheck.util.SearchDictionary.DictionaryType; @@ -37,7 +37,7 @@ * Please keep changes minimal (bug fixes only) until then.
* ========================================================
*/ -public class EpubCSSCheck implements DocumentValidator +public class EpubCSSCheck implements Checker { final ZipFile zip; final Report report; @@ -55,7 +55,7 @@ public EpubCSSCheck(EpubPackage epack, Report report) this.isGlobalFixed = EpubPackage.isGlobalFixed(epack); } - public boolean validate() + public void check() { boolean hasFixedFormatItems = getHasFixedFormatItems(epack); SearchDictionary tsd = new SearchDictionary(DictionaryType.CSS_VALUES); @@ -146,7 +146,6 @@ public boolean validate() { report.message(MessageId.CSS_011, EPUBLocation.create(epack.getFileName())); } - return true; } boolean getHasFixedFormatItems(EpubPackage epack) diff --git a/src/main/java/com/adobe/epubcheck/ctc/EpubCfiCheck.java b/src/main/java/com/adobe/epubcheck/ctc/EpubCfiCheck.java index 2532c1f2e..1a01a9804 100644 --- a/src/main/java/com/adobe/epubcheck/ctc/EpubCfiCheck.java +++ b/src/main/java/com/adobe/epubcheck/ctc/EpubCfiCheck.java @@ -4,6 +4,8 @@ import java.util.Vector; import java.util.zip.ZipEntry; +import org.w3c.epubcheck.core.Checker; + import com.adobe.epubcheck.api.EPUBLocation; import com.adobe.epubcheck.api.Report; import com.adobe.epubcheck.ctc.epubpackage.EpubPackage; @@ -11,7 +13,6 @@ import com.adobe.epubcheck.ctc.xml.AnchorTagHandler; import com.adobe.epubcheck.ctc.xml.XMLContentDocParser; import com.adobe.epubcheck.messages.MessageId; -import com.adobe.epubcheck.opf.DocumentValidator; import com.adobe.epubcheck.util.SearchDictionary; import com.adobe.epubcheck.util.SearchDictionary.DictionaryType; @@ -22,7 +23,7 @@ * Please keep changes minimal (bug fixes only) until then.
* ========================================================
*/ -public class EpubCfiCheck implements DocumentValidator +public class EpubCfiCheck implements Checker { private final Report report; private final EpubPackage epack; @@ -34,7 +35,7 @@ public EpubCfiCheck(EpubPackage epack, Report report) } - public boolean validate() + public void check() { SearchDictionary validTypes = new SearchDictionary(DictionaryType.VALID_TEXT_MEDIA_TYPES); @@ -64,8 +65,6 @@ public boolean validate() } } } - - return true; } private void searchInsideValue(AnchorTagHandler.DocTagContent entry, String file) diff --git a/src/main/java/com/adobe/epubcheck/ctc/EpubCheckContentFactory.java b/src/main/java/com/adobe/epubcheck/ctc/EpubCheckContentFactory.java index 72fb84883..2be39d446 100644 --- a/src/main/java/com/adobe/epubcheck/ctc/EpubCheckContentFactory.java +++ b/src/main/java/com/adobe/epubcheck/ctc/EpubCheckContentFactory.java @@ -1,8 +1,9 @@ package com.adobe.epubcheck.ctc; +import org.w3c.epubcheck.core.Checker; + import com.adobe.epubcheck.api.Report; import com.adobe.epubcheck.ctc.epubpackage.EpubPackage; -import com.adobe.epubcheck.opf.DocumentValidator; /** * === WARNING ==========================================
@@ -21,7 +22,7 @@ static public EpubCheckContentFactory getInstance() } @Override - public DocumentValidator newInstance(Report report, ValidationType vt, EpubPackage epack) + public Checker newInstance(Report report, ValidationType vt, EpubPackage epack) { if (vt.equals(ValidationType.METADATA_V3)) { diff --git a/src/main/java/com/adobe/epubcheck/ctc/EpubExtLinksCheck.java b/src/main/java/com/adobe/epubcheck/ctc/EpubExtLinksCheck.java index 28c387d2e..cfb17686f 100644 --- a/src/main/java/com/adobe/epubcheck/ctc/EpubExtLinksCheck.java +++ b/src/main/java/com/adobe/epubcheck/ctc/EpubExtLinksCheck.java @@ -5,6 +5,8 @@ import java.util.regex.Pattern; import java.util.zip.ZipEntry; +import org.w3c.epubcheck.core.Checker; + import com.adobe.epubcheck.api.EPUBLocation; import com.adobe.epubcheck.api.Report; import com.adobe.epubcheck.ctc.epubpackage.EpubPackage; @@ -12,7 +14,6 @@ import com.adobe.epubcheck.ctc.xml.AnchorTagHandler; import com.adobe.epubcheck.ctc.xml.XMLContentDocParser; import com.adobe.epubcheck.messages.MessageId; -import com.adobe.epubcheck.opf.DocumentValidator; import com.adobe.epubcheck.util.PathUtil; import com.adobe.epubcheck.util.SearchDictionary; import com.adobe.epubcheck.util.SearchDictionary.DictionaryType; @@ -25,7 +26,7 @@ * Please keep changes minimal (bug fixes only) until then.
* ========================================================
*/ -public class EpubExtLinksCheck implements DocumentValidator +public class EpubExtLinksCheck implements Checker { private final Report report; private final EpubPackage epack; @@ -36,7 +37,7 @@ public EpubExtLinksCheck(EpubPackage epack, Report report) this.report = report; } - public boolean validate() + public void check() { SearchDictionary tsd = new SearchDictionary(DictionaryType.LINK_VALUES); SearchDictionary validTypes = new SearchDictionary(DictionaryType.VALID_TEXT_MEDIA_TYPES); @@ -98,7 +99,6 @@ public boolean validate() } } } - return true; } private void searchInsideValue(AnchorTagHandler.DocTagContent entry, SearchDictionary tds, String file) diff --git a/src/main/java/com/adobe/epubcheck/ctc/EpubHTML5StructureCheck.java b/src/main/java/com/adobe/epubcheck/ctc/EpubHTML5StructureCheck.java index 8b76f24fe..b5a6f5e57 100644 --- a/src/main/java/com/adobe/epubcheck/ctc/EpubHTML5StructureCheck.java +++ b/src/main/java/com/adobe/epubcheck/ctc/EpubHTML5StructureCheck.java @@ -9,6 +9,8 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipFile; +import org.w3c.epubcheck.core.Checker; + import com.adobe.epubcheck.api.EPUBLocation; import com.adobe.epubcheck.api.Report; import com.adobe.epubcheck.ctc.epubpackage.EpubPackage; @@ -18,7 +20,6 @@ import com.adobe.epubcheck.ctc.xml.XMLContentDocParser; import com.adobe.epubcheck.messages.MessageId; import com.adobe.epubcheck.ocf.EncryptionFilter; -import com.adobe.epubcheck.opf.DocumentValidator; import com.adobe.epubcheck.util.EPUBVersion; import com.adobe.epubcheck.util.FeatureEnum; import com.adobe.epubcheck.util.SearchDictionary; @@ -31,7 +32,7 @@ * Please keep changes minimal (bug fixes only) until then.
* ========================================================
*/ -public class EpubHTML5StructureCheck implements DocumentValidator +public class EpubHTML5StructureCheck implements Checker { static final int hasHtml = 1; static final int hasPublic = 2; @@ -54,7 +55,7 @@ public EpubHTML5StructureCheck(EpubPackage epack, Report report) } @Override - public boolean validate() + public void check() { boolean result = false; SearchDictionary vtsd = new SearchDictionary(DictionaryType.VALID_TEXT_MEDIA_TYPES); @@ -155,7 +156,6 @@ else if ((0 != (docTypeMatches & hasHTML5)) && ((hasXhtml != (docTypeMatches & h } } - return result; } InputStream getInputStream(String name) throws diff --git a/src/main/java/com/adobe/epubcheck/ctc/EpubLangCheck.java b/src/main/java/com/adobe/epubcheck/ctc/EpubLangCheck.java index c14196e8b..a42293f67 100644 --- a/src/main/java/com/adobe/epubcheck/ctc/EpubLangCheck.java +++ b/src/main/java/com/adobe/epubcheck/ctc/EpubLangCheck.java @@ -3,6 +3,8 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipFile; +import org.w3c.epubcheck.core.Checker; + import com.adobe.epubcheck.api.EPUBLocation; import com.adobe.epubcheck.api.Report; import com.adobe.epubcheck.ctc.epubpackage.EpubPackage; @@ -10,7 +12,6 @@ import com.adobe.epubcheck.ctc.xml.LangAttributeHandler; import com.adobe.epubcheck.ctc.xml.XMLContentDocParser; import com.adobe.epubcheck.messages.MessageId; -import com.adobe.epubcheck.opf.DocumentValidator; import com.adobe.epubcheck.util.SearchDictionary; import com.adobe.epubcheck.util.SearchDictionary.DictionaryType; @@ -21,7 +22,7 @@ * Please keep changes minimal (bug fixes only) until then.
* ========================================================
*/ -public class EpubLangCheck implements DocumentValidator +public class EpubLangCheck implements Checker { private final ZipFile zip; private final Report report; @@ -35,7 +36,7 @@ public EpubLangCheck(EpubPackage epack, Report report) } @Override - public boolean validate() + public void check() { boolean result = false; SearchDictionary vtsd = new SearchDictionary(DictionaryType.VALID_TEXT_MEDIA_TYPES); @@ -88,7 +89,6 @@ public boolean validate() } } } - return result; } private boolean isValidLanguageDefinition(String language) diff --git a/src/main/java/com/adobe/epubcheck/ctc/EpubMetaDataV2Check.java b/src/main/java/com/adobe/epubcheck/ctc/EpubMetaDataV2Check.java index b0773e3b3..c1c138c26 100644 --- a/src/main/java/com/adobe/epubcheck/ctc/EpubMetaDataV2Check.java +++ b/src/main/java/com/adobe/epubcheck/ctc/EpubMetaDataV2Check.java @@ -1,10 +1,10 @@ package com.adobe.epubcheck.ctc; import org.w3c.dom.Document; +import org.w3c.epubcheck.core.Checker; import com.adobe.epubcheck.api.Report; import com.adobe.epubcheck.ctc.epubpackage.EpubPackage; -import com.adobe.epubcheck.opf.DocumentValidator; /** * === WARNING ==========================================
@@ -13,7 +13,7 @@ * Please keep changes minimal (bug fixes only) until then.
* ========================================================
*/ -public class EpubMetaDataV2Check implements DocumentValidator +public class EpubMetaDataV2Check implements Checker { private final Document doc; private final String pathRootFile; @@ -28,13 +28,13 @@ public EpubMetaDataV2Check(EpubPackage epack, Report report) } @Override - public boolean validate() + public void check() { - return isMetaDataValid(doc, pathRootFile); + isMetaDataValid(doc, pathRootFile); } - private boolean isMetaDataValid(Document doc, String pathRootFile) + private void isMetaDataValid(Document doc, String pathRootFile) { - return true; // no custom checks + // no custom checks } } diff --git a/src/main/java/com/adobe/epubcheck/ctc/EpubMetaDataV3Check.java b/src/main/java/com/adobe/epubcheck/ctc/EpubMetaDataV3Check.java index e51f6fb75..078a9ea94 100644 --- a/src/main/java/com/adobe/epubcheck/ctc/EpubMetaDataV3Check.java +++ b/src/main/java/com/adobe/epubcheck/ctc/EpubMetaDataV3Check.java @@ -1,10 +1,10 @@ package com.adobe.epubcheck.ctc; import org.w3c.dom.Document; +import org.w3c.epubcheck.core.Checker; import com.adobe.epubcheck.api.Report; import com.adobe.epubcheck.ctc.epubpackage.EpubPackage; -import com.adobe.epubcheck.opf.DocumentValidator; /** * === WARNING ==========================================
@@ -13,7 +13,7 @@ * Please keep changes minimal (bug fixes only) until then.
* ========================================================
*/ -public class EpubMetaDataV3Check implements DocumentValidator +public class EpubMetaDataV3Check implements Checker { private final Document doc; @@ -29,13 +29,13 @@ public EpubMetaDataV3Check(EpubPackage epack, Report report) } @Override - public boolean validate() + public void check() { - return isMetaDataValid(doc, pathRootFile); + isMetaDataValid(doc, pathRootFile); } - private boolean isMetaDataValid(Document doc, String pathRootFile) + private void isMetaDataValid(Document doc, String pathRootFile) { - return true; // no custom checks + // no custom checks } } diff --git a/src/main/java/com/adobe/epubcheck/ctc/EpubNCXCheck.java b/src/main/java/com/adobe/epubcheck/ctc/EpubNCXCheck.java index c7b962af1..4d940f277 100644 --- a/src/main/java/com/adobe/epubcheck/ctc/EpubNCXCheck.java +++ b/src/main/java/com/adobe/epubcheck/ctc/EpubNCXCheck.java @@ -7,6 +7,7 @@ import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.NodeList; +import org.w3c.epubcheck.core.Checker; import com.adobe.epubcheck.api.EPUBLocation; import com.adobe.epubcheck.api.Report; @@ -16,7 +17,6 @@ import com.adobe.epubcheck.ctc.epubpackage.PackageSpine; import com.adobe.epubcheck.ctc.epubpackage.SpineItem; import com.adobe.epubcheck.messages.MessageId; -import com.adobe.epubcheck.opf.DocumentValidator; import com.adobe.epubcheck.reporting.CheckingReport; import com.adobe.epubcheck.util.EPUBVersion; import com.adobe.epubcheck.util.EpubConstants; @@ -30,7 +30,7 @@ * Please keep changes minimal (bug fixes only) until then.
* ========================================================
*/ -public class EpubNCXCheck implements DocumentValidator +public class EpubNCXCheck implements Checker { private final XmlDocParser docParser; private final Document doc; @@ -50,7 +50,7 @@ public EpubNCXCheck(EpubPackage epack, Report report) } @Override - public boolean validate() + public void check() { boolean result = isNCXDefined(doc); if (result) @@ -71,7 +71,6 @@ public boolean validate() } } - return result; } private boolean isNCXDefined(Document doc) diff --git a/src/main/java/com/adobe/epubcheck/ctc/EpubNavCheck.java b/src/main/java/com/adobe/epubcheck/ctc/EpubNavCheck.java index 08332d3e3..b4ba8870b 100644 --- a/src/main/java/com/adobe/epubcheck/ctc/EpubNavCheck.java +++ b/src/main/java/com/adobe/epubcheck/ctc/EpubNavCheck.java @@ -10,6 +10,7 @@ import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.NodeList; +import org.w3c.epubcheck.core.Checker; import com.adobe.epubcheck.api.EPUBLocation; import com.adobe.epubcheck.api.Report; @@ -19,7 +20,6 @@ import com.adobe.epubcheck.ctc.epubpackage.PackageSpine; import com.adobe.epubcheck.ctc.epubpackage.SpineItem; import com.adobe.epubcheck.messages.MessageId; -import com.adobe.epubcheck.opf.DocumentValidator; import com.adobe.epubcheck.util.EpubConstants; import com.adobe.epubcheck.util.FeatureEnum; import com.adobe.epubcheck.util.HandlerUtil; @@ -32,7 +32,7 @@ * Please keep changes minimal (bug fixes only) until then.
* ========================================================
*/ -public class EpubNavCheck implements DocumentValidator +public class EpubNavCheck implements Checker { private final XmlDocParser docParser; @@ -51,7 +51,7 @@ public EpubNavCheck(EpubPackage epack, Report report) @Override - public boolean validate() + public void check() { boolean result = false; Vector navDocPath = getNAVDocuments(packageMainDocument); @@ -84,8 +84,6 @@ public boolean validate() } } } - - return result; } private Vector getNAVDocuments(Document doc) diff --git a/src/main/java/com/adobe/epubcheck/ctc/EpubRenditionCheck.java b/src/main/java/com/adobe/epubcheck/ctc/EpubRenditionCheck.java index 817907290..601c2cff5 100644 --- a/src/main/java/com/adobe/epubcheck/ctc/EpubRenditionCheck.java +++ b/src/main/java/com/adobe/epubcheck/ctc/EpubRenditionCheck.java @@ -1,14 +1,15 @@ package com.adobe.epubcheck.ctc; -import com.adobe.epubcheck.api.Report; -import com.adobe.epubcheck.ctc.epubpackage.EpubPackage; -import com.adobe.epubcheck.ctc.epubpackage.ManifestItem; -import com.adobe.epubcheck.opf.DocumentValidator; -import com.adobe.epubcheck.util.FeatureEnum; import org.w3c.dom.Document; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.NodeList; +import org.w3c.epubcheck.core.Checker; + +import com.adobe.epubcheck.api.Report; +import com.adobe.epubcheck.ctc.epubpackage.EpubPackage; +import com.adobe.epubcheck.ctc.epubpackage.ManifestItem; +import com.adobe.epubcheck.util.FeatureEnum; /** * === WARNING ==========================================
@@ -17,7 +18,7 @@ * Please keep changes minimal (bug fixes only) until then.
* ========================================================
*/ -public class EpubRenditionCheck implements DocumentValidator +public class EpubRenditionCheck implements Checker { private final Document doc; private final EpubPackage epack; @@ -31,12 +32,12 @@ public EpubRenditionCheck(EpubPackage epack, Report report) } @Override - public boolean validate() + public void check() { - return isRenditionDefined(doc); + isRenditionDefined(doc); } - private boolean isRenditionDefined(Document doc) + private void isRenditionDefined(Document doc) { boolean result = false; NodeList nList = doc.getElementsByTagName("metadata"); @@ -146,6 +147,5 @@ private boolean isRenditionDefined(Document doc) } } } - return result; } } diff --git a/src/main/java/com/adobe/epubcheck/ctc/EpubSVGCheck.java b/src/main/java/com/adobe/epubcheck/ctc/EpubSVGCheck.java index 6ad510fe3..b77631772 100644 --- a/src/main/java/com/adobe/epubcheck/ctc/EpubSVGCheck.java +++ b/src/main/java/com/adobe/epubcheck/ctc/EpubSVGCheck.java @@ -6,6 +6,7 @@ import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; +import org.w3c.epubcheck.core.Checker; import com.adobe.epubcheck.api.EPUBLocation; import com.adobe.epubcheck.api.Report; @@ -13,7 +14,6 @@ import com.adobe.epubcheck.ctc.epubpackage.ManifestItem; import com.adobe.epubcheck.ctc.epubpackage.SpineItem; import com.adobe.epubcheck.messages.MessageId; -import com.adobe.epubcheck.opf.DocumentValidator; import com.adobe.epubcheck.util.SearchDictionary; /** @@ -23,7 +23,7 @@ * Please keep changes minimal (bug fixes only) until then.
* ========================================================
*/ -public class EpubSVGCheck implements DocumentValidator +public class EpubSVGCheck implements Checker { private static final String svgNS = "http://www.w3.org/2000/svg"; private static final String xlinkNS = "http://www.w3.org/1999/xlink"; @@ -42,7 +42,7 @@ public EpubSVGCheck(EpubPackage epack, Report report) } @Override - public boolean validate() + public void check() { SearchDictionary validTypes = new SearchDictionary(SearchDictionary.DictionaryType.SVG_MEDIA_TYPES); @@ -103,7 +103,6 @@ else if (prop.equals("rendition:layout-reflowable")) } } } - return true; } void checkSvgDoc(String svgDocEntry) diff --git a/src/main/java/com/adobe/epubcheck/ctc/EpubScriptCheck.java b/src/main/java/com/adobe/epubcheck/ctc/EpubScriptCheck.java index 82cb8acda..ee8bdbe5e 100644 --- a/src/main/java/com/adobe/epubcheck/ctc/EpubScriptCheck.java +++ b/src/main/java/com/adobe/epubcheck/ctc/EpubScriptCheck.java @@ -10,6 +10,8 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipFile; +import org.w3c.epubcheck.core.Checker; + import com.adobe.epubcheck.api.EPUBLocation; import com.adobe.epubcheck.api.Report; import com.adobe.epubcheck.ctc.epubpackage.EpubPackage; @@ -18,7 +20,6 @@ import com.adobe.epubcheck.ctc.xml.XMLContentDocParser; import com.adobe.epubcheck.messages.MessageId; import com.adobe.epubcheck.opf.OPFChecker30; -import com.adobe.epubcheck.opf.DocumentValidator; import com.adobe.epubcheck.util.EPUBVersion; import com.adobe.epubcheck.util.FeatureEnum; import com.adobe.epubcheck.util.SearchDictionary; @@ -31,7 +32,7 @@ * Please keep changes minimal (bug fixes only) until then.
* ========================================================
*/ -public class EpubScriptCheck implements DocumentValidator +public class EpubScriptCheck implements Checker { private final ZipFile zip; private final Report report; @@ -45,7 +46,7 @@ public EpubScriptCheck(EpubPackage epack, Report report) } @Override - public boolean validate() + public void check() { boolean result = false; SearchDictionary vtsd = new SearchDictionary(DictionaryType.VALID_TEXT_MEDIA_TYPES); @@ -90,7 +91,6 @@ public boolean validate() checkJavascript(mi); } - return result; } void checkJavascript(ManifestItem mi) diff --git a/src/main/java/com/adobe/epubcheck/ctc/EpubSpanCheck.java b/src/main/java/com/adobe/epubcheck/ctc/EpubSpanCheck.java index 02807b77e..e6f064419 100644 --- a/src/main/java/com/adobe/epubcheck/ctc/EpubSpanCheck.java +++ b/src/main/java/com/adobe/epubcheck/ctc/EpubSpanCheck.java @@ -3,6 +3,8 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipFile; +import org.w3c.epubcheck.core.Checker; + import com.adobe.epubcheck.api.EPUBLocation; import com.adobe.epubcheck.api.Report; import com.adobe.epubcheck.ctc.epubpackage.EpubPackage; @@ -10,7 +12,6 @@ import com.adobe.epubcheck.ctc.xml.SpanTagHandler; import com.adobe.epubcheck.ctc.xml.XMLContentDocParser; import com.adobe.epubcheck.messages.MessageId; -import com.adobe.epubcheck.opf.DocumentValidator; import com.adobe.epubcheck.util.SearchDictionary; import com.adobe.epubcheck.util.SearchDictionary.DictionaryType; @@ -21,7 +22,7 @@ * Please keep changes minimal (bug fixes only) until then.
* ========================================================
*/ -public class EpubSpanCheck implements DocumentValidator +public class EpubSpanCheck implements Checker { private final ZipFile zip; private final Report report; @@ -35,7 +36,7 @@ public EpubSpanCheck(EpubPackage epack, Report report) } @Override - public boolean validate() + public void check() { boolean result = false; SearchDictionary vtsd = new SearchDictionary(DictionaryType.VALID_TEXT_MEDIA_TYPES); @@ -64,6 +65,5 @@ public boolean validate() } } } - return result; } } diff --git a/src/main/java/com/adobe/epubcheck/ctc/EpubSpineCheck.java b/src/main/java/com/adobe/epubcheck/ctc/EpubSpineCheck.java index de3729be8..c13208a53 100644 --- a/src/main/java/com/adobe/epubcheck/ctc/EpubSpineCheck.java +++ b/src/main/java/com/adobe/epubcheck/ctc/EpubSpineCheck.java @@ -1,19 +1,19 @@ package com.adobe.epubcheck.ctc; +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.w3c.epubcheck.core.Checker; + import com.adobe.epubcheck.api.EPUBLocation; import com.adobe.epubcheck.api.Report; import com.adobe.epubcheck.ctc.epubpackage.EpubPackage; import com.adobe.epubcheck.ctc.epubpackage.MetadataElement; import com.adobe.epubcheck.ctc.epubpackage.SpineItem; import com.adobe.epubcheck.messages.MessageId; -import com.adobe.epubcheck.opf.DocumentValidator; import com.adobe.epubcheck.util.EpubConstants; import com.adobe.epubcheck.util.outWriter; -import org.w3c.dom.Document; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - /** * === WARNING ==========================================
* This class is scheduled to be refactored and integrated
@@ -21,7 +21,7 @@ * Please keep changes minimal (bug fixes only) until then.
* ========================================================
*/ -public class EpubSpineCheck implements DocumentValidator +public class EpubSpineCheck implements Checker { private static final int MAX_SPINE_ITEM_THRESHOLD = 100; private final EpubPackage epubPack; @@ -37,12 +37,10 @@ public EpubSpineCheck(EpubPackage epubPack, Report report) this.report = report; } - public boolean validate() + public void check() { - boolean resExists = isSpineDefined(doc, pathRootFile); - boolean resElements = tooManySpineElements(doc, pathRootFile, MAX_SPINE_ITEM_THRESHOLD); - - return (resExists && resElements); + isSpineDefined(doc, pathRootFile); + tooManySpineElements(doc, pathRootFile, MAX_SPINE_ITEM_THRESHOLD); } private boolean isSpineDefined(Document doc, String pathRootFile) diff --git a/src/main/java/com/adobe/epubcheck/ctc/EpubStyleSheetsCheck.java b/src/main/java/com/adobe/epubcheck/ctc/EpubStyleSheetsCheck.java index 58cd7c687..bedc52c0b 100644 --- a/src/main/java/com/adobe/epubcheck/ctc/EpubStyleSheetsCheck.java +++ b/src/main/java/com/adobe/epubcheck/ctc/EpubStyleSheetsCheck.java @@ -2,12 +2,13 @@ import java.util.zip.ZipEntry; +import org.w3c.epubcheck.core.Checker; + import com.adobe.epubcheck.api.Report; import com.adobe.epubcheck.ctc.epubpackage.EpubPackage; import com.adobe.epubcheck.ctc.epubpackage.ManifestItem; import com.adobe.epubcheck.ctc.xml.LinkTagHandler; import com.adobe.epubcheck.ctc.xml.XMLContentDocParser; -import com.adobe.epubcheck.opf.DocumentValidator; import com.adobe.epubcheck.util.SearchDictionary; import com.adobe.epubcheck.util.SearchDictionary.DictionaryType; @@ -18,7 +19,7 @@ * Please keep changes minimal (bug fixes only) until then.
* ========================================================
*/ -public class EpubStyleSheetsCheck implements DocumentValidator +public class EpubStyleSheetsCheck implements Checker { private final Report report; private final EpubPackage epack; @@ -29,7 +30,7 @@ public EpubStyleSheetsCheck(EpubPackage epack, Report report) this.report = report; } - public boolean validate() + public void check() { SearchDictionary validTypes = new SearchDictionary(DictionaryType.VALID_TEXT_MEDIA_TYPES); @@ -56,7 +57,6 @@ public boolean validate() h.checkForMultipleStyleSheets(fileToParse); } } - return true; } } diff --git a/src/main/java/com/adobe/epubcheck/ctc/EpubTextContentCheck.java b/src/main/java/com/adobe/epubcheck/ctc/EpubTextContentCheck.java index 6ded0619f..24ecf1910 100644 --- a/src/main/java/com/adobe/epubcheck/ctc/EpubTextContentCheck.java +++ b/src/main/java/com/adobe/epubcheck/ctc/EpubTextContentCheck.java @@ -4,10 +4,11 @@ import java.util.List; import java.util.zip.ZipEntry; +import org.w3c.epubcheck.core.Checker; + import com.adobe.epubcheck.api.Report; import com.adobe.epubcheck.ctc.epubpackage.EpubPackage; import com.adobe.epubcheck.ctc.epubpackage.ManifestItem; -import com.adobe.epubcheck.opf.DocumentValidator; import com.adobe.epubcheck.util.SearchDictionary; import com.adobe.epubcheck.util.SearchDictionary.DictionaryType; @@ -18,7 +19,7 @@ * Please keep changes minimal (bug fixes only) until then.
* ========================================================
*/ -public class EpubTextContentCheck implements DocumentValidator +public class EpubTextContentCheck implements Checker { private final Report report; private final EpubPackage epack; @@ -33,7 +34,7 @@ public EpubTextContentCheck(Report report, EpubPackage epack) this.report = report; } - public boolean validate() + public void check() { SearchDictionary validScriptTypes = new SearchDictionary(DictionaryType.VALID_TEXT_MEDIA_TYPES); @@ -58,7 +59,6 @@ public boolean validate() } } } - return true; } } diff --git a/src/main/java/com/adobe/epubcheck/ctc/EpubTocCheck.java b/src/main/java/com/adobe/epubcheck/ctc/EpubTocCheck.java index fd9a8d995..c1b7fb9ca 100644 --- a/src/main/java/com/adobe/epubcheck/ctc/EpubTocCheck.java +++ b/src/main/java/com/adobe/epubcheck/ctc/EpubTocCheck.java @@ -1,11 +1,12 @@ package com.adobe.epubcheck.ctc; +import org.w3c.epubcheck.core.Checker; + import com.adobe.epubcheck.api.EPUBLocation; import com.adobe.epubcheck.api.Report; import com.adobe.epubcheck.ctc.epubpackage.EpubPackage; import com.adobe.epubcheck.ctc.epubpackage.PackageSpine; import com.adobe.epubcheck.messages.MessageId; -import com.adobe.epubcheck.opf.DocumentValidator; import com.adobe.epubcheck.util.EPUBVersion; /** @@ -15,7 +16,7 @@ * Please keep changes minimal (bug fixes only) until then.
* ========================================================
*/ -public class EpubTocCheck implements DocumentValidator +public class EpubTocCheck implements Checker { private final String pathRootFile; private final EpubPackage epack; @@ -29,7 +30,7 @@ public EpubTocCheck(EpubPackage epack, Report report) } @Override - public boolean validate() + public void check() { boolean result = true; PackageSpine spine = epack.getSpine(); @@ -38,6 +39,5 @@ public boolean validate() report.message(MessageId.NCX_002, EPUBLocation.create(pathRootFile)); result = false; } - return result; } } diff --git a/src/main/java/com/adobe/epubcheck/dict/SearchKeyMapChecker.java b/src/main/java/com/adobe/epubcheck/dict/SearchKeyMapChecker.java index e8325693d..bd70785cb 100644 --- a/src/main/java/com/adobe/epubcheck/dict/SearchKeyMapChecker.java +++ b/src/main/java/com/adobe/epubcheck/dict/SearchKeyMapChecker.java @@ -23,65 +23,38 @@ package com.adobe.epubcheck.dict; import com.adobe.epubcheck.api.EPUBLocation; -import com.adobe.epubcheck.api.Report; import com.adobe.epubcheck.messages.MessageId; -import com.adobe.epubcheck.ocf.OCFPackage; -import com.adobe.epubcheck.opf.ContentChecker; -import com.adobe.epubcheck.opf.DocumentValidator; +import com.adobe.epubcheck.opf.PublicationResourceChecker; import com.adobe.epubcheck.opf.ValidationContext; import com.adobe.epubcheck.xml.XMLParser; import com.adobe.epubcheck.xml.XMLValidators; import com.google.common.base.Preconditions; -public class SearchKeyMapChecker implements ContentChecker, DocumentValidator +public class SearchKeyMapChecker extends PublicationResourceChecker { - private final ValidationContext context; - private final Report report; - private final String path; public SearchKeyMapChecker(ValidationContext context) { + super(context); Preconditions.checkState("application/vnd.epub.search-key-map+xml".equals(context.mimeType)); - this.context = context; - this.report = context.report; - this.path = context.path; } - public void runChecks() + @Override + protected boolean checkContent() { - OCFPackage ocf = context.ocf.get(); - if (!ocf.hasEntry(path)) + // File check + if (!context.path.endsWith(".xml")) { - report.message(MessageId.RSC_001, EPUBLocation.create(ocf.getName()), path); + report.message(MessageId.OPF_080, EPUBLocation.create(context.path)); } - else if (!ocf.canDecrypt(path)) - { - report.message(MessageId.RSC_004, EPUBLocation.create(ocf.getName()), path); - } - else if (!path.endsWith(".xml")) - { - report.message(MessageId.OPF_080, EPUBLocation.create(path)); - } - else - { - validate(); - } - } - - public boolean validate() - { - int fatalErrorsSoFar = report.getFatalErrorCount(); - int errorsSoFar = report.getErrorCount(); - int warningsSoFar = report.getWarningCount(); + // Content checks SearchKeyMapHandler handler; XMLParser parser = new XMLParser(context); handler = new SearchKeyMapHandler(context, parser); parser.addValidator(XMLValidators.SEARCH_KEY_MAP_RNC.get()); parser.addXMLHandler(handler); parser.process(); - - return fatalErrorsSoFar == report.getFatalErrorCount() && errorsSoFar == report.getErrorCount() - && warningsSoFar == report.getWarningCount(); + return true; } } diff --git a/src/main/java/com/adobe/epubcheck/dict/SearchKeyMapCheckerFactory.java b/src/main/java/com/adobe/epubcheck/dict/SearchKeyMapCheckerFactory.java deleted file mode 100644 index fb7165882..000000000 --- a/src/main/java/com/adobe/epubcheck/dict/SearchKeyMapCheckerFactory.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2011 Adobe Systems Incorporated - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - */ - -package com.adobe.epubcheck.dict; - -import com.adobe.epubcheck.opf.ContentCheckerFactory; -import com.adobe.epubcheck.opf.DocumentValidatorFactory; -import com.adobe.epubcheck.opf.ValidationContext; - -public class SearchKeyMapCheckerFactory implements ContentCheckerFactory, DocumentValidatorFactory -{ - static private final SearchKeyMapCheckerFactory instance = new SearchKeyMapCheckerFactory(); - - public SearchKeyMapChecker newInstance(ValidationContext context) - { - return new SearchKeyMapChecker(context); - } - - static public SearchKeyMapCheckerFactory getInstance() - { - return instance; - } - -} diff --git a/src/main/java/com/adobe/epubcheck/dtbook/DTBookChecker.java b/src/main/java/com/adobe/epubcheck/dtbook/DTBookChecker.java index edd27e2ba..c774b11a1 100755 --- a/src/main/java/com/adobe/epubcheck/dtbook/DTBookChecker.java +++ b/src/main/java/com/adobe/epubcheck/dtbook/DTBookChecker.java @@ -22,49 +22,30 @@ package com.adobe.epubcheck.dtbook; -import com.adobe.epubcheck.api.EPUBLocation; -import com.adobe.epubcheck.api.Report; -import com.adobe.epubcheck.messages.MessageId; -import com.adobe.epubcheck.ocf.OCFPackage; -import com.adobe.epubcheck.opf.ContentChecker; +import com.adobe.epubcheck.opf.PublicationResourceChecker; import com.adobe.epubcheck.opf.ValidationContext; import com.adobe.epubcheck.xml.XMLParser; import com.adobe.epubcheck.xml.XMLValidators; import com.google.common.base.Preconditions; -public class DTBookChecker implements ContentChecker +public class DTBookChecker extends PublicationResourceChecker { - private final ValidationContext context; - private final Report report; - private final String path; public DTBookChecker(ValidationContext context) { + super(context); Preconditions.checkState("application/x-dtbook+xml".equals(context.mimeType)); - this.context = context; - this.report = context.report; - this.path = context.path; } - public void runChecks() + @Override + protected boolean checkContent() { - OCFPackage ocf = context.ocf.get(); - if (!ocf.hasEntry(path)) - { - report.message(MessageId.RSC_001, EPUBLocation.create(ocf.getName()), path); - } - else if (!ocf.canDecrypt(path)) - { - report.message(MessageId.RSC_004, EPUBLocation.create(ocf.getName()), path); - } - else - { - XMLParser dtbookParser = new XMLParser(context); - dtbookParser.addValidator(XMLValidators.DTBOOK_RNG.get()); - DTBookHandler dtbookHandler = new DTBookHandler(dtbookParser, path, context.xrefChecker.get()); - dtbookParser.addXMLHandler(dtbookHandler); - dtbookParser.process(); - } + XMLParser dtbookParser = new XMLParser(context); + dtbookParser.addValidator(XMLValidators.DTBOOK_RNG.get()); + DTBookHandler dtbookHandler = new DTBookHandler(dtbookParser, context.path, context.xrefChecker.get()); + dtbookParser.addXMLHandler(dtbookHandler); + dtbookParser.process(); + return true; } } diff --git a/src/main/java/com/adobe/epubcheck/dtbook/DTBookCheckerFactory.java b/src/main/java/com/adobe/epubcheck/dtbook/DTBookCheckerFactory.java deleted file mode 100755 index a8c80eb27..000000000 --- a/src/main/java/com/adobe/epubcheck/dtbook/DTBookCheckerFactory.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2007 Adobe Systems Incorporated - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - */ - -package com.adobe.epubcheck.dtbook; - -import com.adobe.epubcheck.opf.ContentChecker; -import com.adobe.epubcheck.opf.ContentCheckerFactory; -import com.adobe.epubcheck.opf.ValidationContext; - -public class DTBookCheckerFactory implements ContentCheckerFactory -{ - public ContentChecker newInstance(ValidationContext context) - { - return new DTBookChecker(context); - } - - static private final DTBookCheckerFactory instance = new DTBookCheckerFactory(); - - static public DTBookCheckerFactory getInstance() - { - return instance; - } -} diff --git a/src/main/java/com/adobe/epubcheck/nav/NavChecker.java b/src/main/java/com/adobe/epubcheck/nav/NavChecker.java index a65525898..a7d7fffb6 100644 --- a/src/main/java/com/adobe/epubcheck/nav/NavChecker.java +++ b/src/main/java/com/adobe/epubcheck/nav/NavChecker.java @@ -22,15 +22,19 @@ package com.adobe.epubcheck.nav; -import static com.adobe.epubcheck.opf.ValidationContext.ValidationContextPredicates.*; -import static com.google.common.base.Predicates.*; +import static com.adobe.epubcheck.opf.ValidationContext.ValidationContextPredicates.hasProp; +import static com.adobe.epubcheck.opf.ValidationContext.ValidationContextPredicates.hasPubType; +import static com.adobe.epubcheck.opf.ValidationContext.ValidationContextPredicates.mimetype; +import static com.adobe.epubcheck.opf.ValidationContext.ValidationContextPredicates.profile; +import static com.adobe.epubcheck.opf.ValidationContext.ValidationContextPredicates.version; +import static com.google.common.base.Predicates.and; +import static com.google.common.base.Predicates.not; +import static com.google.common.base.Predicates.or; import com.adobe.epubcheck.api.EPUBLocation; import com.adobe.epubcheck.api.EPUBProfile; -import com.adobe.epubcheck.api.Report; import com.adobe.epubcheck.messages.MessageId; -import com.adobe.epubcheck.opf.ContentChecker; -import com.adobe.epubcheck.opf.DocumentValidator; +import com.adobe.epubcheck.opf.PublicationResourceChecker; import com.adobe.epubcheck.opf.OPFData; import com.adobe.epubcheck.opf.ValidationContext; import com.adobe.epubcheck.util.EPUBVersion; @@ -44,10 +48,9 @@ import com.google.common.base.Preconditions; import com.google.common.base.Predicates; -public class NavChecker implements ContentChecker, DocumentValidator +public class NavChecker extends PublicationResourceChecker { - @SuppressWarnings("unchecked") private final static ValidatorMap validatorMap = ValidatorMap.builder() .putAll(XMLValidators.NAV_30_RNC, XMLValidators.XHTML_30_SCH, XMLValidators.NAV_30_SCH) .putAll( @@ -67,46 +70,22 @@ public class NavChecker implements ContentChecker, DocumentValidator XMLValidators.XHTML_IDX_SCH, XMLValidators.XHTML_IDX_INDEX_SCH) .build(); - private final ValidationContext context; - private final Report report; - private final String path; public NavChecker(ValidationContext context) { + super(context); Preconditions.checkState("application/xhtml+xml".equals(context.mimeType)); - this.context = context; - this.report = context.report; - this.path = context.path; if (context.version == EPUBVersion.VERSION_2) { - context.report.message(MessageId.NAV_001, EPUBLocation.create(path)); + context.report.message(MessageId.NAV_001, EPUBLocation.create(context.path)); } } @Override - public void runChecks() + protected boolean checkContent() { - if (!context.ocf.get().hasEntry(path)) - { - report.message(MessageId.RSC_001, EPUBLocation.create(context.ocf.get().getName()), path); - } - else if (!context.ocf.get().canDecrypt(path)) - { - report.message(MessageId.RSC_004, EPUBLocation.create(context.ocf.get().getName()), path); - } - else - { - validate(); - } - } - - public boolean validate() - { - int fatalErrors = report.getFatalErrorCount(); - int errors = report.getErrorCount(); - int warnings = report.getWarningCount(); XMLParser navParser = new XMLParser(context); - + XMLHandler navHandler = new NavHandler(context, navParser); navParser.addXMLHandler(navHandler); for (XMLValidator validator : validatorMap.getValidators(context)) @@ -114,8 +93,7 @@ public boolean validate() navParser.addValidator(validator); } navParser.process(); - - return ((fatalErrors == report.getFatalErrorCount()) && (errors == report.getErrorCount()) - && (warnings == report.getWarningCount())); + return true; } + } diff --git a/src/main/java/com/adobe/epubcheck/nav/NavCheckerFactory.java b/src/main/java/com/adobe/epubcheck/nav/NavCheckerFactory.java deleted file mode 100644 index e74f65b75..000000000 --- a/src/main/java/com/adobe/epubcheck/nav/NavCheckerFactory.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2011 Adobe Systems Incorporated - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - */ - -package com.adobe.epubcheck.nav; - -import com.adobe.epubcheck.opf.ContentCheckerFactory; -import com.adobe.epubcheck.opf.DocumentValidatorFactory; -import com.adobe.epubcheck.opf.ValidationContext; - -public class NavCheckerFactory implements ContentCheckerFactory, DocumentValidatorFactory -{ - static private final NavCheckerFactory instance = new NavCheckerFactory(); - - public NavChecker newInstance(ValidationContext context) - { - return new NavChecker(context); - } - - static public NavCheckerFactory getInstance() - { - return instance; - } - -} diff --git a/src/main/java/com/adobe/epubcheck/ncx/NCXChecker.java b/src/main/java/com/adobe/epubcheck/ncx/NCXChecker.java index 357e3fa35..256ff3fda 100755 --- a/src/main/java/com/adobe/epubcheck/ncx/NCXChecker.java +++ b/src/main/java/com/adobe/epubcheck/ncx/NCXChecker.java @@ -23,65 +23,56 @@ package com.adobe.epubcheck.ncx; import com.adobe.epubcheck.api.EPUBLocation; -import com.adobe.epubcheck.api.Report; import com.adobe.epubcheck.messages.MessageId; -import com.adobe.epubcheck.ocf.OCFPackage; -import com.adobe.epubcheck.opf.ContentChecker; +import com.adobe.epubcheck.opf.PublicationResourceChecker; import com.adobe.epubcheck.opf.ValidationContext; import com.adobe.epubcheck.xml.XMLParser; import com.adobe.epubcheck.xml.XMLValidators; import com.google.common.base.Preconditions; -public class NCXChecker implements ContentChecker +public class NCXChecker extends PublicationResourceChecker { - private final ValidationContext context; - private final Report report; - private final String path; + + private String ncxId = null; public NCXChecker(ValidationContext context) { + super(context); Preconditions.checkState("application/x-dtbncx+xml".equals(context.mimeType)); - this.context = context; - this.report = context.report; - this.path = context.path; } - public void runChecks() - { - OCFPackage ocf = context.ocf.get(); - if (!ocf.hasEntry(path)) - { - report.message(MessageId.RSC_001, EPUBLocation.create(ocf.getName()), path); - } - else if (!ocf.canDecrypt(path)) + @Override + protected boolean checkContent() + { + // relaxng + XMLParser ncxParser; + NCXHandler ncxHandler; + + ncxParser = new XMLParser(context); + ncxParser.addValidator(XMLValidators.NCX_RNG.get()); + ncxParser.addValidator(XMLValidators.NCX_SCH.get()); + ncxHandler = new NCXHandler(ncxParser, context.path, context.xrefChecker.get()); + ncxParser.addXMLHandler(ncxHandler); + ncxParser.process(); + + // report this for EPUB2 and ALSO for EPUB3 (see discussion in #669) + ncxId = ncxHandler.getUid(); + if (ncxId != null && !ncxId.equals(ncxId.trim())) { - report.message(MessageId.RSC_004, EPUBLocation.create(ocf.getName()), path); + report.message(MessageId.NCX_004, EPUBLocation.create(context.path)); } - else + return true; + } + + @Override + protected boolean checkPublicationAfterContent() { + // Check that the ID matches the OPF’s ID + // TODO improve way to get this EPUB 2's single OPF + String uid = context.ocf.get().getOpfData().values().iterator().next().getUniqueIdentifier(); + if (uid != null && ncxId != null && !uid.equals(ncxId.trim())) { - // relaxng - XMLParser ncxParser; - NCXHandler ncxHandler; - - ncxParser = new XMLParser(context); - ncxParser.addValidator(XMLValidators.NCX_RNG.get()); - ncxParser.addValidator(XMLValidators.NCX_SCH.get()); - ncxHandler = new NCXHandler(ncxParser, path, context.xrefChecker.get()); - ncxParser.addXMLHandler(ncxHandler); - ncxParser.process(); - - // report this for EPUB2 and ALSO for EPUB3 (see discussion in #669) - String ncxId = ncxHandler.getUid(); - if (ncxId != null && !ncxId.equals(ncxId.trim())) - { - report.message(MessageId.NCX_004, ncxParser.getLocation()); - } - // FIXME improve way to get this EPUB 2's single OPF - String uid = ocf.getOpfData().values().iterator().next().getUniqueIdentifier(); - if (uid != null && ncxId != null && !uid.equals(ncxId.trim())) - { - report.message(MessageId.NCX_001, ncxParser.getLocation(), ncxHandler.getUid(), uid); - } + report.message(MessageId.NCX_001, EPUBLocation.create(context.path), ncxId, uid); } + return true; } } diff --git a/src/main/java/com/adobe/epubcheck/ncx/NCXCheckerFactory.java b/src/main/java/com/adobe/epubcheck/ncx/NCXCheckerFactory.java deleted file mode 100755 index 99a9eb4ee..000000000 --- a/src/main/java/com/adobe/epubcheck/ncx/NCXCheckerFactory.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2007 Adobe Systems Incorporated - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - */ - -package com.adobe.epubcheck.ncx; - -import com.adobe.epubcheck.opf.ContentChecker; -import com.adobe.epubcheck.opf.ContentCheckerFactory; -import com.adobe.epubcheck.opf.ValidationContext; - -public class NCXCheckerFactory implements ContentCheckerFactory -{ - static private final NCXCheckerFactory instance = new NCXCheckerFactory(); - - public ContentChecker newInstance(ValidationContext context) - { - return new NCXChecker(context); - } - - static public NCXCheckerFactory getInstance() - { - return instance; - } -} diff --git a/src/main/java/com/adobe/epubcheck/ocf/OCFChecker.java b/src/main/java/com/adobe/epubcheck/ocf/OCFChecker.java index 967e34757..b5639cec1 100755 --- a/src/main/java/com/adobe/epubcheck/ocf/OCFChecker.java +++ b/src/main/java/com/adobe/epubcheck/ocf/OCFChecker.java @@ -22,7 +22,10 @@ package com.adobe.epubcheck.ocf; -import static com.adobe.epubcheck.opf.ValidationContext.ValidationContextPredicates.*; +import static com.adobe.epubcheck.opf.ValidationContext.ValidationContextPredicates.hasProp; +import static com.adobe.epubcheck.opf.ValidationContext.ValidationContextPredicates.path; +import static com.adobe.epubcheck.opf.ValidationContext.ValidationContextPredicates.profile; +import static com.adobe.epubcheck.opf.ValidationContext.ValidationContextPredicates.version; import java.io.File; import java.io.FileInputStream; @@ -38,13 +41,16 @@ import java.util.Locale; import java.util.Set; +import org.w3c.epubcheck.constants.MIMEType; +import org.w3c.epubcheck.core.Checker; +import org.w3c.epubcheck.core.CheckerFactory; + import com.adobe.epubcheck.api.EPUBLocation; import com.adobe.epubcheck.api.EPUBProfile; import com.adobe.epubcheck.api.FeatureReport; import com.adobe.epubcheck.api.Report; import com.adobe.epubcheck.messages.MessageId; import com.adobe.epubcheck.opf.OPFChecker; -import com.adobe.epubcheck.opf.OPFCheckerFactory; import com.adobe.epubcheck.opf.OPFData; import com.adobe.epubcheck.opf.OPFHandler; import com.adobe.epubcheck.opf.OPFHandler30; @@ -63,7 +69,7 @@ import com.google.common.base.Predicates; import com.google.common.collect.Iterables; -public class OCFChecker +public class OCFChecker implements Checker { private static final ValidatorMap validatorMap = ValidatorMap.builder() @@ -106,7 +112,7 @@ public OCFChecker(ValidationContext context) this.report = context.report; } - public void runChecks() + public void check() { // Create a new validation context builder from the parent context // It will be augmented with detected validation version, profile, etc. @@ -132,7 +138,7 @@ public void runChecks() OCFData containerData = ocf.getOcfData(); // retrieve the paths of root files - List opfPaths = containerData.getEntries(OPFData.OPF_MIME_TYPE); + List opfPaths = containerData.getEntries(MIMEType.PACKAGE_DOC.toString()); if (opfPaths == null || opfPaths.isEmpty()) { checkZipHeader(); // run ZIP header checks in any case before returning @@ -309,11 +315,12 @@ else if (validationVersion == EPUBVersion.VERSION_3) List opfHandlers = new LinkedList(); for (String opfPath : opfPaths) { - OPFChecker opfChecker = OPFCheckerFactory.getInstance() - .newInstance(newContextBuilder.path(opfPath).mimetype(OPFData.OPF_MIME_TYPE) - .featureReport(new FeatureReport()).build()); - opfChecker.runChecks(); - opfHandlers.add(opfChecker.getOPFHandler()); + ValidationContext opfContext = newContextBuilder.path(opfPath).mimetype(MIMEType.PACKAGE_DOC.toString()) + .featureReport(new FeatureReport()).build(); + Checker opfChecker = CheckerFactory.newChecker(opfContext); + assert opfChecker instanceof OPFChecker; + opfChecker.check(); + opfHandlers.add(((OPFChecker)opfChecker).getOPFHandler()); } // diff --git a/src/main/java/com/adobe/epubcheck/ocf/OCFPackage.java b/src/main/java/com/adobe/epubcheck/ocf/OCFPackage.java index 6ee0b189b..6821d90af 100644 --- a/src/main/java/com/adobe/epubcheck/ocf/OCFPackage.java +++ b/src/main/java/com/adobe/epubcheck/ocf/OCFPackage.java @@ -9,6 +9,8 @@ import java.util.Map; import java.util.Set; +import org.w3c.epubcheck.constants.MIMEType; + import com.adobe.epubcheck.api.EPUBLocation; import com.adobe.epubcheck.api.Report; import com.adobe.epubcheck.messages.MessageId; @@ -51,7 +53,7 @@ public Map get() { Preconditions.checkNotNull(reporter); Map result = new HashMap(); - for (String opfPath : ocfData.get().getEntries(OPFData.OPF_MIME_TYPE)) + for (String opfPath : ocfData.get().getEntries(MIMEType.PACKAGE_DOC.toString())) { OPFPeeker peeker = new OPFPeeker(opfPath, reporter, OCFPackage.this); try diff --git a/src/main/java/com/adobe/epubcheck/opf/ContentChecker.java b/src/main/java/com/adobe/epubcheck/opf/ContentChecker.java deleted file mode 100755 index 3e5b84fe6..000000000 --- a/src/main/java/com/adobe/epubcheck/opf/ContentChecker.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2007 Adobe Systems Incorporated - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - */ - -package com.adobe.epubcheck.opf; - -public interface ContentChecker -{ - public void runChecks(); -} diff --git a/src/main/java/com/adobe/epubcheck/opf/ContentCheckerFactory.java b/src/main/java/com/adobe/epubcheck/opf/ContentCheckerFactory.java deleted file mode 100755 index 5645fc02c..000000000 --- a/src/main/java/com/adobe/epubcheck/opf/ContentCheckerFactory.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2007 Adobe Systems Incorporated - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - */ - -package com.adobe.epubcheck.opf; - - -public interface ContentCheckerFactory -{ - public ContentChecker newInstance(ValidationContext context); -} diff --git a/src/main/java/com/adobe/epubcheck/opf/DocumentValidator.java b/src/main/java/com/adobe/epubcheck/opf/DocumentValidator.java deleted file mode 100644 index 38dad7109..000000000 --- a/src/main/java/com/adobe/epubcheck/opf/DocumentValidator.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2011 Adobe Systems Incorporated - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - */ - -package com.adobe.epubcheck.opf; - -public interface DocumentValidator -{ - public boolean validate(); -} diff --git a/src/main/java/com/adobe/epubcheck/opf/DocumentValidatorFactory.java b/src/main/java/com/adobe/epubcheck/opf/DocumentValidatorFactory.java deleted file mode 100644 index bd0e77934..000000000 --- a/src/main/java/com/adobe/epubcheck/opf/DocumentValidatorFactory.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2011 Adobe Systems Incorporated - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - */ - -package com.adobe.epubcheck.opf; - -import com.adobe.epubcheck.api.EPUBProfile; -import com.adobe.epubcheck.api.Report; -import com.adobe.epubcheck.util.EPUBVersion; -import com.adobe.epubcheck.util.GenericResourceProvider; - -public interface DocumentValidatorFactory -{ - public DocumentValidator newInstance(ValidationContext context); -// public DocumentValidator newInstance(Report report, String path, -// GenericResourceProvider resourceProvider, String mimeType, -// EPUBVersion version, EPUBProfile profile); -} diff --git a/src/main/java/com/adobe/epubcheck/opf/GenericContentChecker.java b/src/main/java/com/adobe/epubcheck/opf/GenericContentChecker.java deleted file mode 100755 index 03f5cc5d1..000000000 --- a/src/main/java/com/adobe/epubcheck/opf/GenericContentChecker.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2007 Adobe Systems Incorporated - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - */ - -package com.adobe.epubcheck.opf; - -import com.adobe.epubcheck.api.EPUBLocation; -import com.adobe.epubcheck.api.Report; -import com.adobe.epubcheck.messages.MessageId; -import com.adobe.epubcheck.ocf.OCFPackage; - -public class GenericContentChecker implements ContentChecker -{ - private final OCFPackage ocf; - private final Report report; - private final String path; - - GenericContentChecker(OCFPackage ocf, Report report, String path) - { - this.ocf = ocf; - this.report = report; - this.path = path; - } - - public void runChecks() - { - if (!ocf.hasEntry(path)) - { - report.message(MessageId.RSC_001, EPUBLocation.create(this.ocf.getName()), path); - } - else if (!ocf.canDecrypt(path)) - { - report.message(MessageId.RSC_004, EPUBLocation.create(this.ocf.getName()), path); - } - } -} diff --git a/src/main/java/com/adobe/epubcheck/opf/GenericContentCheckerFactory.java b/src/main/java/com/adobe/epubcheck/opf/GenericContentCheckerFactory.java deleted file mode 100755 index 17edc3aed..000000000 --- a/src/main/java/com/adobe/epubcheck/opf/GenericContentCheckerFactory.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2007 Adobe Systems Incorporated - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - */ - -package com.adobe.epubcheck.opf; - -public class GenericContentCheckerFactory implements ContentCheckerFactory -{ - static private final GenericContentCheckerFactory instance = new GenericContentCheckerFactory(); - - public ContentChecker newInstance(ValidationContext context) - { - return new GenericContentChecker(context.ocf.get(), context.report, context.path); - } - - static public GenericContentCheckerFactory getInstance() - { - return instance; - } -} diff --git a/src/main/java/com/adobe/epubcheck/opf/OPFChecker.java b/src/main/java/com/adobe/epubcheck/opf/OPFChecker.java index 2fa135853..66102c3b5 100755 --- a/src/main/java/com/adobe/epubcheck/opf/OPFChecker.java +++ b/src/main/java/com/adobe/epubcheck/opf/OPFChecker.java @@ -22,27 +22,27 @@ package com.adobe.epubcheck.opf; -import static com.adobe.epubcheck.opf.ValidationContext.ValidationContextPredicates.*; +import static com.adobe.epubcheck.opf.ValidationContext.ValidationContextPredicates.hasPubType; +import static com.adobe.epubcheck.opf.ValidationContext.ValidationContextPredicates.profile; +import static com.adobe.epubcheck.opf.ValidationContext.ValidationContextPredicates.version; import java.util.HashSet; -import java.util.Hashtable; import java.util.List; import java.util.Locale; import java.util.Set; +import org.w3c.epubcheck.core.Checker; +import org.w3c.epubcheck.core.CheckerFactory; + import com.adobe.epubcheck.api.EPUBLocation; import com.adobe.epubcheck.api.EPUBProfile; import com.adobe.epubcheck.api.Report; -import com.adobe.epubcheck.bitmap.BitmapCheckerFactory; -import com.adobe.epubcheck.css.CSSCheckerFactory; -import com.adobe.epubcheck.dtbook.DTBookCheckerFactory; import com.adobe.epubcheck.messages.MessageId; -import com.adobe.epubcheck.nav.NavCheckerFactory; -import com.adobe.epubcheck.ncx.NCXCheckerFactory; +import com.adobe.epubcheck.nav.NavChecker; +import com.adobe.epubcheck.ncx.NCXChecker; import com.adobe.epubcheck.ocf.OCFFilenameChecker; import com.adobe.epubcheck.ocf.OCFPackage; import com.adobe.epubcheck.opf.ValidationContext.ValidationContextBuilder; -import com.adobe.epubcheck.ops.OPSCheckerFactory; import com.adobe.epubcheck.overlay.OverlayTextChecker; import com.adobe.epubcheck.util.EPUBVersion; import com.adobe.epubcheck.util.FeatureEnum; @@ -54,7 +54,7 @@ import com.google.common.base.Optional; import com.google.common.base.Predicates; -public class OPFChecker implements DocumentValidator, ContentChecker +public class OPFChecker implements Checker { private final static ValidatorMap validatorMap = ValidatorMap.builder() @@ -81,23 +81,6 @@ public class OPFChecker implements DocumentValidator, ContentChecker protected final EPUBVersion version; protected OPFHandler opfHandler = null; protected XMLParser opfParser = null; - protected final Hashtable contentCheckerFactoryMap = new Hashtable(); - - protected void initContentCheckerFactoryMap() - { - Hashtable map = new Hashtable(); - map.put("application/xhtml+xml", OPSCheckerFactory.getInstance()); - map.put("application/x-dtbook+xml", DTBookCheckerFactory.getInstance()); - map.put("image/jpeg", BitmapCheckerFactory.getInstance()); - map.put("image/gif", BitmapCheckerFactory.getInstance()); - map.put("image/png", BitmapCheckerFactory.getInstance()); - map.put("image/svg+xml", OPSCheckerFactory.getInstance()); - map.put("text/css", CSSCheckerFactory.getInstance()); - map.put("text/html", OPSCheckerFactory.getInstance()); - map.put("text/x-oeb1-document", OPSCheckerFactory.getInstance()); - - contentCheckerFactoryMap.putAll(map); - } public OPFChecker(ValidationContext context) { @@ -119,20 +102,26 @@ public OPFChecker(ValidationContext context) } this.context = newContext.build(); - // Initialize validators and factories - initContentCheckerFactoryMap(); + } + + public void check() { + if (context.ocf.isPresent()) { + checkPackage(); + } else { + checkContent(); + } } - public void runChecks() + protected boolean checkPackage() { OCFPackage ocf = context.ocf.get(); XRefChecker xrefChecker = context.xrefChecker.get(); if (!ocf.hasEntry(path)) { report.message(MessageId.PKG_020, EPUBLocation.create(ocf.getName()), path); - return; + return false; } - validate(); + checkContent(); if (!opfHandler.checkUniqueIdentExists()) { @@ -169,6 +158,7 @@ public void runChecks() } xrefChecker.checkReferences(); + return false; } protected void checkItemAfterResourceValidation(OPFItem item) { @@ -213,13 +203,8 @@ public OPFHandler getOPFHandler() return opfHandler; } - @Override - public boolean validate() + protected boolean checkContent() { - int fatalErrorsSoFar = report.getFatalErrorCount(); - int errorsSoFar = report.getErrorCount(); - int warningsSoFar = report.getWarningCount(); - opfParser = new XMLParser(new ValidationContextBuilder(context).mimetype("opf").build()); initHandler(); opfParser.addXMLHandler(opfHandler); @@ -291,9 +276,7 @@ public boolean validate() } } } - - return fatalErrorsSoFar == report.getFatalErrorCount() && errorsSoFar == report.getErrorCount() - && warningsSoFar == report.getWarningCount(); + return true; } public static boolean isBlessedItemType(String type, EPUBVersion version) @@ -428,36 +411,28 @@ else if (isBlessedStyleType(mimeType)) protected void checkItemContent(OPFItem item) { - String mimetype = item.getMimeType(); - ContentCheckerFactory checkerFactory; - if (item.isNcx()) - { - checkerFactory = NCXCheckerFactory.getInstance(); - } - else if (item.isNav()) - { - checkerFactory = NavCheckerFactory.getInstance(); - } - else - { - checkerFactory = contentCheckerFactoryMap.get(mimetype); - } - - if (checkerFactory == null) - { - checkerFactory = GenericContentCheckerFactory.getInstance(); - } - if (checkerFactory != null) - { - try { - // Create the content checker with an overridden validation context - ContentChecker checker = checkerFactory.newInstance(new ValidationContextBuilder(context) - .path(item.getPath()).mimetype(mimetype).properties(item.getProperties()).build()); - // Validate - checker.runChecks(); - } catch (IllegalStateException e) { - report.message(MessageId.CHK_008, EPUBLocation.create(path), item.getPath()); + // Create a new validation context for the OPF item + ValidationContext itemContext = new ValidationContextBuilder(context) + .path(item.getPath()).mimetype(item.getMimeType()).properties(item.getProperties()).build(); + // Create an appropriate checker + try { + Checker checker; + if (item.isNcx()) + { + checker = new NCXChecker(itemContext); + } + else if (item.isNav()) + { + checker = new NavChecker(itemContext); + } + else + { + checker = CheckerFactory.newChecker(itemContext); } + // Check the item + checker.check(); + } catch (IllegalStateException e) { + report.message(MessageId.CHK_008, EPUBLocation.create(path), item.getPath()); } } diff --git a/src/main/java/com/adobe/epubcheck/opf/OPFChecker30.java b/src/main/java/com/adobe/epubcheck/opf/OPFChecker30.java index c3efaa470..8f7f27e10 100644 --- a/src/main/java/com/adobe/epubcheck/opf/OPFChecker30.java +++ b/src/main/java/com/adobe/epubcheck/opf/OPFChecker30.java @@ -24,22 +24,15 @@ import java.net.URI; import java.net.URISyntaxException; -import java.util.HashMap; import java.util.Iterator; import java.util.Set; import com.adobe.epubcheck.api.EPUBLocation; import com.adobe.epubcheck.api.EPUBProfile; import com.adobe.epubcheck.api.FeatureReport.Feature; -import com.adobe.epubcheck.bitmap.BitmapCheckerFactory; -import com.adobe.epubcheck.css.CSSCheckerFactory; -import com.adobe.epubcheck.dict.SearchKeyMapCheckerFactory; -import com.adobe.epubcheck.dtbook.DTBookCheckerFactory; import com.adobe.epubcheck.messages.MessageId; import com.adobe.epubcheck.opf.MetadataSet.Metadata; import com.adobe.epubcheck.opf.ResourceCollection.Roles; -import com.adobe.epubcheck.ops.OPSCheckerFactory; -import com.adobe.epubcheck.overlay.OverlayCheckerFactory; import com.adobe.epubcheck.overlay.OverlayTextChecker; import com.adobe.epubcheck.util.EPUBVersion; import com.adobe.epubcheck.util.FeatureEnum; @@ -52,7 +45,7 @@ import com.google.common.collect.Iterables; import com.google.common.io.Files; -public class OPFChecker30 extends OPFChecker implements DocumentValidator +public class OPFChecker30 extends OPFChecker { public OPFChecker30(ValidationContext context) @@ -60,23 +53,6 @@ public OPFChecker30(ValidationContext context) super(context); } - @Override - protected void initContentCheckerFactoryMap() - { - HashMap map = new HashMap(); - map.put("application/vnd.epub.search-key-map+xml", SearchKeyMapCheckerFactory.getInstance()); - map.put("application/smil+xml", OverlayCheckerFactory.getInstance()); - map.put("application/xhtml+xml", OPSCheckerFactory.getInstance()); - map.put("application/x-dtbook+xml", DTBookCheckerFactory.getInstance()); - map.put("image/jpeg", BitmapCheckerFactory.getInstance()); - map.put("image/gif", BitmapCheckerFactory.getInstance()); - map.put("image/png", BitmapCheckerFactory.getInstance()); - map.put("image/svg+xml", OPSCheckerFactory.getInstance()); - map.put("text/css", CSSCheckerFactory.getInstance()); - contentCheckerFactoryMap.clear(); - contentCheckerFactoryMap.putAll(map); - } - @Override public void initHandler() { @@ -84,29 +60,24 @@ public void initHandler() } @Override - public void runChecks() + protected boolean checkPackage() { - super.runChecks(); + super.checkPackage(); checkCollectionsContent(); checkPagination(); checkSemantics(); checkNav(); checkSpecifics(); + return false; } @Override - public boolean validate() + protected boolean checkContent() { - int fatalErrorsSoFar = report.getFatalErrorCount(); - int errorsSoFar = report.getErrorCount(); - int warningsSoFar = report.getWarningCount(); - - super.validate(); + super.checkContent(); checkLinkedResources(); checkCollections(); - - return fatalErrorsSoFar == report.getFatalErrorCount() && errorsSoFar == report.getErrorCount() - && warningsSoFar == report.getWarningCount(); + return true; } @Override diff --git a/src/main/java/com/adobe/epubcheck/opf/OPFCheckerFactory.java b/src/main/java/com/adobe/epubcheck/opf/OPFCheckerFactory.java deleted file mode 100644 index 40ba1e749..000000000 --- a/src/main/java/com/adobe/epubcheck/opf/OPFCheckerFactory.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2011 Adobe Systems Incorporated - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - */ - -package com.adobe.epubcheck.opf; - -import com.adobe.epubcheck.util.EPUBVersion; - -public class OPFCheckerFactory implements DocumentValidatorFactory, ContentCheckerFactory -{ - static private final OPFCheckerFactory instance = new OPFCheckerFactory(); - - static public OPFCheckerFactory getInstance() - { - return instance; - } - - public OPFChecker newInstance(ValidationContext context) - { - if (context.version == EPUBVersion.VERSION_2) - { - return new OPFChecker(context); - } - else - { - return new OPFChecker30(context); - } - } -} diff --git a/src/main/java/com/adobe/epubcheck/opf/OPFData.java b/src/main/java/com/adobe/epubcheck/opf/OPFData.java index 84ef16c70..e9cc02e2a 100644 --- a/src/main/java/com/adobe/epubcheck/opf/OPFData.java +++ b/src/main/java/com/adobe/epubcheck/opf/OPFData.java @@ -8,7 +8,6 @@ public final class OPFData { - public static final String OPF_MIME_TYPE = "application/oebps-package+xml"; public static final String DC_TYPE_DICT = "dictionary"; public static final String DC_TYPE_EDUPUB = "edupub"; public static final String DC_TYPE_INDEX = "index"; diff --git a/src/main/java/com/adobe/epubcheck/opf/PublicationResourceChecker.java b/src/main/java/com/adobe/epubcheck/opf/PublicationResourceChecker.java new file mode 100755 index 000000000..64485a92d --- /dev/null +++ b/src/main/java/com/adobe/epubcheck/opf/PublicationResourceChecker.java @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2007 Adobe Systems Incorporated + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +package com.adobe.epubcheck.opf; + +import org.w3c.epubcheck.core.AbstractChecker; + +import com.adobe.epubcheck.api.EPUBLocation; +import com.adobe.epubcheck.messages.MessageId; +import com.google.common.base.Preconditions; + +//FIXME 2021 Romain - document +public class PublicationResourceChecker extends AbstractChecker +{ + + public PublicationResourceChecker(ValidationContext context) + { + super(context); + } + + + @Override + public final void check() + { + boolean cont = !context.ocf.isPresent() || checkPublicationBeforeContent(); + cont = cont && checkContent(); + cont = cont && !context.ocf.isPresent() || checkPublicationAfterContent(); + } + + // by construction we know context.ocf is present + protected boolean checkPublicationBeforeContent() + { + return checkResourceExists(context) + && checkResourceCanBeDecrypted(context); + } + + protected boolean checkContent() + { + return true; + } + + //by construction we know context.ocf is present + protected boolean checkPublicationAfterContent() + { + return true; + } + + + private static boolean checkResourceExists(ValidationContext context) + { + Preconditions.checkState(context.ocf.isPresent()); + if (!context.ocf.get().hasEntry(context.path)) + { + context.report.message(MessageId.RSC_001, EPUBLocation.create(context.ocf.get().getName()), + context.path); + return false; + } + else + { + return true; + } + } + + private static boolean checkResourceCanBeDecrypted(ValidationContext context) + { + Preconditions.checkState(context.ocf.isPresent()); + if (!context.ocf.get().canDecrypt(context.path)) + { + context.report.message(MessageId.RSC_004, EPUBLocation.create(context.ocf.get().getName()), + context.path); + return false; + } + else + { + return true; + } + } +} diff --git a/src/main/java/com/adobe/epubcheck/opf/ValidationContext.java b/src/main/java/com/adobe/epubcheck/opf/ValidationContext.java index 9d06e5b66..9024d2936 100644 --- a/src/main/java/com/adobe/epubcheck/opf/ValidationContext.java +++ b/src/main/java/com/adobe/epubcheck/opf/ValidationContext.java @@ -5,6 +5,8 @@ import java.util.Locale; import java.util.Set; +import org.w3c.epubcheck.core.Checker; + import com.adobe.epubcheck.api.EPUBProfile; import com.adobe.epubcheck.api.FeatureReport; import com.adobe.epubcheck.api.LocalizableReport; @@ -23,8 +25,7 @@ /** * Holds various contextual objects used during validation. This validation - * context is used by both {@link ContentChecker} and {@link DocumentValidator} - * instances. + * context is notalby used by {@link Checker} instances. * */ public final class ValidationContext diff --git a/src/main/java/com/adobe/epubcheck/ops/OPSChecker.java b/src/main/java/com/adobe/epubcheck/ops/OPSChecker.java index 965365943..bde30aa04 100755 --- a/src/main/java/com/adobe/epubcheck/ops/OPSChecker.java +++ b/src/main/java/com/adobe/epubcheck/ops/OPSChecker.java @@ -22,19 +22,22 @@ package com.adobe.epubcheck.ops; -import static com.adobe.epubcheck.opf.ValidationContext.ValidationContextPredicates.*; -import static com.google.common.base.Predicates.*; +import static com.adobe.epubcheck.opf.ValidationContext.ValidationContextPredicates.hasProp; +import static com.adobe.epubcheck.opf.ValidationContext.ValidationContextPredicates.hasPubType; +import static com.adobe.epubcheck.opf.ValidationContext.ValidationContextPredicates.mimetype; +import static com.adobe.epubcheck.opf.ValidationContext.ValidationContextPredicates.profile; +import static com.adobe.epubcheck.opf.ValidationContext.ValidationContextPredicates.version; +import static com.google.common.base.Predicates.and; +import static com.google.common.base.Predicates.not; +import static com.google.common.base.Predicates.or; import java.io.IOException; import java.util.List; import com.adobe.epubcheck.api.EPUBLocation; import com.adobe.epubcheck.api.EPUBProfile; -import com.adobe.epubcheck.api.Report; import com.adobe.epubcheck.messages.MessageId; -import com.adobe.epubcheck.ocf.OCFPackage; -import com.adobe.epubcheck.opf.ContentChecker; -import com.adobe.epubcheck.opf.DocumentValidator; +import com.adobe.epubcheck.opf.PublicationResourceChecker; import com.adobe.epubcheck.opf.OPFData; import com.adobe.epubcheck.opf.ValidationContext; import com.adobe.epubcheck.util.EPUBVersion; @@ -46,10 +49,9 @@ import com.adobe.epubcheck.xml.XMLValidators; import com.google.common.base.Predicates; -public class OPSChecker implements ContentChecker, DocumentValidator +public class OPSChecker extends PublicationResourceChecker { - @SuppressWarnings("unchecked") private final static ValidatorMap validatorMap = ValidatorMap.builder() .putAll(Predicates.and(mimetype("application/xhtml+xml"), version(EPUBVersion.VERSION_2)), XMLValidators.XHTML_20_NVDL, XMLValidators.XHTML_20_SCH, XMLValidators.IDUNIQUE_20_SCH) @@ -80,49 +82,24 @@ public class OPSChecker implements ContentChecker, DocumentValidator XMLValidators.XHTML_DATANAV_SCH) .build(); - private final ValidationContext context; - private final Report report; - private final String path; public OPSChecker(ValidationContext context) { - this.context = context; - this.path = context.path; - this.report = context.report; + super(context); } - public void runChecks() + @Override + protected boolean checkContent() { - OCFPackage ocf = context.ocf.get(); - if (!ocf.hasEntry(path)) - { - report.message(MessageId.RSC_001, EPUBLocation.create(ocf.getName()), path); - } - else if (!ocf.canDecrypt(path)) - { - report.message(MessageId.RSC_004, EPUBLocation.create(ocf.getName()), path); - } - else - { - validate(); - } - } - - public boolean validate() - { - int fatalErrorsSoFar = report.getFatalErrorCount(); - int errorsSoFar = report.getErrorCount(); - int warningsSoFar = report.getWarningCount(); List validators = validatorMap.getValidators(context); try { validate(validators); } catch (IOException e) { - report.message(MessageId.PKG_008, EPUBLocation.create(path), path); + report.message(MessageId.PKG_008, EPUBLocation.create(context.path), context.path); } - return fatalErrorsSoFar == report.getFatalErrorCount() && errorsSoFar == report.getErrorCount() - && warningsSoFar == report.getWarningCount(); + return true; } void validate(List validators) diff --git a/src/main/java/com/adobe/epubcheck/ops/OPSCheckerFactory.java b/src/main/java/com/adobe/epubcheck/ops/OPSCheckerFactory.java deleted file mode 100755 index cddfcf6d9..000000000 --- a/src/main/java/com/adobe/epubcheck/ops/OPSCheckerFactory.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2007 Adobe Systems Incorporated - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - */ - -package com.adobe.epubcheck.ops; - -import com.adobe.epubcheck.opf.ContentCheckerFactory; -import com.adobe.epubcheck.opf.DocumentValidatorFactory; -import com.adobe.epubcheck.opf.ValidationContext; - -public class OPSCheckerFactory implements ContentCheckerFactory, DocumentValidatorFactory -{ - - public OPSChecker newInstance(ValidationContext context) - { - return new OPSChecker(context); - } - - static private final OPSCheckerFactory instance = new OPSCheckerFactory(); - - static public OPSCheckerFactory getInstance() - { - return instance; - } - -} diff --git a/src/main/java/com/adobe/epubcheck/ops/OPSHandler.java b/src/main/java/com/adobe/epubcheck/ops/OPSHandler.java index f5c71e5d9..d57d11d11 100755 --- a/src/main/java/com/adobe/epubcheck/ops/OPSHandler.java +++ b/src/main/java/com/adobe/epubcheck/ops/OPSHandler.java @@ -22,10 +22,8 @@ package com.adobe.epubcheck.ops; -import java.net.MalformedURLException; import java.net.URI; import java.net.URISyntaxException; -import java.net.URL; import java.util.Locale; import java.util.Stack; @@ -33,7 +31,7 @@ import com.adobe.epubcheck.api.EPUBLocation; import com.adobe.epubcheck.api.Report; -import com.adobe.epubcheck.css.CSSCheckerFactory; +import com.adobe.epubcheck.css.CSSChecker; import com.adobe.epubcheck.messages.MessageId; import com.adobe.epubcheck.opf.OPFChecker; import com.adobe.epubcheck.opf.ValidationContext; @@ -438,8 +436,7 @@ else if (name.equals("script")) String style = e.getAttribute("style"); if (style != null && style.length() > 0) { - CSSCheckerFactory.getInstance() - .newInstance(context, style, currentLocation.getLineNumber(), true).runChecks(); + new CSSChecker(context, style, currentLocation.getLineNumber(), true).check(); } } } @@ -521,8 +518,7 @@ public void endElement() String style = textNode.toString(); if (style.length() > 0) { - CSSCheckerFactory.getInstance() - .newInstance(context, style, currentLocation.getLineNumber(), false).runChecks(); + new CSSChecker(context, style, currentLocation.getLineNumber(), false).check(); } textNode = null; } diff --git a/src/main/java/com/adobe/epubcheck/overlay/OverlayChecker.java b/src/main/java/com/adobe/epubcheck/overlay/OverlayChecker.java index ef4aecaa9..a68cfbd54 100644 --- a/src/main/java/com/adobe/epubcheck/overlay/OverlayChecker.java +++ b/src/main/java/com/adobe/epubcheck/overlay/OverlayChecker.java @@ -22,54 +22,25 @@ package com.adobe.epubcheck.overlay; -import com.adobe.epubcheck.api.EPUBLocation; -import com.adobe.epubcheck.api.Report; -import com.adobe.epubcheck.messages.MessageId; -import com.adobe.epubcheck.ocf.OCFPackage; -import com.adobe.epubcheck.opf.ContentChecker; -import com.adobe.epubcheck.opf.DocumentValidator; +import com.adobe.epubcheck.opf.PublicationResourceChecker; import com.adobe.epubcheck.opf.ValidationContext; import com.adobe.epubcheck.xml.XMLParser; import com.adobe.epubcheck.xml.XMLValidators; import com.google.common.base.Preconditions; -public class OverlayChecker implements ContentChecker, DocumentValidator +public class OverlayChecker extends PublicationResourceChecker { - private final ValidationContext context; - private final Report report; - private final String path; public OverlayChecker(ValidationContext context) { + super(context); Preconditions.checkState("application/smil+xml".equals(context.mimeType)); - this.context = context; - this.report = context.report; - this.path = context.path; } - public void runChecks() + @Override + protected boolean checkContent() { - OCFPackage ocf = context.ocf.get(); - if (!ocf.hasEntry(path)) - { - report.message(MessageId.RSC_001, EPUBLocation.create(ocf.getName()), path); - } - else if (!ocf.canDecrypt(path)) - { - report.message(MessageId.RSC_004, EPUBLocation.create(ocf.getName()), path); - } - else - { - validate(); - } - } - - public boolean validate() - { - int fatalErrorsSoFar = report.getFatalErrorCount(); - int errorsSoFar = report.getErrorCount(); - int warningsSoFar = report.getWarningCount(); OverlayHandler overlayHandler; XMLParser overlayParser = new XMLParser(context); overlayHandler = new OverlayHandler(context, overlayParser); @@ -77,8 +48,7 @@ public boolean validate() overlayParser.addValidator(XMLValidators.MO_30_SCH.get()); overlayParser.addXMLHandler(overlayHandler); overlayParser.process(); - - return fatalErrorsSoFar == report.getFatalErrorCount() && errorsSoFar == report.getErrorCount() - && warningsSoFar == report.getWarningCount(); + return true; } + } diff --git a/src/main/java/com/adobe/epubcheck/overlay/OverlayCheckerFactory.java b/src/main/java/com/adobe/epubcheck/overlay/OverlayCheckerFactory.java deleted file mode 100644 index d1364c059..000000000 --- a/src/main/java/com/adobe/epubcheck/overlay/OverlayCheckerFactory.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2011 Adobe Systems Incorporated - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - */ - -package com.adobe.epubcheck.overlay; - -import com.adobe.epubcheck.opf.ContentCheckerFactory; -import com.adobe.epubcheck.opf.DocumentValidatorFactory; -import com.adobe.epubcheck.opf.ValidationContext; - -public class OverlayCheckerFactory implements ContentCheckerFactory, DocumentValidatorFactory -{ - - public OverlayChecker newInstance(ValidationContext context) - { - return new OverlayChecker(context); - } - - static private final OverlayCheckerFactory instance = new OverlayCheckerFactory(); - - static public OverlayCheckerFactory getInstance() - { - return instance; - } - -} diff --git a/src/main/java/com/adobe/epubcheck/tool/EpubChecker.java b/src/main/java/com/adobe/epubcheck/tool/EpubChecker.java index 4648d9829..01cdd3bd1 100644 --- a/src/main/java/com/adobe/epubcheck/tool/EpubChecker.java +++ b/src/main/java/com/adobe/epubcheck/tool/EpubChecker.java @@ -34,19 +34,21 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.w3c.epubcheck.core.Checker; + import com.adobe.epubcheck.api.EPUBProfile; import com.adobe.epubcheck.api.EpubCheck; import com.adobe.epubcheck.api.EpubCheckFactory; import com.adobe.epubcheck.api.LocalizableReport; import com.adobe.epubcheck.api.Report; import com.adobe.epubcheck.messages.MessageDictionaryDumper; -import com.adobe.epubcheck.nav.NavCheckerFactory; -import com.adobe.epubcheck.opf.DocumentValidator; -import com.adobe.epubcheck.opf.DocumentValidatorFactory; -import com.adobe.epubcheck.opf.OPFCheckerFactory; +import com.adobe.epubcheck.nav.NavChecker; +import com.adobe.epubcheck.opf.OPFChecker; +import com.adobe.epubcheck.opf.OPFChecker30; +import com.adobe.epubcheck.opf.ValidationContext; import com.adobe.epubcheck.opf.ValidationContext.ValidationContextBuilder; -import com.adobe.epubcheck.ops.OPSCheckerFactory; -import com.adobe.epubcheck.overlay.OverlayCheckerFactory; +import com.adobe.epubcheck.ops.OPSChecker; +import com.adobe.epubcheck.overlay.OverlayChecker; import com.adobe.epubcheck.reporting.CheckingReport; import com.adobe.epubcheck.util.Archive; import com.adobe.epubcheck.util.DefaultReportImpl; @@ -94,7 +96,6 @@ public class EpubChecker int reportingLevel = ReportingLevel.Info; private static final HashMap modeMimeTypeMap; - private static final HashMap documentValidatorFactoryMap; private static final String EPUBCHECK_CUSTOM_MESSAGE_FILE = "ePubCheckCustomMessageFile"; static @@ -112,24 +113,6 @@ public class EpubChecker modeMimeTypeMap = map; } - - static - { - HashMap map = new HashMap(); - map.put(new OPSType(null, EPUBVersion.VERSION_2), EpubCheckFactory.getInstance()); - map.put(new OPSType(null, EPUBVersion.VERSION_3), EpubCheckFactory.getInstance()); - map.put(new OPSType("opf", EPUBVersion.VERSION_2), OPFCheckerFactory.getInstance()); - map.put(new OPSType("opf", EPUBVersion.VERSION_3), OPFCheckerFactory.getInstance()); - map.put(new OPSType("xhtml", EPUBVersion.VERSION_2), OPSCheckerFactory.getInstance()); - map.put(new OPSType("xhtml", EPUBVersion.VERSION_3), OPSCheckerFactory.getInstance()); - map.put(new OPSType("svg", EPUBVersion.VERSION_2), OPSCheckerFactory.getInstance()); - map.put(new OPSType("svg", EPUBVersion.VERSION_3), OPSCheckerFactory.getInstance()); - map.put(new OPSType("mo", EPUBVersion.VERSION_3), OverlayCheckerFactory.getInstance()); - map.put(new OPSType("nav", EPUBVersion.VERSION_3), NavCheckerFactory.getInstance()); - - documentValidatorFactoryMap = map; - } - public Locale getLocale() { return locale; } @@ -201,9 +184,39 @@ int validateFile(String path, EPUBVersion version, Report report, EPUBProfile pr OPSType opsType = new OPSType(mode, version); - DocumentValidatorFactory factory = documentValidatorFactoryMap.get(opsType); - - if (factory == null) + ValidationContext context = new ValidationContextBuilder().path(path) + .report(report).resourceProvider(resourceProvider).mimetype(modeMimeTypeMap.get(opsType)) + .version(version).profile(profile).build(); + + Checker checker = null; + if (mode == null) { + checker = EpubCheckFactory.getInstance().newInstance(context); + } else { + switch (mode) + { + case "opf": + if (version == EPUBVersion.VERSION_2) { + checker = new OPFChecker(context); + } else { + checker = new OPFChecker30(context); + } + break; + case "xhtml": + case "svg": + checker = new OPSChecker(context); + break; + case "mo": + if (version == EPUBVersion.VERSION_3) checker = new OverlayChecker(context); + break; + case "nav": + if (version == EPUBVersion.VERSION_3) checker = new NavChecker(context); + break; + default: + break; + } + } + + if (checker == null) { outWriter.println(messages.get("display_help")); System.err.println(String.format(messages.get("mode_version_not_supported"), mode, version)); @@ -212,13 +225,10 @@ int validateFile(String path, EPUBVersion version, Report report, EPUBProfile pr version)); } - DocumentValidator check = factory.newInstance(new ValidationContextBuilder().path(path) - .report(report).resourceProvider(resourceProvider).mimetype(modeMimeTypeMap.get(opsType)) - .version(version).profile(profile).build()); - if (check.getClass() == EpubCheck.class) + if (checker.getClass() == EpubCheck.class) { - int validationResult = ((EpubCheck) check).doValidate(); + int validationResult = ((EpubCheck) checker).doValidate(); if (validationResult == 0) { outWriter.println(messages.get("no_errors__or_warnings")); @@ -234,8 +244,8 @@ else if (validationResult == 1) } else { - boolean validationResult = check.validate(); - if (validationResult) + checker.check(); + if (report.getWarningCount() == 0 && report.getFatalErrorCount() == 0 && report.getErrorCount() == 0) { outWriter.println(messages.get("no_errors__or_warnings")); return 0; diff --git a/src/main/java/com/adobe/epubcheck/util/OPSType.java b/src/main/java/com/adobe/epubcheck/util/OPSType.java index bb80d9c86..ce86bf022 100644 --- a/src/main/java/com/adobe/epubcheck/util/OPSType.java +++ b/src/main/java/com/adobe/epubcheck/util/OPSType.java @@ -24,8 +24,8 @@ public class OPSType { - private final EPUBVersion version; - private final String mimeType; + public final EPUBVersion version; + public final String mimeType; public OPSType(String mimeType, EPUBVersion version) { diff --git a/src/main/java/org/w3c/epubcheck/constants/MIMEType.java b/src/main/java/org/w3c/epubcheck/constants/MIMEType.java new file mode 100644 index 000000000..eeadc9adb --- /dev/null +++ b/src/main/java/org/w3c/epubcheck/constants/MIMEType.java @@ -0,0 +1,55 @@ +package org.w3c.epubcheck.constants; + +import java.util.Collections; +import java.util.Locale; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import com.google.common.base.Optional; + +//FIXME 2021 Romain - document +public enum MIMEType +{ + CSS("text/css"), + DTBOOK("application/x-dtbook+xml"), + EPUB("application/epub+zip"), + HTML("text/html"), + IMAGE_JPEG("image/jpeg"), + IMAGE_GIF("image/gif"), + IMAGE_PNG("image/png"), + OEBPS("text/x-oeb1-document"), + PACKAGE_DOC("application/oebps-package+xml"), + SEARCH_KEY_MAP("application/vnd.epub.search-key-map+xml"), + SMIL("application/smil+xml"), + SVG("image/svg+xml"), + XHTML("application/xhtml+xml"); + + private static final Map ENUM_MAP; + + private final String definition; + + private MIMEType(final String definition) + { + this.definition = definition; + } + + public String toString() + { + return definition; + } + + static + { + Map map = new ConcurrentHashMap(); + for (MIMEType value : MIMEType.values()) + { + map.put(value.toString(), value); + } + ENUM_MAP = Collections.unmodifiableMap(map); + } + + public static Optional get(String name) + { + return Optional.fromNullable(ENUM_MAP.get(name.toLowerCase(Locale.ENGLISH))); + } +} diff --git a/src/main/java/org/w3c/epubcheck/core/AbstractChecker.java b/src/main/java/org/w3c/epubcheck/core/AbstractChecker.java new file mode 100644 index 000000000..67225390a --- /dev/null +++ b/src/main/java/org/w3c/epubcheck/core/AbstractChecker.java @@ -0,0 +1,19 @@ +package org.w3c.epubcheck.core; + +import com.adobe.epubcheck.api.Report; +import com.adobe.epubcheck.opf.ValidationContext; +import com.google.common.base.Preconditions; + +//FIXME 2021 Romain - document +public abstract class AbstractChecker implements Checker +{ + + protected final ValidationContext context; + protected final Report report; + + public AbstractChecker(ValidationContext context) + { + this.context = Preconditions.checkNotNull(context); + this.report = context.report; + } +} diff --git a/src/main/java/org/w3c/epubcheck/core/Checker.java b/src/main/java/org/w3c/epubcheck/core/Checker.java new file mode 100644 index 000000000..5801ee6df --- /dev/null +++ b/src/main/java/org/w3c/epubcheck/core/Checker.java @@ -0,0 +1,6 @@ +package org.w3c.epubcheck.core; + +//FIXME 2021 Romain - document +public interface Checker { + public void check(); +} diff --git a/src/main/java/org/w3c/epubcheck/core/CheckerFactory.java b/src/main/java/org/w3c/epubcheck/core/CheckerFactory.java new file mode 100644 index 000000000..206d43582 --- /dev/null +++ b/src/main/java/org/w3c/epubcheck/core/CheckerFactory.java @@ -0,0 +1,69 @@ +package org.w3c.epubcheck.core; + +import org.w3c.epubcheck.constants.MIMEType; + +import com.adobe.epubcheck.bitmap.BitmapChecker; +import com.adobe.epubcheck.css.CSSChecker; +import com.adobe.epubcheck.dict.SearchKeyMapChecker; +import com.adobe.epubcheck.dtbook.DTBookChecker; +import com.adobe.epubcheck.opf.PublicationResourceChecker; +import com.adobe.epubcheck.opf.OPFChecker; +import com.adobe.epubcheck.opf.OPFChecker30; +import com.adobe.epubcheck.opf.ValidationContext; +import com.adobe.epubcheck.ops.OPSChecker; +import com.adobe.epubcheck.overlay.OverlayChecker; +import com.adobe.epubcheck.util.EPUBVersion; +import com.google.common.base.Optional; + +// FIXME 2021 Romain - document +public final class CheckerFactory +{ + public enum CheckerTypes + { + + } + + public static Checker newChecker(ValidationContext context) + { + Optional mimeType = MIMEType.get(context.mimeType); + if (mimeType.isPresent()) + { + switch (mimeType.get()) + { + case CSS: + return new CSSChecker(context); + case DTBOOK: + return new DTBookChecker(context); + case EPUB: + // FIXME 2021 Romain - ValidationContext-based EPUB checker will come later + break; + case HTML: + if (context.version == EPUBVersion.VERSION_2) return new OPSChecker(context); + break; + case IMAGE_GIF: + case IMAGE_JPEG: + case IMAGE_PNG: + return new BitmapChecker(context); + case OEBPS: + if (context.version == EPUBVersion.VERSION_2) return new OPSChecker(context); + break; + case PACKAGE_DOC: + return (context.version == EPUBVersion.VERSION_2) ? new OPFChecker(context) + : new OPFChecker30(context); + case SEARCH_KEY_MAP: + if (context.version == EPUBVersion.VERSION_3) return new SearchKeyMapChecker(context); + break; + case SVG: + return new OPSChecker(context); + case SMIL: + if (context.version == EPUBVersion.VERSION_3) return new OverlayChecker(context); + break; + case XHTML: + return new OPSChecker(context); + default: + break; + } + } + return new PublicationResourceChecker(context); + } +} diff --git a/src/test/java/com/adobe/epubcheck/stress/StressTest.java b/src/test/java/com/adobe/epubcheck/stress/StressTest.java index 76a7b0ef5..a833b78a3 100644 --- a/src/test/java/com/adobe/epubcheck/stress/StressTest.java +++ b/src/test/java/com/adobe/epubcheck/stress/StressTest.java @@ -91,7 +91,7 @@ private void validate() throws Exception epub.createArchive(); ValidationReport report = new ValidationReport(TEMP_DIR.getName()); EpubCheck epubCheck = new EpubCheck(epub.getEpubFile(), report); - epubCheck.validate(); + epubCheck.check(); assertTrue(report.getErrorCount() < 1); assertTrue(report.getWarningCount() < 1); epub.deleteEpubFile(); diff --git a/src/test/java/org/w3c/epubcheck/test/ExecutionSteps.java b/src/test/java/org/w3c/epubcheck/test/ExecutionSteps.java index 81729d7c6..b780e075e 100644 --- a/src/test/java/org/w3c/epubcheck/test/ExecutionSteps.java +++ b/src/test/java/org/w3c/epubcheck/test/ExecutionSteps.java @@ -9,13 +9,16 @@ import java.net.URL; import java.util.Locale; +import org.w3c.epubcheck.core.Checker; + import com.adobe.epubcheck.api.EPUBProfile; import com.adobe.epubcheck.api.EpubCheck; import com.adobe.epubcheck.api.Report; import com.adobe.epubcheck.messages.Severity; import com.adobe.epubcheck.nav.NavChecker; -import com.adobe.epubcheck.opf.DocumentValidator; -import com.adobe.epubcheck.opf.OPFCheckerFactory; +import com.adobe.epubcheck.opf.OPFChecker; +import com.adobe.epubcheck.opf.OPFChecker30; +import com.adobe.epubcheck.opf.ValidationContext; import com.adobe.epubcheck.opf.ValidationContext.ValidationContextBuilder; import com.adobe.epubcheck.ops.OPSChecker; import com.adobe.epubcheck.overlay.OverlayChecker; @@ -123,15 +126,15 @@ public void check(String path) { Locale.setDefault(defaultLocale); File testFile = getEPUBFile(basepath + path); - DocumentValidator checker = getChecker(mode, testFile, version, profile, report); - checker.validate(); + Checker checker = getChecker(mode, testFile, version, profile, report); + checker.check(); } finally { Locale.setDefault(oldDefaultLocale); } } - private DocumentValidator getChecker(CheckerMode mode, File file, EPUBVersion version, + private Checker getChecker(CheckerMode mode, File file, EPUBVersion version, EPUBProfile profile, Report report) { switch (mode) @@ -147,11 +150,11 @@ private DocumentValidator getChecker(CheckerMode mode, File file, EPUBVersion ve .resourceProvider(new FileResourceProvider(file.getPath())).report(report) .version(EPUBVersion.VERSION_3).profile(profile).build()); case PACKAGE_DOC: - return OPFCheckerFactory.getInstance() - .newInstance(new ValidationContextBuilder().path(file.getPath()) - .mimetype("application/oebps-package+xml") - .resourceProvider(new FileResourceProvider(file.getPath())).report(report) - .version(version).profile(profile).build()); + ValidationContext context = new ValidationContextBuilder().path(file.getPath()) + .mimetype("application/oebps-package+xml") + .resourceProvider(new FileResourceProvider(file.getPath())).report(report) + .version(version).profile(profile).build(); + return (context.version == EPUBVersion.VERSION_2)?new OPFChecker(context):new OPFChecker30(context); case SVG_CONTENT_DOC: return new OPSChecker(new ValidationContextBuilder().path(file.getPath()) .mimetype("image/svg+xml").resourceProvider(new FileResourceProvider(file.getPath()))