Skip to content

Commit

Permalink
feat: check remote resource usage in Media Overlays
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
mattgarrish authored and rdeltour committed Dec 28, 2020
1 parent eea1574 commit df16ede
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 5 deletions.
44 changes: 39 additions & 5 deletions src/main/java/com/adobe/epubcheck/overlay/OverlayHandler.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.adobe.epubcheck.overlay;

import java.util.EnumSet;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
Expand All @@ -13,8 +14,10 @@
import com.adobe.epubcheck.util.EpubConstants;
import com.adobe.epubcheck.util.HandlerUtil;
import com.adobe.epubcheck.util.PathUtil;
import com.adobe.epubcheck.vocab.Property;
import com.adobe.epubcheck.vocab.AggregateVocab;
import com.adobe.epubcheck.vocab.PackageVocabs;
import com.adobe.epubcheck.vocab.PackageVocabs.ITEM_PROPERTIES;
import com.adobe.epubcheck.vocab.Property;
import com.adobe.epubcheck.vocab.StructureVocab;
import com.adobe.epubcheck.vocab.Vocab;
import com.adobe.epubcheck.vocab.VocabUtil;
Expand All @@ -24,6 +27,7 @@
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;

public class OverlayHandler implements XMLHandler
{
Expand All @@ -44,6 +48,8 @@ public class OverlayHandler implements XMLHandler

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

private final Set<ITEM_PROPERTIES> requiredProperties = EnumSet.noneOf(ITEM_PROPERTIES.class);

public OverlayHandler(ValidationContext context, XMLParser parser)
{
this.context = context;
Expand Down Expand Up @@ -79,11 +85,11 @@ public void startElement()
break;

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

case "audio":
processRef(e.getAttribute("src"), XRefChecker.Type.AUDIO);
processAudioSrc(e);
checkTime(e.getAttribute("clipBegin"), e.getAttribute("clipEnd"));
break;
}
Expand Down Expand Up @@ -142,10 +148,21 @@ private void checkType(String type)
}
}

private void processSrc(XMLElement e)
private void processTextSrc(XMLElement e)
{
processRef(e.getAttribute("src"), XRefChecker.Type.HYPERLINK);

}

private void processAudioSrc(XMLElement e) {

String src = e.getAttribute("src");

processRef(src, XRefChecker.Type.AUDIO);

if (src != null && PathUtil.isRemote(src))
{
requiredProperties.add(ITEM_PROPERTIES.REMOTE_RESOURCES);
}
}

private void processRef(String ref, XRefChecker.Type type)
Expand Down Expand Up @@ -195,6 +212,7 @@ public void endElement()
if (name.equals("smil"))
{
checkItemReferences();
checkProperties();
}
}

Expand Down Expand Up @@ -223,4 +241,20 @@ private void checkFragment(String ref) {
report.message(MessageId.MED_014, EPUBLocation.create(path, parser.getLineNumber(), parser.getColumnNumber()));
}
}

protected void checkProperties()
{
if (!context.ocf.isPresent()) // single file validation
{
return;
}

Set<ITEM_PROPERTIES> itemProps = Property.filter(context.properties, ITEM_PROPERTIES.class);

for (ITEM_PROPERTIES requiredProperty : Sets.difference(requiredProperties, itemProps))
{
report.message(MessageId.OPF_014, EPUBLocation.create(path),
PackageVocabs.ITEM_VOCAB.getName(requiredProperty));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<smil xmlns="http://www.w3.org/ns/SMIL" xmlns:epub="http://www.idpf.org/2007/ops" version="3.0">
<body>
<par id="heading1">
<text src="content_001.xhtml#hd01"/>
<audio src="http://example.com/audio/c001.mp4" clipBegin="0:00:24.500"/>
</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="hd01">Loomings</h1>
<p>boring boring boring</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,21 @@
<?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>
<!--MEDIA OVERLAY METADATA-->
<meta property="media:duration" refines="#chapter_001_overlay">0:14:20.500</meta>
<meta property="media:duration">0:14:20.500</meta>
</metadata>
<manifest>
<item id="content_001" href="content_001.xhtml" media-type="application/xhtml+xml" media-overlay="chapter_001_overlay"/>
<item id="chapter_001_overlay" href="chapter_001_overlay.smil" media-type="application/smil+xml"/>
<item id="chapter_001_audio" href="http://example.com/audio/c001.mp4" media-type="audio/mp4"/>
<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 xmlns="urn:oasis:names:tc:opendocument:xmlns:container" version="1.0">
<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
5 changes: 5 additions & 0 deletions src/test/resources/epub3/package-publication.feature
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ Feature: EPUB 3 ▸ Packages ▸ Full Publication Checks
Then warning OPF-018 is reported
And no other errors or warnings are reported
Scenario: Report a media overlay document with remote resources but missing the `remote-resources` property
When checking EPUB 'package-manifest-prop-remote-resource-overlays-error'
Then error OPF-014 is reported
And no other errors or warnings are reported
### E.2.5 scripted
Expand Down

0 comments on commit df16ede

Please sign in to comment.