Skip to content

Commit 09244a4

Browse files
committed
feat: report as a usage when no reference were found to manifest items
This PR introduces a new usage message (`OPF-097`) reported when the manifest includes a resource for which no reference was found in content. This is legit for instance for exempt resources (like data files included in the container). But it is likely an author error otherwise, so reporting a usage message can help to detect that. We do not report an error since: - references can be added via scripting, so the check can only be informative for scripted content - EPUBCheck historically required all container resources to be listed in the manifest (not doing so was reported as a warning, `OPF-003`), which is conflicting with a requirement to **not** list unsused resources Close #1452
1 parent f81b423 commit 09244a4

File tree

13 files changed

+52
-16
lines changed

13 files changed

+52
-16
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
@@ -291,6 +291,7 @@ private void initialize()
291291
severities.put(MessageId.OPF_095, Severity.ERROR);
292292
severities.put(MessageId.OPF_096, Severity.ERROR);
293293
severities.put(MessageId.OPF_096b, Severity.USAGE);
294+
severities.put(MessageId.OPF_097, Severity.USAGE);
294295

295296
// PKG
296297
severities.put(MessageId.PKG_001, Severity.WARNING);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ public enum MessageId implements Comparable<MessageId>
285285
OPF_095("OPF-095"),
286286
OPF_096("OPF-096"),
287287
OPF_096b("OPF-096b"),
288+
OPF_097("OPF-097"),
288289

289290
// Messages relating to the entire package
290291
PKG_001("PKG-001"),

src/main/java/com/adobe/epubcheck/opf/OPFChecker30.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,17 @@ protected void checkItem(OPFItem item, OPFHandler opfHandler)
122122
{
123123
report.message(MessageId.OPF_091, item.getLocation());
124124
}
125+
126+
// Register media overlay usage
127+
if (context.referenceRegistry.isPresent() && !Strings.isNullOrEmpty(item.getMediaOverlay()))
128+
{
129+
Optional<OPFItem> overlay = opfHandler.getItemById(item.getMediaOverlay());
130+
if (overlay.isPresent())
131+
{
132+
context.referenceRegistry.get().registerReference(overlay.get().getURL(),
133+
Reference.Type.MEDIA_OVERLAY, item.getLocation());
134+
}
135+
}
125136
}
126137

127138
@Override
@@ -156,6 +167,18 @@ else if (!context.referenceRegistry.get().hasReferencesTo(item.geturl("")))
156167
}
157168
}
158169

170+
// check that resources in the manifest are referenced (usage report)
171+
// - search the reference registry
172+
// - report if no reference (of a publication-resource type) is found
173+
if (!(item.isInSpine() || item.isNav() || item.isNcx())
174+
&& context.referenceRegistry.isPresent()
175+
&& context.referenceRegistry.get().asList().stream()
176+
.noneMatch(ref -> ref.targetResource.equals(item.getURL())
177+
&& ref.type.isPublicationResourceReference()))
178+
{
179+
report.message(MessageId.OPF_097, item.getLocation(), item.getPath());
180+
}
181+
159182
if (isBlessedItemType(mediatype, version))
160183
{
161184
// check whether media-overlay attribute needs to be specified

src/main/java/org/w3c/epubcheck/core/references/Reference.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public static enum Type
1515
// Publication resources
1616
GENERIC,
1717
STYLESHEET,
18+
MEDIA_OVERLAY,
1819
HYPERLINK,
1920
FONT,
2021
IMAGE,
@@ -30,7 +31,25 @@ public static enum Type
3031
SEARCH_KEY,
3132
NAV_TOC_LINK,
3233
NAV_PAGELIST_LINK,
33-
OVERLAY_TEXT_LINK,
34+
OVERLAY_TEXT_LINK;
35+
36+
public boolean isPublicationResourceReference()
37+
{
38+
switch (this)
39+
{
40+
case GENERIC:
41+
case STYLESHEET:
42+
case FONT:
43+
case IMAGE:
44+
case AUDIO:
45+
case VIDEO:
46+
case TRACK:
47+
case MEDIA_OVERLAY:
48+
return true;
49+
default:
50+
return false;
51+
}
52+
}
3453
}
3554

3655
public final URL url;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,8 @@ OPF_093=The "media-type" attribute is required for linked resources located in t
212212
OPF_094=The "media-type" attribute is required for "%1$s" links.
213213
OPF_095=The "media-type" attribute of "voicing" links must be an audio MIME type, but found "%1$s".
214214
OPF_096=Non-linear content must be reachable, but found no hyperlink to "%1$s".
215-
OPF_096b=No hyperlink was found to non-linear document "%1$s", please check that it can be reached from scripted content.
215+
OPF_096b=No hyperlink was found to non-linear document "%1$s", please check that it can be reached from scripted content.
216+
OPF_097=Resource "%1$s" is listed in the manifest, but no reference to it was found in content documents.
216217

217218
#Package
218219
PKG_001=Validating the EPUB against version %1$s but detected version %2$s.

src/test/resources/com/adobe/epubcheck/tools/20-severity-tester/OPS/toc.ncx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<navLabel>
1313
<text>Loomings</text>
1414
</navLabel>
15-
<content src="content_001.xhtml"/>
15+
<content src="content%20001.xhtml"/>
1616
</navPoint>
1717
</navMap>
1818
</ncx>

src/test/resources/com/adobe/epubcheck/tools/20-warning-tester/OPS/content_002.xhtml

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/test/resources/com/adobe/epubcheck/tools/20-warning-tester/OPS/package.opf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<dc:identifier id="q">NOID</dc:identifier>
77
</metadata>
88
<manifest>
9-
<item id="content_001" href="content_001.xhtml" media-type="application/xhtml+xml"/>
9+
<item id="content_001" href="content%20001.xhtml" media-type="application/xhtml+xml"/>
1010
<item id="ncx" href="toc.ncx" media-type="application/x-dtbncx+xml" />
1111
</manifest>
1212
<spine toc="ncx">

0 commit comments

Comments
 (0)