Skip to content

Commit df16ede

Browse files
mattgarrishrdeltour
authored andcommitted
feat: check remote resource usage in Media Overlays
- Report OPF-014 when a remote audio file is used in Media Overlays and the `remote-resources` prroperty is not declared in the Package Document. Implementation notes: - flag references to remote resources when parsing `audio` elements - check that the `remote-resources` property is correctly set in the package item declaration when at the end of the SMIL parsing
1 parent eea1574 commit df16ede

File tree

8 files changed

+105
-5
lines changed

8 files changed

+105
-5
lines changed

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

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.adobe.epubcheck.overlay;
22

3+
import java.util.EnumSet;
34
import java.util.HashSet;
45
import java.util.Map;
56
import java.util.Set;
@@ -13,8 +14,10 @@
1314
import com.adobe.epubcheck.util.EpubConstants;
1415
import com.adobe.epubcheck.util.HandlerUtil;
1516
import com.adobe.epubcheck.util.PathUtil;
16-
import com.adobe.epubcheck.vocab.Property;
1717
import com.adobe.epubcheck.vocab.AggregateVocab;
18+
import com.adobe.epubcheck.vocab.PackageVocabs;
19+
import com.adobe.epubcheck.vocab.PackageVocabs.ITEM_PROPERTIES;
20+
import com.adobe.epubcheck.vocab.Property;
1821
import com.adobe.epubcheck.vocab.StructureVocab;
1922
import com.adobe.epubcheck.vocab.Vocab;
2023
import com.adobe.epubcheck.vocab.VocabUtil;
@@ -24,6 +27,7 @@
2427
import com.google.common.base.Strings;
2528
import com.google.common.collect.ImmutableMap;
2629
import com.google.common.collect.ImmutableSet;
30+
import com.google.common.collect.Sets;
2731

2832
public class OverlayHandler implements XMLHandler
2933
{
@@ -44,6 +48,8 @@ public class OverlayHandler implements XMLHandler
4448

4549
private Set<String> resourceRefs = new HashSet<String>();
4650

51+
private final Set<ITEM_PROPERTIES> requiredProperties = EnumSet.noneOf(ITEM_PROPERTIES.class);
52+
4753
public OverlayHandler(ValidationContext context, XMLParser parser)
4854
{
4955
this.context = context;
@@ -79,11 +85,11 @@ public void startElement()
7985
break;
8086

8187
case "text":
82-
processSrc(e);
88+
processTextSrc(e);
8389
break;
8490

8591
case "audio":
86-
processRef(e.getAttribute("src"), XRefChecker.Type.AUDIO);
92+
processAudioSrc(e);
8793
checkTime(e.getAttribute("clipBegin"), e.getAttribute("clipEnd"));
8894
break;
8995
}
@@ -142,10 +148,21 @@ private void checkType(String type)
142148
}
143149
}
144150

145-
private void processSrc(XMLElement e)
151+
private void processTextSrc(XMLElement e)
146152
{
147153
processRef(e.getAttribute("src"), XRefChecker.Type.HYPERLINK);
148-
154+
}
155+
156+
private void processAudioSrc(XMLElement e) {
157+
158+
String src = e.getAttribute("src");
159+
160+
processRef(src, XRefChecker.Type.AUDIO);
161+
162+
if (src != null && PathUtil.isRemote(src))
163+
{
164+
requiredProperties.add(ITEM_PROPERTIES.REMOTE_RESOURCES);
165+
}
149166
}
150167

151168
private void processRef(String ref, XRefChecker.Type type)
@@ -195,6 +212,7 @@ public void endElement()
195212
if (name.equals("smil"))
196213
{
197214
checkItemReferences();
215+
checkProperties();
198216
}
199217
}
200218

@@ -223,4 +241,20 @@ private void checkFragment(String ref) {
223241
report.message(MessageId.MED_014, EPUBLocation.create(path, parser.getLineNumber(), parser.getColumnNumber()));
224242
}
225243
}
244+
245+
protected void checkProperties()
246+
{
247+
if (!context.ocf.isPresent()) // single file validation
248+
{
249+
return;
250+
}
251+
252+
Set<ITEM_PROPERTIES> itemProps = Property.filter(context.properties, ITEM_PROPERTIES.class);
253+
254+
for (ITEM_PROPERTIES requiredProperty : Sets.difference(requiredProperties, itemProps))
255+
{
256+
report.message(MessageId.OPF_014, EPUBLocation.create(path),
257+
PackageVocabs.ITEM_VOCAB.getName(requiredProperty));
258+
}
259+
}
226260
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<smil xmlns="http://www.w3.org/ns/SMIL" xmlns:epub="http://www.idpf.org/2007/ops" version="3.0">
2+
<body>
3+
<par id="heading1">
4+
<text src="content_001.xhtml#hd01"/>
5+
<audio src="http://example.com/audio/c001.mp4" clipBegin="0:00:24.500"/>
6+
</par>
7+
</body>
8+
</smil>
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="hd01">Loomings</h1>
9+
<p>boring boring boring</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>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<package xmlns="http://www.idpf.org/2007/opf" version="3.0" xml:lang="en" unique-identifier="q">
3+
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/">
4+
<dc:title id="title">Minimal EPUB 3.0</dc:title>
5+
<dc:language>en</dc:language>
6+
<dc:identifier id="q">NOID</dc:identifier>
7+
<meta property="dcterms:modified">2017-06-14T00:00:01Z</meta>
8+
<!--MEDIA OVERLAY METADATA-->
9+
<meta property="media:duration" refines="#chapter_001_overlay">0:14:20.500</meta>
10+
<meta property="media:duration">0:14:20.500</meta>
11+
</metadata>
12+
<manifest>
13+
<item id="content_001" href="content_001.xhtml" media-type="application/xhtml+xml" media-overlay="chapter_001_overlay"/>
14+
<item id="chapter_001_overlay" href="chapter_001_overlay.smil" media-type="application/smil+xml"/>
15+
<item id="chapter_001_audio" href="http://example.com/audio/c001.mp4" media-type="audio/mp4"/>
16+
<item id="nav" href="nav.xhtml" media-type="application/xhtml+xml" properties="nav"/>
17+
</manifest>
18+
<spine>
19+
<itemref idref="content_001" />
20+
</spine>
21+
</package>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<container xmlns="urn:oasis:names:tc:opendocument:xmlns:container" version="1.0">
3+
<rootfiles>
4+
<rootfile full-path="EPUB/package.opf" media-type="application/oebps-package+xml"/>
5+
</rootfiles>
6+
</container>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
application/epub+zip

src/test/resources/epub3/package-publication.feature

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,11 @@ Feature: EPUB 3 ▸ Packages ▸ Full Publication Checks
174174
Then warning OPF-018 is reported
175175
And no other errors or warnings are reported
176176
177+
Scenario: Report a media overlay document with remote resources but missing the `remote-resources` property
178+
When checking EPUB 'package-manifest-prop-remote-resource-overlays-error'
179+
Then error OPF-014 is reported
180+
And no other errors or warnings are reported
181+
177182
178183
### E.2.5 scripted
179184

0 commit comments

Comments
 (0)