Skip to content

Commit

Permalink
feat: check the epub:textref attribute on Media Overlays body and seq…
Browse files Browse the repository at this point in the history
… elements

- Check the value of the `epub:textref` attribute when found on `body`
  or `seq` elements
- New error MED-014 is reported when a fragment has been specified in
  `epub:textref` and `src` attributes
- RSC-012 is reported when the resource referenced in `epub.textref`
  could not be found
  • Loading branch information
mattgarrish authored and rdeltour committed Dec 28, 2020
1 parent f49aa84 commit eea1574
Show file tree
Hide file tree
Showing 23 changed files with 179 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ private void initialize()
severities.put(MessageId.MED_011, Severity.ERROR);
severities.put(MessageId.MED_012, Severity.ERROR);
severities.put(MessageId.MED_013, Severity.ERROR);
severities.put(MessageId.MED_014, Severity.ERROR);

// NAV
severities.put(MessageId.NAV_001, Severity.ERROR);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/adobe/epubcheck/messages/MessageId.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ public enum MessageId implements Comparable<MessageId>
MED_011("MED_011"),
MED_012("MED_012"),
MED_013("MED_013"),
MED_014("MED_014"),

// Epub3 based table of content errors
NAV_001("NAV-001"),
Expand Down
63 changes: 37 additions & 26 deletions src/main/java/com/adobe/epubcheck/overlay/OverlayHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,29 +64,28 @@ public void startElement()
XMLElement e = parser.getCurrentElement();
String name = e.getName();

if (name.equals("smil"))
{
vocabs = VocabUtil.parsePrefixDeclaration(
e.getAttributeNS(EpubConstants.EpubTypeNamespaceUri, "prefix"), RESERVED_VOCABS,
KNOWN_VOCAB_URIS, DEFAULT_VOCAB_URIS, report,
EPUBLocation.create(path, parser.getLineNumber(), parser.getColumnNumber()));
}
else if (name.equals("seq"))
{
processSeq(e);
}
else if (name.equals("text"))
{
processSrc(e);
}
else if (name.equals("audio"))
{
processRef(e.getAttribute("src"), XRefChecker.Type.AUDIO);
checkTime(e.getAttribute("clipBegin"), e.getAttribute("clipEnd"));
}
else if (name.equals("body") || name.equals("par"))
{
checkType(e.getAttributeNS(EpubConstants.EpubTypeNamespaceUri, "type"));
switch (name) {
case "smil":
vocabs = VocabUtil.parsePrefixDeclaration(
e.getAttributeNS(EpubConstants.EpubTypeNamespaceUri, "prefix"), RESERVED_VOCABS,
KNOWN_VOCAB_URIS, DEFAULT_VOCAB_URIS, report,
EPUBLocation.create(path, parser.getLineNumber(), parser.getColumnNumber()));
break;

case "body":
case "seq":
case "par":
processGlobalAttrs(e);
break;

case "text":
processSrc(e);
break;

case "audio":
processRef(e.getAttribute("src"), XRefChecker.Type.AUDIO);
checkTime(e.getAttribute("clipBegin"), e.getAttribute("clipEnd"));
break;
}
}

