Skip to content

Commit 3086258

Browse files
committed
feat: update checking of the package rendering vocabulary
- deprecated properties are now reported as `OPF-086`, like for other deprecated properties, instead of `RSC-017`. This means the check relies on the `Property#isDeprecated` facility, instead of custom Schematron code. - deprecated property value is checked in custom Java code the `OPFHandler30#processMeta()` method. - verify that custom properties cannot be defined using the reserved "rendition" prefix. A new feature file is added for this single test, to match the spec section ordering. Fix #1327
1 parent 3199b81 commit 3086258

File tree

6 files changed

+135
-47
lines changed

6 files changed

+135
-47
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858

5959
import com.adobe.epubcheck.api.EPUBLocation;
6060
import com.adobe.epubcheck.api.QuietReport;
61+
import com.adobe.epubcheck.messages.LocalizedMessages;
6162
import com.adobe.epubcheck.messages.MessageId;
6263
import com.adobe.epubcheck.opf.ResourceCollection.Roles;
6364
import com.adobe.epubcheck.opf.XRefChecker.Type;
@@ -592,8 +593,9 @@ private void processMeta()
592593

593594
if (prop.isPresent() && !metadataBuilders.isEmpty())
594595
{
596+
String value = Strings.nullToEmpty((String) e.getPrivateData()).trim();
595597
metadataBuilders.peekFirst().meta(e.getAttribute("id"), prop.get(),
596-
(String) e.getPrivateData(), e.getAttribute("refines"));
598+
value, e.getAttribute("refines"));
597599

598600
// Primary metadata checks
599601
if (metadataBuilders.size() == 1)
@@ -608,6 +610,14 @@ private void processMeta()
608610
context.featureReport.report(FeatureEnum.MEDIA_OVERLAYS_PLAYBACK_ACTIVE_CLASS, location(),
609611
e.getPrivateData().toString());
610612
break;
613+
case "rendition:spread":
614+
if (value.equals("portrait"))
615+
{
616+
report.message(MessageId.OPF_086, location(), "rendition:spread portrait",
617+
LocalizedMessages.getInstance(context.locale)
618+
.getSuggestion(MessageId.OPF_086, null));
619+
}
620+
break;
611621
default:
612622
break;
613623
}

src/main/java/com/adobe/epubcheck/vocab/RenditionVocabs.java

Lines changed: 65 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,96 @@
11
package com.adobe.epubcheck.vocab;
22

3+
import com.adobe.epubcheck.opf.ValidationContext;
4+
import com.google.common.base.Preconditions;
5+
36
public final class RenditionVocabs
47
{
58
public static final String PREFIX = "rendition";
69
public static final String URI = "http://www.idpf.org/vocab/rendition/#";
710

811
public static final EnumVocab<META_PROPERTIES> META_VOCAB = new EnumVocab<META_PROPERTIES>(
9-
META_PROPERTIES.class, URI);
12+
META_PROPERTIES.class, URI, PREFIX);
1013

11-
public enum META_PROPERTIES
14+
public enum META_PROPERTIES implements PropertyStatus
1215
{
13-
FLOW,
1416
LAYOUT,
1517
ORIENTATION,
1618
SPREAD,
17-
VIEWPORT
19+
VIEWPORT(DEPRECATED),
20+
FLOW;
21+
22+
private final PropertyStatus status;
23+
24+
private META_PROPERTIES()
25+
{
26+
this(ALLOWED);
27+
}
28+
29+
private META_PROPERTIES(PropertyStatus status)
30+
{
31+
this.status = Preconditions.checkNotNull(status);
32+
}
33+
34+
@Override
35+
public boolean isAllowed(ValidationContext context)
36+
{
37+
return status.isAllowed(context);
38+
}
39+
40+
@Override
41+
public boolean isDeprecated()
42+
{
43+
return status.isDeprecated();
44+
}
1845
}
1946

2047
public static final EnumVocab<ITEMREF_PROPERTIES> ITEMREF_VOCAB = new EnumVocab<ITEMREF_PROPERTIES>(
2148
ITEMREF_PROPERTIES.class, URI);
2249

