Skip to content

Commit

Permalink
feat: update checking of the package rendering vocabulary
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
rdeltour committed Nov 27, 2022
1 parent 3199b81 commit 3086258
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 47 deletions.
12 changes: 11 additions & 1 deletion src/main/java/com/adobe/epubcheck/opf/OPFHandler30.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@

import com.adobe.epubcheck.api.EPUBLocation;
import com.adobe.epubcheck.api.QuietReport;
import com.adobe.epubcheck.messages.LocalizedMessages;
import com.adobe.epubcheck.messages.MessageId;
import com.adobe.epubcheck.opf.ResourceCollection.Roles;
import com.adobe.epubcheck.opf.XRefChecker.Type;
Expand Down Expand Up @@ -592,8 +593,9 @@ private void processMeta()

if (prop.isPresent() && !metadataBuilders.isEmpty())
{
String value = Strings.nullToEmpty((String) e.getPrivateData()).trim();
metadataBuilders.peekFirst().meta(e.getAttribute("id"), prop.get(),
(String) e.getPrivateData(), e.getAttribute("refines"));
value, e.getAttribute("refines"));

// Primary metadata checks
if (metadataBuilders.size() == 1)
Expand All @@ -608,6 +610,14 @@ private void processMeta()
context.featureReport.report(FeatureEnum.MEDIA_OVERLAYS_PLAYBACK_ACTIVE_CLASS, location(),
e.getPrivateData().toString());
break;
case "rendition:spread":
if (value.equals("portrait"))
{
report.message(MessageId.OPF_086, location(), "rendition:spread portrait",
LocalizedMessages.getInstance(context.locale)
.getSuggestion(MessageId.OPF_086, null));
}
break;
default:
break;
}
Expand Down
77 changes: 65 additions & 12 deletions src/main/java/com/adobe/epubcheck/vocab/RenditionVocabs.java
Original file line number Diff line number Diff line change
@@ -1,43 +1,96 @@
package com.adobe.epubcheck.vocab;

import com.adobe.epubcheck.opf.ValidationContext;
import com.google.common.base.Preconditions;

public final class RenditionVocabs
{
public static final String PREFIX = "rendition";
public static final String URI = "http://www.idpf.org/vocab/rendition/#";

public static final EnumVocab<META_PROPERTIES> META_VOCAB = new EnumVocab<META_PROPERTIES>(
META_PROPERTIES.class, URI);
META_PROPERTIES.class, URI, PREFIX);

public enum META_PROPERTIES
public enum META_PROPERTIES implements PropertyStatus
{
FLOW,
LAYOUT,
ORIENTATION,
SPREAD,
VIEWPORT
VIEWPORT(DEPRECATED),
FLOW;

private final PropertyStatus status;

private META_PROPERTIES()
{
this(ALLOWED);
}

private META_PROPERTIES(PropertyStatus status)
{
this.status = Preconditions.checkNotNull(status);
}

@Override
public boolean isAllowed(ValidationContext context)
{
return status.isAllowed(context);
}

@Override
public boolean isDeprecated()
{
return status.isDeprecated();
}
}

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

public enum ITEMREF_PROPERTIES
public enum ITEMREF_PROPERTIES implements PropertyStatus
{
ALIGN_X_CENTER,
FLOW_AUTO,
FLOW_PAGINATED,
FLOW_SCROLLED_CONTINUOUS,
FLOW_SCROLLED_DOC,
LAYOUT_PRE_PAGINATED,
LAYOUT_REFLOWABLE,
ORIENTATION_AUTO,
ORIENTATION_LANDSCAPE,
ORIENTATION_PORTRAIT,
PAGE_SPREAD_CENTER,
SPREAD_AUTO,
SPREAD_BOTH,
SPREAD_LANDSCAPE,
SPREAD_NONE,
SPREAD_PORTRAIT
SPREAD_PORTRAIT(DEPRECATED),
PAGE_SPREAD_CENTER,
PAGE_SPREAD_LEFT,
PAGE_SPREAD_RIGHT,
FLOW_PAGINATED,
FLOW_SCROLLED_CONTINUOUS,
FLOW_SCROLLED_DOC,
FLOW_AUTO,
ALIGN_X_CENTER;

private final PropertyStatus status;

private ITEMREF_PROPERTIES()
{
this(ALLOWED);
}

private ITEMREF_PROPERTIES(PropertyStatus status)
{
this.status = Preconditions.checkNotNull(status);
}

@Override
public boolean isAllowed(ValidationContext context)
{
return status.isAllowed(context);
}

@Override
public boolean isDeprecated()
{
return status.isDeprecated();
}
}

