Skip to content

Commit eea1574

Browse files
mattgarrishrdeltour
authored andcommitted
feat: check the epub:textref attribute on Media Overlays body and seq 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
1 parent f49aa84 commit eea1574

File tree

23 files changed

+179
-31
lines changed

23 files changed

+179
-31
lines changed

src/main/java/com/adobe/epubcheck/messages/DefaultSeverities.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ private void initialize()
150150
severities.put(MessageId.MED_011, Severity.ERROR);
151151
severities.put(MessageId.MED_012, Severity.ERROR);
152152
severities.put(MessageId.MED_013, Severity.ERROR);
153+
severities.put(MessageId.MED_014, Severity.ERROR);
153154

154155
// NAV
155156
severities.put(MessageId.NAV_001, Severity.ERROR);

src/main/java/com/adobe/epubcheck/messages/MessageId.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ public enum MessageId implements Comparable<MessageId>
144144
MED_011("MED_011"),
145145
MED_012("MED_012"),
146146
MED_013("MED_013"),
147+
MED_014("MED_014"),
147148

148149
// Epub3 based table of content errors
149150
NAV_001("NAV-001"),

src/main/java/com/adobe/epubcheck/overlay/OverlayHandler.java

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -64,29 +64,28 @@ public void startElement()
6464
XMLElement e = parser.getCurrentElement();
6565
String name = e.getName();
6666

67-
if (name.equals("smil"))
68-
{
69-
vocabs = VocabUtil.parsePrefixDeclaration(
70-
e.getAttributeNS(EpubConstants.EpubTypeNamespaceUri, "prefix"), RESERVED_VOCABS,
71-
KNOWN_VOCAB_URIS, DEFAULT_VOCAB_URIS, report,
72-
EPUBLocation.create(path, parser.getLineNumber(), parser.getColumnNumber()));
73-
}
74-
else if (name.equals("seq"))
75-
{
76-
processSeq(e);
77-
}
78-
else if (name.equals("text"))
79-
{
80-
processSrc(e);
81-
}
82-
else if (name.equals("audio"))
83-
{
84-
processRef(e.getAttribute("src"), XRefChecker.Type.AUDIO);
85-
checkTime(e.getAttribute("clipBegin"), e.getAttribute("clipEnd"));
86-
}
87-
else if (name.equals("body") || name.equals("par"))
88-
{
89-
checkType(e.getAttributeNS(EpubConstants.EpubTypeNamespaceUri, "type"));
67+
switch (name) {
68+
case "smil":
69+
vocabs = VocabUtil.parsePrefixDeclaration(
70+
e.getAttributeNS(EpubConstants.EpubTypeNamespaceUri, "prefix"), RESERVED_VOCABS,
71+
KNOWN_VOCAB_URIS, DEFAULT_VOCAB_URIS, report,
72+
EPUBLocation.create(path, parser.getLineNumber(), parser.getColumnNumber()));
73+
break;
74+
75+
case "body":
76+
case "seq":
77+
case "par":
78+
processGlobalAttrs(e);
79+
break;
80+
81+
case "text":
82+
processSrc(e);
83+
break;
84+
85+
case "audio":
86+
processRef(e.getAttribute("src"), XRefChecker.Type.AUDIO);
87+
checkTime(e.getAttribute("clipBegin"), e.getAttribute("clipEnd"));
88+
break;
9089
}
9190
}
9291

@@ -163,6 +162,7 @@ private void processRef(String ref, XRefChecker.Type type)
163162
}
164163
}
165164
else {
165+
checkFragment(ref);
166166
String uniqueResource = PathUtil.removeFragment(ref);
167167
if (!Strings.isNullOrEmpty(uniqueResource)) {
168168
if (!context.overlayTextChecker.get().add(uniqueResource, context.opfItem.get().getId())) {
@@ -175,10 +175,12 @@ private void processRef(String ref, XRefChecker.Type type)
175175
}
176176
}
177177

178-
private void processSeq(XMLElement e)
178+
private void processGlobalAttrs(XMLElement e)
179179
{
180-
processRef(e.getAttributeNS(EpubConstants.EpubTypeNamespaceUri, "textref"),
181-
XRefChecker.Type.HYPERLINK);
180+
if (!e.getName().equals("audio")) {
181+
processRef(e.getAttributeNS(EpubConstants.EpubTypeNamespaceUri, "textref"),
182+
XRefChecker.Type.HYPERLINK);
183+
}
182184
checkType(e.getAttributeNS(EpubConstants.EpubTypeNamespaceUri, "type"));
183185
}
184186

@@ -212,4 +214,13 @@ private void checkItemReferences() {
212214

213215
}
214216

217+
private void checkFragment(String ref) {
218+
219+
String frag = PathUtil.getFragment(ref.trim());
220+
221+
if (ref.indexOf("#") == -1 || Strings.isNullOrEmpty(frag)) {
222+
// must include a non-empty fragid
223+
report.message(MessageId.MED_014, EPUBLocation.create(path, parser.getLineNumber(), parser.getColumnNumber()));
224+
}
225+
}
215226
}

src/main/resources/com/adobe/epubcheck/messages/MessageBundle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ MED_010=EPUB Content Documents referenced from a Media Overlay must specify the
137137
MED_011=EPUB Content Document referenced from multiple Media Overlay Documents.
138138
MED_012=The "media-overlay" attribute does not match the ID of the Media Overlay that refers to this document.
139139
MED_013=Media Overlay Document referenced from the "media-overlay" attribute does not contain a reference to this Content Document.
140+
MED_014=A non-empty fragment identifier is required.
140141

141142
#NAV EPUB v3 Table of contents
142143
NAV_001=The nav file is not supported for EPUB v2.

src/test/resources/epub3/files/epub/mediaoverlays-audio-non-cmt-error/EPUB/content_001.smil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<smil xmlns="http://www.w3.org/ns/SMIL" xmlns:epub="http://www.idpf.org/2007/ops" version="3.0">
33
<body>
44
<par id="par1">
5-
<text src="content_001.xhtml"/>
5+
<text src="content_001.xhtml#c01"/>
66
<audio src="content_001.m4a"/>
77
</par>
88
</body>

src/test/resources/epub3/files/epub/mediaoverlays-audio-non-cmt-error/EPUB/content_001.xhtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<title>Minimal EPUB</title>
66
</head>
77
<body>
8-
<h1>Loomings</h1>
8+
<h1 id="c01">Loomings</h1>
99
<p>Call me Ishmael.</p>
1010
</body>
1111
</html>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<smil xmlns="http://www.w3.org/ns/SMIL" xmlns:epub="http://www.idpf.org/2007/ops" version="3.0">
3+
<body epub:textref="content_001.xhtml#">
4+
<par id="par1">
5+
<text src="content_001.xhtml"/>
6+
<audio src="content_001.mp3"/>
7+
</par>
8+
</body>
9+
</smil>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<title>Minimal EPUB</title>
6+
</head>
7+
<body>
8+
<h1 id="c01">Loomings</h1>
9+
<p>Call me Ishmael.</p>
10+
</body>
11+
</html>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="en" lang="en">
3+
<head>
4+
<meta charset="utf-8"/>
5+
<title>Minimal Nav</title>
6+
</head>
7+
<body>
8+
<nav epub:type="toc">
9+
<ol>
10+
<li><a href="content_001.xhtml">content 001</a></li>
11+
</ol>
12+
</nav>
13+
</body>
14+
</html>

0 commit comments

Comments
 (0)