Expand Down Expand Up @@ -163,6 +162,7 @@ private void processRef(String ref, XRefChecker.Type type)
}
}
else {
checkFragment(ref);
String uniqueResource = PathUtil.removeFragment(ref);
if (!Strings.isNullOrEmpty(uniqueResource)) {
if (!context.overlayTextChecker.get().add(uniqueResource, context.opfItem.get().getId())) {
Expand All @@ -175,10 +175,12 @@ private void processRef(String ref, XRefChecker.Type type)
}
}

private void processSeq(XMLElement e)
private void processGlobalAttrs(XMLElement e)
{
processRef(e.getAttributeNS(EpubConstants.EpubTypeNamespaceUri, "textref"),
XRefChecker.Type.HYPERLINK);
if (!e.getName().equals("audio")) {
processRef(e.getAttributeNS(EpubConstants.EpubTypeNamespaceUri, "textref"),
XRefChecker.Type.HYPERLINK);
}
checkType(e.getAttributeNS(EpubConstants.EpubTypeNamespaceUri, "type"));
}

Expand Down Expand Up @@ -212,4 +214,13 @@ private void checkItemReferences() {

}

private void checkFragment(String ref) {

String frag = PathUtil.getFragment(ref.trim());

if (ref.indexOf("#") == -1 || Strings.isNullOrEmpty(frag)) {
// must include a non-empty fragid
report.message(MessageId.MED_014, EPUBLocation.create(path, parser.getLineNumber(), parser.getColumnNumber()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ MED_010=EPUB Content Documents referenced from a Media Overlay must specify the
MED_011=EPUB Content Document referenced from multiple Media Overlay Documents.
MED_012=The "media-overlay" attribute does not match the ID of the Media Overlay that refers to this document.
MED_013=Media Overlay Document referenced from the "media-overlay" attribute does not contain a reference to this Content Document.
MED_014=A non-empty fragment identifier is required.

#NAV EPUB v3 Table of contents
NAV_001=The nav file is not supported for EPUB v2.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<smil xmlns="http://www.w3.org/ns/SMIL" xmlns:epub="http://www.idpf.org/2007/ops" version="3.0">
<body>
<par id="par1">
<text src="content_001.xhtml"/>
<text src="content_001.xhtml#c01"/>
<audio src="content_001.m4a"/>
</par>
</body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<title>Minimal EPUB</title>
</head>
<body>
<h1>Loomings</h1>
<h1 id="c01">Loomings</h1>
<p>Call me Ishmael.</p>
</body>
</html>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<smil xmlns="http://www.w3.org/ns/SMIL" xmlns:epub="http://www.idpf.org/2007/ops" version="3.0">
<body epub:textref="content_001.xhtml#">
<par id="par1">
<text src="content_001.xhtml"/>
<audio src="content_001.mp3"/>
</par>
</body>
</smil>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta charset="utf-8" />
<title>Minimal EPUB</title>
</head>
<body>
<h1 id="c01">Loomings</h1>
<p>Call me Ishmael.</p>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="en" lang="en">
<head>
<meta charset="utf-8"/>
<title>Minimal Nav</title>
</head>
<body>
<nav epub:type="toc">
<ol>
<li><a href="content_001.xhtml">content 001</a></li>
</ol>
</nav>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<package xmlns="http://www.idpf.org/2007/opf" version="3.0" xml:lang="en" unique-identifier="q">
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/">
<dc:title id="title">Minimal EPUB 3.0</dc:title>
<dc:language>en</dc:language>
<dc:identifier id="q">NOID</dc:identifier>
<meta property="dcterms:modified">2017-06-14T00:00:01Z</meta>
<meta property="media:duration">2.5s</meta>
<meta property="media:duration" refines="#mo_001">2.5s</meta>
</metadata>
<manifest>
<item id="content_001" href="content_001.xhtml" media-type="application/xhtml+xml" media-overlay="mo_001"/>
<item id="mo_001" href="content_001.smil" media-type="application/smil+xml"/>
<item id="audio_001" href="content_001.mp3" media-type="audio/mpeg"/>
<item id="nav" href="nav.xhtml" media-type="application/xhtml+xml" properties="nav"/>
</manifest>
<spine>
<itemref idref="content_001" />
</spine>
</package>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?>
<container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">
<rootfiles>
<rootfile full-path="EPUB/package.opf" media-type="application/oebps-package+xml"/>
</rootfiles>
</container>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
application/epub+zip
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<smil xmlns="http://www.w3.org/ns/SMIL" xmlns:epub="http://www.idpf.org/2007/ops" version="3.0">
<body>
<seq epub:textref="content_001.xhtml#c1111">
<par id="par1">
<text src="content_001.xhtml#c01"/>
<audio src="content_001.mp3"/>
</par>
</seq>
</body>
</smil>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta charset="utf-8" />
<title>Minimal EPUB</title>
</head>
<body>
<h1 id="c01">Loomings</h1>
<p>Call me Ishmael.</p>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="en" lang="en">
<head>
<meta charset="utf-8"/>
<title>Minimal Nav</title>
</head>
<body>
<nav epub:type="toc">
<ol>
<li><a href="content_001.xhtml">content 001</a></li>
</ol>
</nav>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<package xmlns="http://www.idpf.org/2007/opf" version="3.0" xml:lang="en" unique-identifier="q">
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/">
<dc:title id="title">Minimal EPUB 3.0</dc:title>
<dc:language>en</dc:language>
<dc:identifier id="q">NOID</dc:identifier>
<meta property="dcterms:modified">2017-06-14T00:00:01Z</meta>
<meta property="media:duration">2.5s</meta>
<meta property="media:duration" refines="#mo_001">2.5s</meta>
</metadata>
<manifest>
<item id="content_001" href="content_001.xhtml" media-type="application/xhtml+xml" media-overlay="mo_001"/>
<item id="mo_001" href="content_001.smil" media-type="application/smil+xml"/>
<item id="audio_001" href="content_001.mp3" media-type="audio/mpeg"/>
<item id="nav" href="nav.xhtml" media-type="application/xhtml+xml" properties="nav"/>
</manifest>
<spine>
<itemref idref="content_001" />
</spine>
</package>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?>
<container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">
<rootfiles>
<rootfile full-path="EPUB/package.opf" media-type="application/oebps-package+xml"/>
</rootfiles>
</container>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
application/epub+zip
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<smil xmlns="http://www.w3.org/ns/SMIL" xmlns:epub="http://www.idpf.org/2007/ops" version="3.0">
<body>
<par id="par1">
<text src="content_001.xhtml"/>
<text src="content_001.xhtml#c01"/>
<audio src="content_001.mp3"/>
</par>
</body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<title>Minimal EPUB</title>
</head>
<body>
<h1>Loomings</h1>
<h1 id="c01">Loomings</h1>
<p>Call me Ishmael.</p>
</body>
</html>
12 changes: 11 additions & 1 deletion src/test/resources/epub3/mediaoverlays-publication.feature
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,17 @@ Feature: EPUB 3 ▸ Media Overlays ▸ Full Publication Checks
Then error MED-011 is reported
And no other errors or warnings are reported

### The audio Element
Scenario: Report empty fragment identifiers
When checking EPUB 'mediaoverlays-fragid-invalid-error'
Then error MED-014 is reported 2 times
And no other errors or warnings are reported

Scenario: Report a fragment identifier that does not resolve to an element
When checking EPUB 'mediaoverlays-fragid-resolve-error'
Then error RSC-012 is reported
And no other errors or warnings are reported

### 2.4.8 The audio Element

Scenario: Report an audio clip that is not a Core Media Type
When checking EPUB 'mediaoverlays-audio-non-cmt-error'
Expand Down

0 comments on commit eea1574

Please sign in to comment.