23-
public enum ITEMREF_PROPERTIES
50+
public enum ITEMREF_PROPERTIES implements PropertyStatus
2451
{
25-
ALIGN_X_CENTER,
26-
FLOW_AUTO,
27-
FLOW_PAGINATED,
28-
FLOW_SCROLLED_CONTINUOUS,
29-
FLOW_SCROLLED_DOC,
3052
LAYOUT_PRE_PAGINATED,
3153
LAYOUT_REFLOWABLE,
3254
ORIENTATION_AUTO,
3355
ORIENTATION_LANDSCAPE,
3456
ORIENTATION_PORTRAIT,
35-
PAGE_SPREAD_CENTER,
3657
SPREAD_AUTO,
3758
SPREAD_BOTH,
3859
SPREAD_LANDSCAPE,
3960
SPREAD_NONE,
40-
SPREAD_PORTRAIT
61+
SPREAD_PORTRAIT(DEPRECATED),
62+
PAGE_SPREAD_CENTER,
63+
PAGE_SPREAD_LEFT,
64+
PAGE_SPREAD_RIGHT,
65+
FLOW_PAGINATED,
66+
FLOW_SCROLLED_CONTINUOUS,
67+
FLOW_SCROLLED_DOC,
68+
FLOW_AUTO,
69+
ALIGN_X_CENTER;
70+
71+
private final PropertyStatus status;
72+
73+
private ITEMREF_PROPERTIES()
74+
{
75+
this(ALLOWED);
76+
}
77+
78+
private ITEMREF_PROPERTIES(PropertyStatus status)
79+
{
80+
this.status = Preconditions.checkNotNull(status);
81+
}
82+
83+
@Override
84+
public boolean isAllowed(ValidationContext context)
85+
{
86+
return status.isAllowed(context);
87+
}
88+
89+
@Override
90+
public boolean isDeprecated()
91+
{
92+
return status.isDeprecated();
93+
}
4194
}
4295

4396
private RenditionVocabs()

src/main/resources/com/adobe/epubcheck/schema/30/package-30.sch

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -455,24 +455,8 @@
455455
</rule>
456456
</pattern>
457457

458-
<pattern id="opf.meta.viewport.deprecated">
459-
<rule context="opf:metadata/opf:meta[normalize-space(@property)='rendition:viewport']">
460-
<report test=".">WARNING: Use of the rendition:viewport property is deprecated</report>
461-
</rule>
462-
</pattern>
463-
464-
<pattern id="opf.meta.spread.portrait.deprecated">
465-
<rule context="opf:metadata/opf:meta[normalize-space(@property)='rendition:spread']">
466-
<report test=". = 'portrait'">WARNING: Use of the rendition:spread value "portrait" is deprecated in favour of the value "both"</report>
467-
</rule>
468-
</pattern>
469-
470-
<pattern id="opf.itemref.spread.portrait.deprecated">
471-
<rule context="opf:spine/opf:itemref[@properties]">
472-
<report test="tokenize(@properties,'\s+')='rendition:spread-portrait'">WARNING: Use of the "rendition:spread-portrait" spine override is deprecated in favour of "rendition:spread-both"</report>
473-
</rule>
474-
</pattern>
475-
458+
459+
<!--FIXME deprecation should be in vocab-->
476460
<pattern id="opf.meta.meta-auth.deprecated">
477461
<rule context="opf:metadata/opf:meta[normalize-space(@property)='meta-auth']">
478462
<report test=".">WARNING: Use of the meta-auth property is deprecated</report>

src/test/resources/epub3/08-layout/layout.feature

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,12 @@ Feature: EPUB 3 — Layout Rendering Control
140140
And the message contains "refines"
141141
And no other errors or warnings are reported
142142

143+
@spec @xref:spread
144+
Scenario: the 'rendition:spread' 'portrait' value is deprecated as a global value
145+
When checking file 'rendition-spread-portrait-global-deprecated-warning.opf'
146+
Then warning OPF-086 is reported
147+
And no other errors or warnings are reported
148+
143149
#### 8.2.2.3.1 Synthetic spread overrides
144150

145151
@spec @xref:spread-overrides
@@ -154,18 +160,6 @@ Feature: EPUB 3 — Layout Rendering Control
154160
And the message contains "are mutually exclusive"
155161
And no other errors or warnings are reported
156162

