it = properties.iterator();
while (it.hasNext()) {
boolean match = false;
String propertyValue = it.next();
String expectedType = itemPropertyTypeMap.get(propertyValue);
String expectedTypeArray[] = expectedType.split(" ");
for (int j = 0; j < expectedTypeArray.length; j++)
if (expectedTypeArray[j].equals(mimeType)) {
match = true;
break;
}
if (!match)
report.error(path, parser.getLineNumber(), parser.getColumnNumber(),
String.format(Messages.OPF_ITEM_PROPERTY_NOT_DEFINED, propertyValue, mimeType));
}
}
private void processLinkRel(String rel) {
if (rel == null)
return;
MetaUtils
.validateProperties(rel, linkRelSet, prefixSet, path,
parser.getLineNumber(), parser.getColumnNumber(),
report, false);
}
private void processMeta(XMLElement e) {
processMetaProperty(e.getAttribute("property"));
processMetaScheme(e.getAttribute("scheme"));
}
private void processMetaScheme(String scheme) {
if (scheme == null)
return;
MetaUtils.validateProperties(scheme, null, prefixSet, path,
parser.getLineNumber(), parser.getColumnNumber(), report, true);
}
private void processMetaProperty(String property) {
if (property == null)
return;
MetaUtils.validateProperties(property, metaPropertySet, prefixSet,
path, parser.getLineNumber(), parser.getColumnNumber(), report,
true);
}
}
epubcheck-3.0.1/src/main/java/com/adobe/epubcheck/opf/ContentCheckerFactory.java 0000755 0001750 0001750 00000003024 12150645332 027044 0 ustar eugene eugene /*
* 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.Report;
import com.adobe.epubcheck.ocf.OCFPackage;
import com.adobe.epubcheck.util.EPUBVersion;
public interface ContentCheckerFactory {
public ContentChecker newInstance(OCFPackage ocf, Report report,
String path, String mimeType, String properties,
XRefChecker xrefChecker, EPUBVersion version);
}
epubcheck-3.0.1/src/main/java/com/adobe/epubcheck/opf/VersionRetriever.java 0000644 0001750 0001750 00000012613 12150645332 026133 0 ustar eugene eugene /*
* 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 java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.Attributes;
import org.xml.sax.EntityResolver;
import org.xml.sax.ErrorHandler;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.helpers.DefaultHandler;
import com.adobe.epubcheck.api.Report;
import com.adobe.epubcheck.util.EPUBVersion;
import com.adobe.epubcheck.util.FeatureEnum;
import com.adobe.epubcheck.util.InvalidVersionException;
public class VersionRetriever implements EntityResolver, ErrorHandler {
private class OPFhandler extends DefaultHandler {
@Override
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
if ("package".equals(localName))
processPackage(attributes);
else
throw new SAXException(
InvalidVersionException.PACKAGE_ELEMENT_NOT_FOUND);
}
private void processPackage(Attributes attributes) throws SAXException {
String version = attributes.getValue("version");
if (version == null)
throw new SAXException(
InvalidVersionException.VERSION_ATTRIBUTE_NOT_FOUND);
else if (VERSION_3.equals(version))
throw new SAXException(VERSION_3);
else if (VERSION_2.equals(version))
throw new SAXException(VERSION_2);
throw new SAXException(InvalidVersionException.UNSUPPORTED_VERSION);
}
}
public static final String VERSION_3 = "3.0";
public static final String VERSION_2 = "2.0";
private Report report;
private String path;
public VersionRetriever(String path, Report report) {
this.path = path;
this.report = report;
}
public EPUBVersion retrieveOpfVersion(InputStream inputStream)
throws InvalidVersionException {
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setNamespaceAware(true);
factory.setValidating(false);
try {
factory.setFeature("http://xml.org/sax/features/validation", false);
} catch (Exception e) {
}
SAXParser parser;
try {
parser = factory.newSAXParser();
parser.getXMLReader().setEntityResolver(this);
parser.getXMLReader().setErrorHandler(this);
parser.getXMLReader().setContentHandler(new OPFhandler());
parser.getXMLReader().parse(new InputSource(inputStream));
} catch (ParserConfigurationException e) {
report.exception(path, e);
} catch (SAXException e) {
if (VERSION_3.equals(e.getMessage())) {
report.info(null, FeatureEnum.FORMAT_VERSION, EPUBVersion.VERSION_3.toString());
return EPUBVersion.VERSION_3;
} else if (VERSION_2.equals(e.getMessage())) {
report.info(null, FeatureEnum.FORMAT_VERSION, EPUBVersion.VERSION_2.toString());
return EPUBVersion.VERSION_2;
} else if (InvalidVersionException.UNSUPPORTED_VERSION.equals(e
.getMessage()))
throw new InvalidVersionException(
InvalidVersionException.UNSUPPORTED_VERSION);
else if (InvalidVersionException.VERSION_ATTRIBUTE_NOT_FOUND
.equals(e.getMessage()))
throw new InvalidVersionException(
InvalidVersionException.VERSION_ATTRIBUTE_NOT_FOUND);
else if (InvalidVersionException.PACKAGE_ELEMENT_NOT_FOUND.equals(e
.getMessage()))
throw new InvalidVersionException(
InvalidVersionException.PACKAGE_ELEMENT_NOT_FOUND);
else
report.exception(path, e);
} catch (IOException e) {
report.error(path, 0, 0, e.getMessage());
}
throw new InvalidVersionException(
InvalidVersionException.VERSION_NOT_FOUND);
}
@Override
public InputSource resolveEntity(String arg0, String arg1) throws SAXException, IOException {
return new InputSource(new StringReader(""));
}
@Override
public void error(SAXParseException arg0) throws SAXException {
// TODO Auto-generated method stub
}
@Override
public void fatalError(SAXParseException arg0) throws SAXException {
// TODO Auto-generated method stub
}
@Override
public void warning(SAXParseException arg0) throws SAXException {
// TODO Auto-generated method stub
}
}
epubcheck-3.0.1/src/main/java/com/adobe/epubcheck/opf/OPFDataImpl.java 0000644 0001750 0001750 00000000673 12150645332 024661 0 ustar eugene eugene package com.adobe.epubcheck.opf;
import com.adobe.epubcheck.util.EPUBVersion;
public class OPFDataImpl implements OPFData {
private final EPUBVersion version;
public OPFDataImpl(EPUBVersion version) {
this.version = version;
}
@Override
public EPUBVersion getVersion() {
return version;
}
@Override
public String getUniqueIdentifier() {
throw new UnsupportedOperationException("OPF ID peeking is not implemented.");
}
}
epubcheck-3.0.1/src/main/java/com/adobe/epubcheck/opf/DocumentValidatorFactory.java 0000644 0001750 0001750 00000003026 12150645332 027570 0 ustar eugene eugene /*
* 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.Report;
import com.adobe.epubcheck.util.EPUBVersion;
import com.adobe.epubcheck.util.GenericResourceProvider;
public interface DocumentValidatorFactory {
public DocumentValidator newInstance(Report report, String path,
GenericResourceProvider resourceProvider, String mimeType,
EPUBVersion version);
}
epubcheck-3.0.1/src/main/java/com/adobe/epubcheck/api/ 0000755 0001750 0001750 00000000000 12150645332 021735 5 ustar eugene eugene epubcheck-3.0.1/src/main/java/com/adobe/epubcheck/api/EpubCheckFactory.java 0000644 0001750 0001750 00000004214 12150645332 025762 0 ustar eugene eugene /*
* 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.api;
import java.io.File;
import java.io.IOException;
import com.adobe.epubcheck.api.Report;
import com.adobe.epubcheck.opf.DocumentValidator;
import com.adobe.epubcheck.opf.DocumentValidatorFactory;
import com.adobe.epubcheck.util.EPUBVersion;
import com.adobe.epubcheck.util.GenericResourceProvider;
public class EpubCheckFactory implements DocumentValidatorFactory {
static private EpubCheckFactory instance = new EpubCheckFactory();
static public EpubCheckFactory getInstance() {
return instance;
}
public DocumentValidator newInstance(Report report, String path,
GenericResourceProvider resourceProvider, String mimeType,
EPUBVersion version) {
if (path.startsWith("http://") || path.startsWith("https://"))
try {
return new EpubCheck(resourceProvider.getInputStream(path),
report, path);
} catch (IOException e) {
throw new RuntimeException(e);
}
else
return new EpubCheck(new File(path), report);
}
}
epubcheck-3.0.1/src/main/java/com/adobe/epubcheck/api/EpubCheck.java 0000644 0001750 0001750 00000015504 12150645332 024436 0 ustar eugene eugene /*
* 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.api;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Properties;
import java.util.zip.ZipFile;
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.util.CheckUtil;
import com.adobe.epubcheck.util.DefaultReportImpl;
import com.adobe.epubcheck.util.EPUBVersion;
import com.adobe.epubcheck.util.Messages;
import com.adobe.epubcheck.util.ResourceUtil;
import com.adobe.epubcheck.util.WriterReportImpl;
/**
* Public interface to epub validator.
*/
public class EpubCheck implements DocumentValidator {
private static String VERSION = null;
private static String BUILD_DATE = null;
public static String version() {
if (VERSION == null) {
Properties prop = new Properties();
InputStream in = EpubCheck.class.getResourceAsStream("project.properties");
try {
prop.load(in);
} catch (Exception e) {
System.err.println("Couldn't read project properties: " + e.getMessage());
} finally {
if (in != null){
try {
in.close();
} catch (IOException e) {}
}
}
VERSION = prop.getProperty("version");
BUILD_DATE = prop.getProperty("buildDate");
}
return VERSION;
}
public static String buildDate() {
return BUILD_DATE;
}
private File epubFile;
private Report report;
private EPUBVersion version;
/*
* Create an epub validator to validate the given file. Issues will be
* reported to standard error.
*/
public EpubCheck(File epubFile) {
this(epubFile, new DefaultReportImpl(epubFile.getName()));
}
/*
* Create an epub validator to validate the given file. Issues will be
* reported to the given PrintWriter.
*/
public EpubCheck(File epubFile, PrintWriter out) {
this(epubFile, new WriterReportImpl(out));
}
/*
* Create an epub validator to validate the given file and report issues to
* a given Report object.
*/
public EpubCheck(File epubFile, Report report) {
this(epubFile, report, null);
}
public EpubCheck(File epubFile, Report report, EPUBVersion version) {
this.epubFile = epubFile;
this.report = report;
this.version = version;
}
public EpubCheck(InputStream inputStream, Report report, String uri) {
this(inputStream, report, uri, null);
}
public EpubCheck(InputStream inputStream, Report report, String uri,
EPUBVersion version) {
File epubFile;
OutputStream out = null;
try {
epubFile = File.createTempFile("epub." + ResourceUtil.getExtension(uri), null);
epubFile.deleteOnExit();
out = new FileOutputStream(epubFile);
byte[] bytes = new byte[1024];
int read;
while ((read = inputStream.read(bytes)) != -1) {
out.write(bytes, 0, read);
}
this.epubFile = epubFile;
this.report = report;
this.version = version;
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
try{
inputStream.close();
out.flush();
out.close();
}catch (Exception e) {
}
}
}
/**
* Validate the file. Return true if no errors or warnings found.
*/
public boolean validate() {
ZipFile zip = null;
FileInputStream epubIn = null;
try {
String extension = ResourceUtil.getExtension(epubFile.getName());
if(extension != null) {
if(!extension.equals("epub")) {
if(extension.matches("[Ee][Pp][Uu][Bb]")){
report.warning(epubFile.getName(), -1, -1,
"Use only lowercase characters for the EPUB file extension for maximum compatibility");
} else {
report.warning(epubFile.getName(), -1, -1,
"Uncommon EPUB file extension'" + extension + "'. For maximum compatibility, use '.epub'");
}
}
}
epubIn = new FileInputStream(epubFile);
byte[] header = new byte[58];
int readCount = epubIn.read(header);
if (readCount != -1) {
while (readCount < header.length) {
int read = epubIn.read(header, readCount, header.length
- readCount);
// break on eof
if (read == -1)
break;
readCount += read;
}
}
if (readCount != header.length) {
report.error(null, 0, 0, Messages.CANNOT_READ_HEADER);
} else {
int extsize = getIntFromBytes(header, 28);
if (header[0] != 'P' && header[1] != 'K') {
report.error(null, 0, 0, Messages.CORRUPTED_ZIP_HEADER);
} else if (!CheckUtil.checkString(header, 30, "mimetype")) {
report.error(null, 0, 0, Messages.MIMETYPE_ENTRY_MISSING);
} else if (extsize != 0) {
report.error(null, 0, 0,
String.format(Messages.EXTRA_FIELD_LENGTH, extsize));
} else if (!CheckUtil.checkString(header, 38,
"application/epub+zip")) {
report.error(null, 0, 0, String.format(
Messages.MIMETYPE_WRONG_TYPE,
"application/epub+zip"));
}
}
zip = new ZipFile(epubFile);
OCFPackage ocf = new OCFZipPackage(zip);
OCFChecker checker = new OCFChecker(ocf, report, version);
checker.runChecks();
} catch (IOException e) {
report.error(null, 0, 0,
String.format(Messages.IO_ERROR, e.getMessage()));
} finally {
try{
epubIn.close();
zip.close();
}catch (Exception e) {
}
}
return report.getWarningCount() == 0 && report.getErrorCount() == 0;
}
private int getIntFromBytes(byte[] bytes, int offset) {
int hi = 0xFF & bytes[offset + 1];
int lo = 0xFF & bytes[offset + 0];
return hi << 8 | lo;
}
}
epubcheck-3.0.1/src/main/java/com/adobe/epubcheck/api/Report.java 0000755 0001750 0001750 00000007657 12150645332 024075 0 ustar eugene eugene /*
* 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.api;
import com.adobe.epubcheck.util.FeatureEnum;
/**
* Interface that is used to report issues found in epub.
*/
public interface Report {
/**
* Called when a violation of the standard is found in the epub.
*
* @param resource
* name of the resource in the epub zip container that caused
* error or null if the error is on the container level.
* @param line
* line number in the resource which has caused error (lines
* start with 1), non-positive number if the resource is not text
* or line is not available.
* @param message
* error message.
*/
public void error(String resource, int line, int column, String message);
/**
* Called when some notable issue is found in the epub.
*
* @param resource
* name of the resource in the epub zip container that caused
* warning or null if the error is on the container level.
* @param line
* line number in the resource which has caused warning (lines
* start with 1), non-positive number if the resource is not text
* or line is not available.
* @param message
* warning message.
*/
public void warning(String resource, int line, int column, String message);
public void exception(String resource, Exception e);
public int getErrorCount();
public int getWarningCount();
public int getExceptionCount();
/**
* Called when when a feature is found in epub.
*
* @param resource
* name of the resource in the epub zip container that has this
* feature or null if the feature is on the container level.
* @param feature
* a keyword to know what kind of feature has been found
* @param value
* value found
*/
public void info(String resource, FeatureEnum feature, String value);
/**
* Called when a construct is detected that neither constitutes an error or
* a warning state, but for which information is issued anyway, as there
* may be reasons in certain contexts to check and/or adjust the construct.
*
* Like {@link #info(String, FeatureEnum, String)}, an invocation of this
* method shall not be interpreted as a content anomaly.
*
* @param resource
* name of the resource in the epub zip container in which the
* construct occurs.
* @param line
* line number in the resource on which the construct occurs
* @param column
* column number in the resource on which the construct occurs
* @param message
* message describing the detected construct
*/
public void hint(String resource, int line, int column, String message);
}
epubcheck-3.0.1/src/main/java/com/adobe/epubcheck/ops/ 0000755 0001750 0001750 00000000000 12150645332 021765 5 ustar eugene eugene epubcheck-3.0.1/src/main/java/com/adobe/epubcheck/ops/OPSHandler30.java 0000644 0001750 0001750 00000024502 12150645332 024735 0 ustar eugene eugene package com.adobe.epubcheck.ops;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import com.adobe.epubcheck.api.Report;
import com.adobe.epubcheck.ocf.OCFPackage;
import com.adobe.epubcheck.opf.OPFChecker;
import com.adobe.epubcheck.opf.OPFChecker30;
import com.adobe.epubcheck.opf.XRefChecker;
import com.adobe.epubcheck.util.EPUBVersion;
import com.adobe.epubcheck.util.EpubTypeAttributes;
import com.adobe.epubcheck.util.HandlerUtil;
import com.adobe.epubcheck.util.Messages;
import com.adobe.epubcheck.util.MetaUtils;
import com.adobe.epubcheck.util.PathUtil;
import com.adobe.epubcheck.xml.XMLElement;
import com.adobe.epubcheck.xml.XMLParser;
public class OPSHandler30 extends OPSHandler {
String properties;
HashSet prefixSet;
HashSet propertiesSet;
String mimeType;
boolean video = false;
boolean audio = false;
boolean hasValidFallback = false;
int imbricatedObjects = 0;
int imbricatedCanvases = 0;
public static HashSet linkClassSet;
boolean reportedUnsupportedXMLVersion;
static {
HashSet set = new HashSet();
set.add("vertical");
set.add("horizontal");
set.add("day");
set.add("night");
linkClassSet = set;
}
public OPSHandler30(OCFPackage ocf, String path, String mimeType, String properties,
XRefChecker xrefChecker, XMLParser parser, Report report, EPUBVersion version) {
super(ocf, path, xrefChecker, parser, report, version);
this.mimeType = mimeType;
this.properties = properties;
prefixSet = new HashSet();
propertiesSet = new HashSet();
reportedUnsupportedXMLVersion = false;
}
boolean checkPrefix(String prefix) {
prefix = prefix.trim();
if (!prefixSet.contains(prefix)) {
report.error(path, parser.getLineNumber(),
parser.getColumnNumber(), "Undecleared prefix: " + prefix);
return false;
}
return true;
}
private void checkType(String type) {
if (type == null)
return;
MetaUtils.validateProperties(type, EpubTypeAttributes.EpubTypeSet,
prefixSet, path, parser.getLineNumber(),
parser.getColumnNumber(), report, false);
}
private void checkSSMLPh(String ph) {
//issue 139; enhancement is to add real syntax check for IPA and x-SAMPA
if(ph == null)
return;
if (ph.trim().length() < 1)
report.warning(path, parser.getLineNumber(),
parser.getColumnNumber(), "Empty or whitespace-only value of attribute ssml:ph");
}
@Override
public void characters(char[] chars, int arg1, int arg2) {
super.characters(chars, arg1, arg2);
String str = new String(chars, arg1, arg2);
str = str.trim();
if (!str.equals("")
&& (audio || video || imbricatedObjects > 0 || imbricatedCanvases > 0))
hasValidFallback = true;
}
public void startElement() {
super.startElement();
if (!reportedUnsupportedXMLVersion)
reportedUnsupportedXMLVersion = HandlerUtil.checkXMLVersion(parser);
XMLElement e = parser.getCurrentElement();
String name = e.getName();
if (name.equals("html"))
HandlerUtil.processPrefixes(
e.getAttributeNS("http://www.idpf.org/2007/ops", "prefix"),
prefixSet, report, path, parser.getLineNumber(),
parser.getColumnNumber());
else if (name.equals("link"))
processLink(e);
else if (name.equals("object"))
processObject(e);
else if (name.equals("math"))
propertiesSet.add("mathml");
else if (!mimeType.equals("image/svg+xml") && name.equals("svg"))
propertiesSet.add("svg");
else if (name.equals("script"))
propertiesSet.add("scripted");
else if (name.equals("switch"))
propertiesSet.add("switch");
else if (name.equals("audio"))
processAudio(e);
else if (name.equals("video"))
processVideo(e);
else if (name.equals("canvas"))
processCanvas(e);
else if (name.equals("img"))
processImg(e);
processSrc(("source".equals(name)) ? e.getParent().getName() : name, e.getAttribute("src"));
checkType(e.getAttributeNS("http://www.idpf.org/2007/ops", "type"));
checkSSMLPh(e.getAttributeNS("http://www.w3.org/2001/10/synthesis", "ph"));
}
private void processLink(XMLElement e) {
String classAttribute = e.getAttribute("class");
if (classAttribute == null)
return;
Set values = MetaUtils.validateProperties(classAttribute,
linkClassSet, null, path, parser.getLineNumber(),
parser.getColumnNumber(), report, false);
if (values.size() == 1)
return;
boolean vertical = false, horizontal = false, day = false, night = false;
Iterator it = values.iterator();
while (it.hasNext()) {
String attribute = it.next();
if (attribute.equals("vertical"))
vertical = true;
else if (attribute.equals("horizontal"))
horizontal = true;
else if (attribute.equals("day"))
day = true;
else if (attribute.equals("night"))
night = true;
}
if (vertical && horizontal || day && night)
report.error(path, parser.getLineNumber(),
parser.getColumnNumber(), Messages.CONFLICTING_ATTRIBUTES
+ classAttribute);
}
private void processImg(XMLElement e) {
if ((audio || video || imbricatedObjects > 0 || imbricatedCanvases > 0))
hasValidFallback = true;
}
private void processCanvas(XMLElement e) {
imbricatedCanvases++;
}
private void processAudio(XMLElement e) {
audio = true;
}
private void processVideo(XMLElement e) {
video = true;
String posterSrc = e.getAttribute("poster");
String posterMimeType = null;
if (xrefChecker != null && posterSrc != null)
posterMimeType = xrefChecker.getMimeType(PathUtil
.resolveRelativeReference(path, posterSrc, base));
if (posterMimeType != null
&& !OPFChecker.isBlessedImageType(posterMimeType))
report.error(path, parser.getLineNumber(),
parser.getColumnNumber(),
"Video poster must have core media image type");
if (posterSrc != null) {
hasValidFallback = true;
processSrc(e.getName(), posterSrc);
}
}
private void processSrc(String name, String src) {
if (src != null) {
src.trim();
if (src.equals(""))
report.error(path, parser.getLineNumber(),
parser.getColumnNumber(),
"The src attribute must not be empty");
}
if (src == null || xrefChecker == null)
return;
if (src.matches("^[^:/?#]+://.*"))
propertiesSet.add("remote-resources");
else
src = PathUtil.resolveRelativeReference(path, src, base);
int refType;
if ("audio".equals(name)) {
refType = XRefChecker.RT_AUDIO;
} else if ("video".equals(name)) {
refType = XRefChecker.RT_VIDEO;
} else {
refType = XRefChecker.RT_GENERIC;
}
xrefChecker.registerReference(path, parser.getLineNumber(),
parser.getColumnNumber(), src, refType);
String srcMimeType = xrefChecker.getMimeType(src);
if (srcMimeType == null)
return;
if (!mimeType.equals("image/svg+xml")
&& srcMimeType.equals("image/svg+xml"))
propertiesSet.add("svg");
if ((audio || video || imbricatedObjects > 0 || imbricatedCanvases > 0)
&& OPFChecker30.isCoreMediaType(srcMimeType)
&& !name.equals("track"))
hasValidFallback = true;
}
private void processObject(XMLElement e) {
imbricatedObjects++;
String type = e.getAttribute("type");
String data = e.getAttribute("data");
if (data != null) {
processSrc(e.getName(), data);
data = PathUtil.resolveRelativeReference(path, data, base);
}
if (type != null && data != null && xrefChecker != null
&& !type.equals(xrefChecker.getMimeType(data)))
report.error(path, parser.getLineNumber(),
parser.getColumnNumber(),
"Object type and the item media-type declared in manifest, do not match");
if (type != null) {
if (!mimeType.equals("image/svg+xml")
&& type.equals("image/svg+xml"))
propertiesSet.add("svg");
if (OPFChecker30.isCoreMediaType(type))
hasValidFallback = true;
}
if (hasValidFallback)
return;
// check bindings
if (xrefChecker != null && type != null
&& xrefChecker.getBindingHandlerSrc(type) != null)
hasValidFallback = true;
}
@Override
public void endElement() {
super.endElement();
XMLElement e = parser.getCurrentElement();
String name = e.getName();
if (openElements == 0 && (name.equals("html") || name.equals("svg"))) {
checkProperties();
} else if (name.equals("object")) {
imbricatedObjects--;
if (imbricatedObjects == 0 && imbricatedCanvases == 0)
checkFallback("Object");
} else if (name.equals("canvas")) {
imbricatedCanvases--;
if (imbricatedObjects == 0 && imbricatedCanvases == 0)
checkFallback("Canvas");
} else if (name.equals("video")) {
if (imbricatedObjects == 0 && imbricatedCanvases == 0)
checkFallback("Video");
video = false;
} else if (name.equals("audio")) {
if (imbricatedObjects == 0 && imbricatedCanvases == 0)
checkFallback("Audio");
audio = false;
}
}
/*
* Checks fallbacks for video, audio and object elements
*/
private void checkFallback(String elementType) {
if (hasValidFallback)
hasValidFallback = false;
else
report.error(path, parser.getLineNumber(),
parser.getColumnNumber(), elementType
+ " element doesn't provide fallback");
}
private void checkProperties() {
Set props = new HashSet(Arrays.asList((properties!=null)?properties.split("\\s+"):new String[]{}));
;
if (props.contains("singleFileValidation"))
return;
props.remove("nav");
props.remove("cover-image");
Iterator propertyIterator = propertiesSet.iterator();
while (propertyIterator.hasNext()) {
String prop = propertyIterator.next();
if (props.contains(prop))
props.remove(prop);
else
report.error(path, 0, 0,
"This file should declare in the OPF the property: " + prop);
}
if (props.contains("remote-resources")) {
props.remove("remote-resources");
report.warning(path, 0, 0,
"This file has the 'remote-resources' property declared in the OPF, but no reference to remote resources has been found. Make sure this property is legitimate.");
}
if (!props.isEmpty())
report.error(path, 0, 0,
"This file should not declare in the OPF the properties: "
+ properties);
}
}
epubcheck-3.0.1/src/main/java/com/adobe/epubcheck/ops/OPSCheckerFactory.java 0000755 0001750 0001750 00000004557 12150645332 026124 0 ustar eugene eugene /*
* 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.api.Report;
import com.adobe.epubcheck.ocf.OCFPackage;
import com.adobe.epubcheck.opf.ContentChecker;
import com.adobe.epubcheck.opf.ContentCheckerFactory;
import com.adobe.epubcheck.opf.DocumentValidator;
import com.adobe.epubcheck.opf.DocumentValidatorFactory;
import com.adobe.epubcheck.opf.XRefChecker;
import com.adobe.epubcheck.util.EPUBVersion;
import com.adobe.epubcheck.util.GenericResourceProvider;
public class OPSCheckerFactory implements ContentCheckerFactory,
DocumentValidatorFactory {
public ContentChecker newInstance(OCFPackage ocf, Report report,
String path, String mimeType, String properties,
XRefChecker xrefChecker, EPUBVersion version) {
return new OPSChecker(ocf, report, path, mimeType, properties,
xrefChecker, version);
}
static private OPSCheckerFactory instance = new OPSCheckerFactory();
static public OPSCheckerFactory getInstance() {
return instance;
}
public DocumentValidator newInstance(Report report, String path,
GenericResourceProvider resourceProvider, String mimeType,
EPUBVersion version) {
return new OPSChecker(path, mimeType, resourceProvider, report, version);
}
}
epubcheck-3.0.1/src/main/java/com/adobe/epubcheck/ops/OPSHandler.java 0000755 0001750 0001750 00000025373 12150645332 024604 0 ustar eugene eugene /*
* 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 java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashSet;
import javax.xml.XMLConstants;
import com.adobe.epubcheck.api.Report;
import com.adobe.epubcheck.css.CSSCheckerFactory;
import com.adobe.epubcheck.ocf.OCFPackage;
import com.adobe.epubcheck.opf.XRefChecker;
import com.adobe.epubcheck.util.EPUBVersion;
import com.adobe.epubcheck.util.FeatureEnum;
import com.adobe.epubcheck.util.Messages;
import com.adobe.epubcheck.util.PathUtil;
import com.adobe.epubcheck.xml.XMLElement;
import com.adobe.epubcheck.xml.XMLHandler;
import com.adobe.epubcheck.xml.XMLParser;
public class OPSHandler implements XMLHandler {
String path;
/** null unless head/base or xml:base is given */
protected String base;
XRefChecker xrefChecker;
static HashSet regURISchemes = fillRegURISchemes();
XMLParser parser;
OCFPackage ocf;
Report report;
EPUBVersion version;
long openElements;
long charsCount;
StringBuilder textNode;
public OPSHandler(OCFPackage ocf, String path, XRefChecker xrefChecker, XMLParser parser,
Report report, EPUBVersion version) {
this.ocf = ocf;
this.path = path;
this.xrefChecker = xrefChecker;
this.report = report;
this.parser = parser;
this.version = version;
}
private void checkPaint(XMLElement e, String attr) {
String paint = e.getAttribute(attr);
if (xrefChecker != null && paint != null && paint.startsWith("url(")
&& paint.endsWith(")")) {
String href = paint.substring(4, paint.length() - 1);
href = PathUtil.resolveRelativeReference(path, href, base);
xrefChecker.registerReference(path, parser.getLineNumber(),
parser.getColumnNumber(), href, XRefChecker.RT_SVG_PAINT);
}
}
private void checkClip(XMLElement e, String attr) {
}
private void checkImage(XMLElement e, String attrNS, String attr) {
String href = e.getAttributeNS(attrNS, attr);
if (xrefChecker != null && href != null) {
href = PathUtil.resolveRelativeReference(path, href, base);
xrefChecker.registerReference(path, parser.getLineNumber(),
parser.getColumnNumber(), href, XRefChecker.RT_IMAGE);
}
}
private void checkObject(XMLElement e, String attrNS, String attr) {
String href = e.getAttributeNS(attrNS, attr);
if (xrefChecker != null && href != null) {
href = PathUtil.resolveRelativeReference(path, href, base);
xrefChecker.registerReference(path, parser.getLineNumber(),
parser.getColumnNumber(), href, XRefChecker.RT_OBJECT);
}
}
private void checkLink(XMLElement e, String attrNS, String attr) {
String href = e.getAttributeNS(attrNS, attr);
String rel = e.getAttributeNS(attrNS, "rel");
if (xrefChecker != null && href != null && rel != null
&& rel.indexOf("stylesheet") >= 0) {
href = PathUtil.resolveRelativeReference(path, href, base);
xrefChecker.registerReference(path, parser.getLineNumber(),
parser.getColumnNumber(), href, XRefChecker.RT_STYLESHEET);
}
}
private void checkSymbol(XMLElement e, String attrNS, String attr) {
String href = e.getAttributeNS(attrNS, attr);
if (xrefChecker != null && href != null) {
href = PathUtil.resolveRelativeReference(path, href, base);
xrefChecker.registerReference(path, parser.getLineNumber(),
parser.getColumnNumber(), href, XRefChecker.RT_SVG_SYMBOL);
}
}
private void checkHRef(XMLElement e, String attrNS, String attr) {
String href = e.getAttributeNS(attrNS, attr);
//System.out.println("HREF: '" + href +"'");
if(href == null) {
return;
}
if(href.contains("#epubcfi")) {
return; //temp until cfi implemented
}
href = href.trim();
if (href.length() < 1) {
//if href="" then selfreference which is valid,
//but as per issue 225, issue a hint
report.hint(path, parser.getLineNumber(),
parser.getColumnNumber(), Messages.EMPTY_HREF);
return;
}
if (".".equals(href)) {
//selfreference, no need to check
}
if (href.startsWith("http")) {
report.info(path, FeatureEnum.REFERENCE, href);
}
/*
* mgy 20120417 adding check for base to initial if clause as part
* of solution to issue 155
*/
if (isRegisteredSchemeType(href) || (null != base && isRegisteredSchemeType(base))) {
return;
}
// This if statement is needed to make sure XML Fragment identifiers
// are not reported as non-registered URI scheme types
else if (href.indexOf(':') > 0) {
report.warning(path, parser.getLineNumber(),
parser.getColumnNumber(),
"use of non-registered URI scheme type in href: "
+ href);
return;
}
try {
href = PathUtil.resolveRelativeReference(path, href, base);
} catch (IllegalArgumentException err) {
report.error(path, parser.getLineNumber(),
parser.getColumnNumber(), err.getMessage());
return;
}
if (xrefChecker != null)
xrefChecker.registerReference(path, parser.getLineNumber(),
parser.getColumnNumber(), href,
XRefChecker.RT_HYPERLINK);
}
public static boolean isRegisteredSchemeType(String href) {
int colonIndex = href.indexOf(':');
if (colonIndex < 0)
return false;
else if (regURISchemes.contains(href.substring(0, colonIndex + 1)))
return true;
else if (href.length() > colonIndex + 2)
if (href.substring(colonIndex + 1, colonIndex + 3).equals("//")
&& regURISchemes
.contains(href.substring(0, colonIndex + 3)))
return true;
else
return false;
else
return false;
}
public void startElement() {
openElements++;
XMLElement e = parser.getCurrentElement();
String id = e.getAttribute("id");
String baseTest = e.getAttributeNS(XMLConstants.XML_NS_URI, "base");
if(baseTest != null) {
base = baseTest;
}
String ns = e.getNamespace();
String name = e.getName();
int resourceType = XRefChecker.RT_GENERIC;
if (ns != null) {
if (ns.equals("http://www.w3.org/2000/svg")) {
if (name.equals("linearGradient")
|| name.equals("radialGradient")
|| name.equals("pattern"))
resourceType = XRefChecker.RT_SVG_PAINT;
else if (name.equals("clipPath"))
resourceType = XRefChecker.RT_SVG_CLIP_PATH;
else if (name.equals("symbol"))
resourceType = XRefChecker.RT_SVG_SYMBOL;
else if (name.equals("a"))
checkHRef(e, "http://www.w3.org/1999/xlink", "href");
else if (name.equals("use"))
checkSymbol(e, "http://www.w3.org/1999/xlink", "href");
else if (name.equals("image"))
checkImage(e, "http://www.w3.org/1999/xlink", "href");
checkPaint(e, "fill");
checkPaint(e, "stroke");
checkClip(e, "clip");
} else if (ns.equals("http://www.w3.org/1999/xhtml")) {
if (name.equals("a"))
checkHRef(e, null, "href");
else if (name.equals("img"))
checkImage(e, null, "src");
else if (name.equals("object"))
checkObject(e, null, "data");
else if (name.equals("link"))
checkLink(e, null, "href");
else if (name.equals("base"))
base = e.getAttribute("href");
else if (name.equals("style"))
textNode = new StringBuilder();
resourceType = XRefChecker.RT_HYPERLINK;
String style = e.getAttribute("style");
if(style!=null && style.length()>0) {
CSSCheckerFactory.getInstance().newInstance(
ocf, report, style, true, path,
parser.getLineNumber(),
parser.getColumnNumber(), xrefChecker, version).runChecks();
}
}
}
if (xrefChecker != null && id != null)
xrefChecker.registerAnchor(path, parser.getLineNumber(),
parser.getColumnNumber(), id, resourceType);
}
public void endElement() {
openElements--;
XMLElement e = parser.getCurrentElement();
String ns = e.getNamespace();
String name = e.getName();
if (openElements == 0) {
report.info(path, FeatureEnum.CHARS_COUNT, Long.toString(charsCount));
}
if ("http://www.w3.org/1999/xhtml".equals(ns) && "script".equals(name)) {
String attr = e.getAttribute("type");
report.info(path, FeatureEnum.HAS_SCRIPTS, (attr==null)?"":attr);
}
if ("http://www.w3.org/1999/xhtml".equals(ns) && "style".equals(name)) {
String style = textNode.toString();
if(style.length()>0) {
CSSCheckerFactory.getInstance().newInstance(
ocf, report, style, false, path,
parser.getLineNumber(),
parser.getColumnNumber(), xrefChecker, version).runChecks();
}
textNode = null;
}
}
public void ignorableWhitespace(char[] chars, int arg1, int arg2) {
}
public void characters(char[] chars, int start, int length) {
charsCount += length;
if(textNode != null) {
textNode.append(chars, start, length);
}
}
public void processingInstruction(String arg0, String arg1) {
}
private static HashSet fillRegURISchemes() {
InputStream schemaStream = null;
BufferedReader schemaReader = null;
try {
HashSet set = new HashSet();
schemaStream = OPSHandler.class
.getResourceAsStream("registeredSchemas.txt");
schemaReader = new BufferedReader(
new InputStreamReader(schemaStream));
String schema = schemaReader.readLine();
while (schema != null) {
set.add(schema);
schema = schemaReader.readLine();
}
return set;
} catch (Exception e) {
e.printStackTrace();
} finally {
try{
schemaReader.close();
schemaStream.close();
}catch (Exception e) {
}
}
return null;
}
}
epubcheck-3.0.1/src/main/java/com/adobe/epubcheck/ops/OPSChecker.java 0000755 0001750 0001750 00000014512 12150645332 024564 0 ustar eugene eugene /*
* 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 java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import com.adobe.epubcheck.api.Report;
import com.adobe.epubcheck.ocf.OCFPackage;
import com.adobe.epubcheck.opf.ContentChecker;
import com.adobe.epubcheck.opf.DocumentValidator;
import com.adobe.epubcheck.opf.XRefChecker;
import com.adobe.epubcheck.util.EPUBVersion;
import com.adobe.epubcheck.util.GenericResourceProvider;
import com.adobe.epubcheck.util.OPSType;
import com.adobe.epubcheck.xml.XMLParser;
import com.adobe.epubcheck.xml.XMLValidator;
public class OPSChecker implements ContentChecker, DocumentValidator {
class EpubValidator {
XMLValidator xmlValidator = null;
XMLValidator schValidator = null;
public EpubValidator(XMLValidator xmlValidator,
XMLValidator schValidator) {
this.xmlValidator = xmlValidator;
this.schValidator = schValidator;
}
}
OCFPackage ocf;
Report report;
String path;
String mimeType;
XRefChecker xrefChecker;
EPUBVersion version;
private OPSHandler opsHandler = null;
GenericResourceProvider resourceProvider;
String properties;
static XMLValidator xhtmlValidator_20_NVDL = new XMLValidator(
"schema/20/rng/ops20.nvdl");
static XMLValidator svgValidator_20_RNG = new XMLValidator(
"schema/20/rng/svg11.rng");
static XMLValidator xhtmlValidator_30_RNC = new XMLValidator(
"schema/30/epub-xhtml-30.rnc");
static XMLValidator svgValidator_30_RNC = new XMLValidator(
"schema/30/epub-svg-30.rnc");
static XMLValidator xhtmlValidator_30_ISOSCH = new XMLValidator(
"schema/30/epub-xhtml-30.sch");
static XMLValidator svgValidator_30_ISOSCH = new XMLValidator(
"schema/30/epub-svg-30.sch");
static XMLValidator idUniqueValidator_20_ISOSCH = new XMLValidator(
"schema/20/sch/id-unique.sch");
private HashMap epubValidatorMap;
private void initEpubValidatorMap() {
HashMap