private RenditionVocabs()
Expand Down
20 changes: 2 additions & 18 deletions src/main/resources/com/adobe/epubcheck/schema/30/package-30.sch
Original file line number Diff line number Diff line change
Expand Up @@ -455,24 +455,8 @@
</rule>
</pattern>

<pattern id="opf.meta.viewport.deprecated">
<rule context="opf:metadata/opf:meta[normalize-space(@property)='rendition:viewport']">
<report test=".">WARNING: Use of the rendition:viewport property is deprecated</report>
</rule>
</pattern>

<pattern id="opf.meta.spread.portrait.deprecated">
<rule context="opf:metadata/opf:meta[normalize-space(@property)='rendition:spread']">
<report test=". = 'portrait'">WARNING: Use of the rendition:spread value "portrait" is deprecated in favour of the value "both"</report>
</rule>
</pattern>

<pattern id="opf.itemref.spread.portrait.deprecated">
<rule context="opf:spine/opf:itemref[@properties]">
<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>
</rule>
</pattern>


<!--FIXME deprecation should be in vocab-->
<pattern id="opf.meta.meta-auth.deprecated">
<rule context="opf:metadata/opf:meta[normalize-space(@property)='meta-auth']">
<report test=".">WARNING: Use of the meta-auth property is deprecated</report>
Expand Down
32 changes: 16 additions & 16 deletions src/test/resources/epub3/08-layout/layout.feature
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ Feature: EPUB 3 — Layout Rendering Control
And the message contains "refines"
And no other errors or warnings are reported

@spec @xref:spread
Scenario: the 'rendition:spread' 'portrait' value is deprecated as a global value
When checking file 'rendition-spread-portrait-global-deprecated-warning.opf'
Then warning OPF-086 is reported
And no other errors or warnings are reported

#### 8.2.2.3.1 Synthetic spread overrides

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

Scenario: the 'rendition:spread' 'portrait' value is deprecated as a global value
When checking file 'rendition-spread-portrait-global-deprecated-warning.opf'
Then warning RSC-017 is reported
And the message contains "is deprecated"
And no other errors or warnings are reported

Scenario: the 'rendition:spread' 'spread-portrait' value is deprecated as a spine override
When checking file 'rendition-spread-portrait-itemref-deprecated-warning.opf'
Then warning RSC-017 is reported
And the message contains "is deprecated"
And no other errors or warnings are reported


#### 8.2.2.4 Spread placement

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

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


#### 8.2.2.5 Viewport dimensions (deprecated)

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

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

Scenario: the 'rendition:viewport' property cannot be declared more than once
When checking file 'rendition-viewport-duplicate-error.opf'
Then warning RSC-017 is reported 2 times (since 'viewport' is deprecated)
Then warning OPF-086 is reported 2 times (since 'viewport' is deprecated)
And error RSC-005 is reported
And the message contains 'The "rendition:viewport" property must not occur more than one time as a global value'
And no other errors or warnings are reported
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<package xmlns="http://www.idpf.org/2007/opf" version="3.0" unique-identifier="uid"
xmlns:dc="http://purl.org/dc/elements/1.1/">
<metadata>
<dc:identifier id="uid">NOID</dc:identifier>
<dc:title>Title</dc:title>
<dc:language>en</dc:language>
<meta property="dcterms:modified">2019-01-01T12:00:00Z</meta>
<meta property="rendition:unknown">error</meta>
</metadata>
<manifest>
<item id="t001" href="contents.xhtml" properties="nav" media-type="application/xhtml+xml"/>
</manifest>
<spine>
<itemref idref="t001"/>
</spine>
</package>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Feature: EPUB 3 — Vocabularies — Package rendering vocabulary


Checks conformance to the "Package rendering vocabulary" section of the EPUB 3.3 specification:
https://www.w3.org/TR/epub-33/#app-rendering-vocab


Background:
Given EPUB test files located at '/epub3/D-vocabularies/files/'
And EPUBCheck with default settings

# Note:
# The properties themselves are tested in the "layout.feature" file,
# since all the properties are defined in that section and not in the
# vocabulary appendix.

# D.5.1 Package rendering vocabulary

@spec @xref:sec-rendering-custom-properties
Scenario: Report a custom rendition property using the 'rendition' prefix
When checking file 'rendition-property-unknown-error.opf'
Then error OPF-027 is reported
And no other errors or warnings are reported

0 comments on commit 3086258

Please sign in to comment.