Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: new requirements of package link 'media-type' attribute #1423

Merged
merged 1 commit into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,9 @@ private void initialize()
severities.put(MessageId.OPF_090, Severity.USAGE);
severities.put(MessageId.OPF_091, Severity.ERROR);
severities.put(MessageId.OPF_092, Severity.ERROR);
severities.put(MessageId.OPF_093, Severity.ERROR);
severities.put(MessageId.OPF_094, Severity.ERROR);
severities.put(MessageId.OPF_095, Severity.ERROR);

// PKG
severities.put(MessageId.PKG_001, Severity.WARNING);
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/adobe/epubcheck/messages/MessageId.java
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ public enum MessageId implements Comparable<MessageId>
OPF_090("OPF-090"),
OPF_091("OPF-091"),
OPF_092("OPF-092"),
OPF_093("OPF-093"),
OPF_094("OPF-094"),
OPF_095("OPF-095"),

// Messages relating to the entire package
PKG_001("PKG-001"),
Expand Down
57 changes: 48 additions & 9 deletions src/main/java/com/adobe/epubcheck/opf/OPFHandler30.java
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ else if (EpubConstants.DCElements.equals(e.getNamespace()))
* Document. Must be called after the parsing.
*
* @return the metadata for the Rendition represented by the current Package
* Document
* Document
*/
public MetadataSet getMetadata()
{
Expand All @@ -350,7 +350,7 @@ public MetadataSet getMetadata()
* called after the parsing.
*
* @return the linked resources for the Rendition represented by the current
* Package Document
* Package Document
*/
public LinkedResources getLinkedResources()
{
Expand All @@ -363,7 +363,7 @@ public LinkedResources getLinkedResources()
* the parsing.
*
* @return the linked resources for the Rendition represented by the current
* Package Document
* Package Document
*/
public ResourceCollections getCollections()
{
Expand Down Expand Up @@ -446,28 +446,67 @@ private void processLink()

String href = e.getAttribute("href");
if (href != null)
{ // check by schema
{ // href presence is checked by schema

// check the 'href' URL
URL url = checkURL(href);
if (context.isRemote(url)) {
if (context.isRemote(url))
{
report.info(path, FeatureEnum.REFERENCE, href);
}

if (context.xrefChecker.isPresent())
{
context.xrefChecker.get().registerReference(url, Type.LINK, location());
}

// check the 'rel' attribute
String rel = e.getAttribute("rel");
Set<Property> relSet = processLinkRel(rel);
Set<LINKREL_PROPERTIES> relEnum = Property.filter(relSet, LINKREL_PROPERTIES.class);

// check the 'media-type' attribute
String mediatype = e.getAttribute("media-type");
if (mediatype == null)
{
// media-type is required for in-container URLs
// NOTE: as legacy EPUB 3.2 collections made heavy use
// of local links with no media type, we only check this
// for metadata links, which may be a violation of EPUB.
if (!context.isRemote(url) && !metadataBuilders.isEmpty())
{
if (linkedResourcesBuilders.size() == 1)
report.message(MessageId.OPF_093, location());
}
// media-type is required by some keywords
else if (relEnum.stream().anyMatch(
keyword -> keyword == LINKREL_PROPERTIES.RECORD
|| keyword == LINKREL_PROPERTIES.VOICING))
{
report.message(MessageId.OPF_094, location(), rel);
}
}
else
{
// 'voicing' links require an audio media type
if (relEnum.contains(LINKREL_PROPERTIES.VOICING) && !OPFChecker30.isAudioType(mediatype))
{
report.message(MessageId.OPF_095, location(), mediatype);
}
}

// check the 'properties' attribute
processLinkProperties(e.getAttribute("properties"));

// build the data model
if (!linkedResourcesBuilders.isEmpty())
{
processLinkProperties(e.getAttribute("properties"));
LinkedResource resource = new LinkedResource.Builder(url).id(e.getAttribute("id"))
.rel(processLinkRel(e.getAttribute("rel"))).mimetype(e.getAttribute("media-type"))
.refines(e.getAttribute("refines")).build();
.rel(relSet).mimetype(mediatype).refines(e.getAttribute("refines")).build();
linkedResourcesBuilders.peekFirst().add(resource);
}
}

// check hreflang attribute
String hreflang = e.getAttribute("hreflang");
if (hreflang != null && !hreflang.isEmpty())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,9 @@ OPF_089=The "alternate" link rel keyword cannot be paired with other keywords.
OPF_090=It is encouraged to use MIME media type "%1$s" instead of "%2$s".
OPF_091=The item href URL must not have a fragment identifier.
OPF_092=Language tag "%1$s" is not well-formed: %2$s
OPF_093=The "media-type" attribute is required for linked resources located in the EPUB container
OPF_094=The "media-type" attribute is required for "%1$s" links.
OPF_095=The "media-type" attribute of "voicing" links must be an audio MIME type, but found "%1$s".

#Package
PKG_001=Validating the EPUB against version %1$s but detected version %2$s.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,15 @@

<pattern id="opf.link.record">
<rule context="opf:link[tokenize(@rel,'\s+')='record']">
<assert test="exists(@media-type)">The type of "record" references must be identifiable
from the link element’s "media-type" attribute.</assert>
<!--<assert test="exists(@media-type)">**checked in java**</assert>-->
<assert test="empty(@refines)">"record" links only applies to the Publication (must not
have a "refines" attribute).</assert>
</rule>
</pattern>

<pattern id="opf.link.voicing">
<rule context="opf:link[tokenize(@rel,'\s+')='voicing']">
<assert test="starts-with(normalize-space(@media-type),'audio/')">"voicing" links must have a "media-type" attribute identifying an audio MIME type.</assert>
<!--<assert test="starts-with(normalize-space(@media-type),'audio/')">**checked in java**</assert>-->
<assert test="exists(@refines)">"voicing" links must have a "refines" attribute.</assert>
</rule>
</pattern>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<dc:language>en</dc:language>
<dc:identifier id="q">NOID</dc:identifier>
<meta property="dcterms:modified">2017-06-14T00:00:01Z</meta>
<link href="file:example" rel="acquire"/>
<link href="file:example" rel="acquire" media-type="text/html"/>
</metadata>
<manifest>
<item id="content_001" href="content_001.xhtml" media-type="application/xhtml+xml"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<dc:identifier id="uid">NOID</dc:identifier>
<meta property="dcterms:modified">2019-01-01T12:00:00Z</meta>
<!--Linked resources MUST NOT be listed in the manifest.-->
<link rel="example:property" href="contents.xhtml#ch1"/>
<link rel="example:property" href="contents.xhtml#ch1" media-type="application/xhtml+xml"/>
</metadata>
<manifest>
<item id="t001" href="contents.xhtml" properties="nav" media-type="application/xhtml+xml"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<package xmlns="http://www.idpf.org/2007/opf" version="3.0" xml:lang="en" unique-identifier="q"
prefix="test: http://example.org">
<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>
<link rel="test:link" href="book.xml"/>
</metadata>
<manifest>
<item id="content_001" href="content_001.xhtml" media-type="application/xhtml+xml"/>
<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,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>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,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<package xmlns="http://www.idpf.org/2007/opf" version="3.0" xml:lang="en" unique-identifier="q"
prefix="test: http://example.org">
<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>
<link rel="test:link" href="https://example.org/"/>
</metadata>
<manifest>
<item id="content_001" href="content_001.xhtml" media-type="application/xhtml+xml"/>
<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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -334,12 +334,15 @@ Feature: EPUB 3 — Package document
And no other errors or warnings are reported

@spec @xref:sec-link-elem
Scenario: A link to a local resource must declare a media type
When checking file 'package-link-missing-media-type-error'
# Then error RSC-005 is reported
# And the message contains 'missing required attribute "media-type"'
# And no other errors or warnings are reported
Then no other errors or warnings are reported
Scenario: Report a missing 'media-type' attribute on links to container resources
When checking file 'package-link-media-type-missing-local-error'
Then error OPF-093 is reported
And no other errors or warnings are reported

@spec @xref:sec-link-elem
Scenario: Allow a missing 'media-type' attribute on links to remote resources
When checking file 'package-link-media-type-missing-remote-valid'
Then no errors or warnings are reported

@spec @xref:sec-link-elem
Scenario: the link 'rel' attribute can have multiple properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<dc:language>en</dc:language>
<dc:identifier id="uid">NOID</dc:identifier>
<meta property="dcterms:modified">2019-01-01T12:00:00Z</meta>
<link rel="record" href="record.atom"/>
<link rel="record" href="https://example.org/record.atom"/>
</metadata>
<manifest>
<item id="t001" href="contents.xhtml" properties="nav" media-type="application/xhtml+xml"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<dc:language>en</dc:language>
<dc:identifier id="uid">NOID</dc:identifier>
<meta property="dcterms:modified">2019-01-01T12:00:00Z</meta>
<link rel="voicing" refines="#title" href="title.mp3"/>
<link rel="voicing" refines="#title" href="http://example.org/title.mp3"/>
</metadata>
<manifest>
<item id="t001" href="contents.xhtml" properties="nav" media-type="application/xhtml+xml"/>
Expand Down
19 changes: 10 additions & 9 deletions src/test/resources/epub3/D-vocabularies/metadata-link.feature
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Feature: EPUB 3 — Vocabularies — Metadata link vocabulary
When checking file 'link-rel-alternate-with-other-keyword-error.opf'
Then error OPF-089 is reported
And no other errors or warnings are reported


#### D.4.1.3, D.4.1.4, D.4.1.5, D.4.1.9 *-record

Expand All @@ -44,6 +44,8 @@ Feature: EPUB 3 — Vocabularies — Metadata link vocabulary
| OPF-086 | "mods-record" is deprecated |
| OPF-086 | "onix-record" is deprecated |
| OPF-086 | "xmp-record" is deprecated |
And error OPF-093 is reported 4 times
# note: 'media-type' is now required, even on deprecated properties
And no other errors or warnings are reported


Expand All @@ -62,10 +64,9 @@ Feature: EPUB 3 — Vocabularies — Metadata link vocabulary
Then no errors or warnings are reported

@spec @xref:sec-record
Scenario: a 'record' link must have a 'media-type' attribute
Scenario: a 'record' link must have a 'media-type' attribute even when remote
When checking file 'link-rel-record-mediatype-missing-error.opf'
Then error RSC-005 is reported
And the message contains "media-type"
Then error OPF-094 is reported
And no other errors or warnings are reported

Scenario: a 'record' link type can be further identified with a 'properties' attribute
Expand Down Expand Up @@ -95,17 +96,15 @@ Feature: EPUB 3 — Vocabularies — Metadata link vocabulary
And no other errors or warnings are reported

@spec @xref:sec-voicing
Scenario: a 'voicing' link must have a 'media-type' attribute
Scenario: a 'voicing' link must have a 'media-type' attribute even when remote
When checking file 'link-rel-voicing-mediatype-missing-error.opf'
Then error RSC-005 is reported
And the message contains 'must have a "media-type" attribute'
Then error OPF-094 is reported
And no other errors or warnings are reported

@spec @xref:sec-voicing
Scenario: a 'voicing' link resource must have an audio media type
When checking file 'link-rel-voicing-mediatype-not-audio-error.opf'
Then error RSC-005 is reported
And the message contains 'must have a "media-type" attribute identifying an audio MIME type'
Then error OPF-095 is reported
And no other errors or warnings are reported


Expand All @@ -115,4 +114,6 @@ Feature: EPUB 3 — Vocabularies — Metadata link vocabulary
When checking file 'link-rel-xml-signature-deprecated-warning.opf'
Then warning OPF-086 is reported
And the message contains '"xml-signature" is deprecated'
And error OPF-093 is reported
# note: 'media-type' is now required, even on deprecated properties
And no other errors or warnings are reported