157-
Scenario: the 'rendition:spread' 'portrait' value is deprecated as a global value
158-
When checking file 'rendition-spread-portrait-global-deprecated-warning.opf'
159-
Then warning RSC-017 is reported
160-
And the message contains "is deprecated"
161-
And no other errors or warnings are reported
162-
163-
Scenario: the 'rendition:spread' 'spread-portrait' value is deprecated as a spine override
164-
When checking file 'rendition-spread-portrait-itemref-deprecated-warning.opf'
165-
Then warning RSC-017 is reported
166-
And the message contains "is deprecated"
167-
And no other errors or warnings are reported
168-
169163

170164
#### 8.2.2.4 Spread placement
171165

@@ -181,25 +175,31 @@ Feature: EPUB 3 — Layout Rendering Control
181175
And the message contains "are mutually exclusive"
182176
And no other errors or warnings are reported
183177

178+
@spec @xref:spread
179+
Scenario: the 'rendition:spread-portrait' value is deprecated as a spine override
180+
When checking file 'rendition-spread-portrait-itemref-deprecated-warning.opf'
181+
Then warning OPF-086 is reported
182+
And no other errors or warnings are reported
183+
184184

185185
#### 8.2.2.5 Viewport dimensions (deprecated)
186186

187+
@spec @xref:viewport
187188
Scenario: the 'rendition:viewport' property is deprecated
188189
When checking file 'rendition-viewport-deprecated-warning.opf'
189-
Then warning RSC-017 is reported
190-
And the message contains "is deprecated"
190+
Then warning OPF-086 is reported
191191
And no other errors or warnings are reported
192192

193193
Scenario: the 'rendition:viewport' property syntax errors are reported
194194
When checking file 'rendition-viewport-syntax-error.opf'
195-
Then warning RSC-017 is reported (since 'viewport' is deprecated)
195+
Then warning OPF-086 is reported (since 'viewport' is deprecated)
196196
And error RSC-005 is reported
197197
And the message contains 'The value of the "rendition:viewport" property must be of the form'
198198
And no other errors or warnings are reported
199199

200200
Scenario: the 'rendition:viewport' property cannot be declared more than once
201201
When checking file 'rendition-viewport-duplicate-error.opf'
202-
Then warning RSC-017 is reported 2 times (since 'viewport' is deprecated)
202+
Then warning OPF-086 is reported 2 times (since 'viewport' is deprecated)
203203
And error RSC-005 is reported
204204
And the message contains 'The "rendition:viewport" property must not occur more than one time as a global value'
205205
And no other errors or warnings are reported
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<package xmlns="http://www.idpf.org/2007/opf" version="3.0" unique-identifier="uid"
3+
xmlns:dc="http://purl.org/dc/elements/1.1/">
4+
<metadata>
5+
<dc:identifier id="uid">NOID</dc:identifier>
6+
<dc:title>Title</dc:title>
7+
<dc:language>en</dc:language>
8+
<meta property="dcterms:modified">2019-01-01T12:00:00Z</meta>
9+
<meta property="rendition:unknown">error</meta>
10+
</metadata>
11+
<manifest>
12+
<item id="t001" href="contents.xhtml" properties="nav" media-type="application/xhtml+xml"/>
13+
</manifest>
14+
<spine>
15+
<itemref idref="t001"/>
16+
</spine>
17+
</package>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Feature: EPUB 3 — Vocabularies — Package rendering vocabulary
2+
3+
4+
Checks conformance to the "Package rendering vocabulary" section of the EPUB 3.3 specification:
5+
https://www.w3.org/TR/epub-33/#app-rendering-vocab
6+
7+
8+
Background:
9+
Given EPUB test files located at '/epub3/D-vocabularies/files/'
10+
And EPUBCheck with default settings
11+
12+
# Note:
13+
# The properties themselves are tested in the "layout.feature" file,
14+
# since all the properties are defined in that section and not in the
15+
# vocabulary appendix.
16+
17+
# D.5.1 Package rendering vocabulary
18+
19+
@spec @xref:sec-rendering-custom-properties
20+
Scenario: Report a custom rendition property using the 'rendition' prefix
21+
When checking file 'rendition-property-unknown-error.opf'
22+
Then error OPF-027 is reported
23+
And no other errors or warnings are reported
24+

0 commit comments

Comments
 (0)