Skip to content

Commit

Permalink
issue a warning when guide/reference elements are not unique // refs #…
Browse files Browse the repository at this point in the history
…493

The OPF 2.0 schematron needed to be switched to ISO Schematron to be able to implement the test.
  • Loading branch information
tofi86 committed Aug 15, 2017
1 parent 251aa93 commit 25f28c0
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/main/resources/com/adobe/epubcheck/schema/20/sch/opf.sch
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
<sch:schema xmlns:sch="http://www.ascc.net/xml/schematron">
<sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2">

<sch:ns prefix="dc" uri="http://purl.org/dc/elements/1.1/"/>
<sch:ns prefix="opf" uri="http://www.idpf.org/2007/opf"/>

<sch:pattern name="opf_idAttrUnique" id="opf_idAttrUnique">
<sch:pattern id="opf_idAttrUnique">
<!-- id attribute value must be unique for any id attribute in opf file-->
<sch:rule context="//*[@id]">
<sch:assert test="count(//@id[normalize-space(.) = normalize-space(current()/@id)]) = 1">The
"id" attribute does not have a unique value</sch:assert>
</sch:rule>
</sch:pattern>

<sch:pattern id="opf_guideReferenceUnique">
<!-- guide/reference element should be unique (#493) -->
<sch:rule context="opf:reference">
<sch:let name="current_type_normalized" value="normalize-space(lower-case(@type))"/>
<sch:let name="current_href_normalized" value="normalize-space(lower-case(@href))"/>
<sch:assert test="
count(//opf:reference[
normalize-space(lower-case(@type)) = $current_type_normalized and
normalize-space(lower-case(@href)) = $current_href_normalized
]) = 1">WARNING: Duplicate 'reference' elements with the same 'type' and 'href' attributes</sch:assert>
</sch:rule>
</sch:pattern>

</sch:schema>
13 changes: 13 additions & 0 deletions src/main/resources/com/adobe/epubcheck/schema/30/package-30.sch
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,19 @@
</rule>
</pattern>

<pattern id="opf_guideReferenceUnique">
<!-- guide/reference element should be unique (#493) -->
<rule context="opf:reference">
<let name="current_type_normalized" value="normalize-space(lower-case(@type))"/>
<let name="current_href_normalized" value="normalize-space(lower-case(@href))"/>
<assert test="
count(//opf:reference[
normalize-space(lower-case(@type)) = $current_type_normalized and
normalize-space(lower-case(@href)) = $current_href_normalized
]) = 1">WARNING: Duplicate 'reference' elements with the same 'type' and 'href' attributes</assert>
</rule>
</pattern>

<include href="./mod/id-unique.sch"/>

</schema>
14 changes: 14 additions & 0 deletions src/test/java/com/adobe/epubcheck/opf/OPFCheckerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,20 @@ public void testIDX_CollectionInvalid_ResourceNotContentDoc()
testValidateDocument("invalid/idx-collection-resource-noxhtml.opf", EPUBVersion.VERSION_3);
}

@Test
public void testGuideReferenceUnique_EPUB2()
{
Collections.addAll(expectedWarnings, MessageId.RSC_017, MessageId.RSC_017);
testValidateDocument("invalid/guide-duplicates.opf", EPUBVersion.VERSION_2);
}

@Test
public void testGuideReferenceUnique_EPUB3()
{
Collections.addAll(expectedWarnings, MessageId.RSC_017, MessageId.RSC_017);
testValidateDocument("invalid/guide-duplicates.opf", EPUBVersion.VERSION_3);
}

@Test
public void testDict_Single()
{
Expand Down
25 changes: 25 additions & 0 deletions src/test/resources/20/single/opf/invalid/guide-duplicates.opf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version='1.0' encoding='UTF-8'?>
<package xmlns:opf="http://www.idpf.org/2007/opf" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.idpf.org/2007/opf" version="2.0" unique-identifier="id">
<metadata>
<dc:rights>Public domain in the USA.</dc:rights>
<dc:identifier id="id" opf:scheme="URI">http://www.gutenberg.org/ebooks/36582</dc:identifier>
<dc:creator opf:file-as="Anonymous">Anonymous</dc:creator>
<dc:title>Advice to Sunday School Children</dc:title>
<dc:language xsi:type="dcterms:RFC4646">en</dc:language>
<dc:date opf:event="publication">2011-07-02</dc:date>
<dc:date opf:event="conversion">2011-07-03T19:26:31.417584+00:00</dc:date>
<dc:source>http://www.gutenberg.org/files/36582/36582-h/36582-h.htm</dc:source>
</metadata>
<manifest>
<item href="pgepub.css" id="item12" media-type="text/css"/>
<item href="toc.ncx" id="ncx" media-type="application/x-dtbncx+xml"/>
<item href="wrap0000.html" id="coverpage-wrapper" media-type="application/xhtml+xml"/>
</manifest>
<spine toc="ncx">
<itemref idref="coverpage-wrapper"/>
</spine>
<guide>
<reference href="wrap0000.html" type="cover" title="Cover"/>
<reference href="wrap0000.html" type="cover" title="Cover"/>
</guide>
</package>
22 changes: 22 additions & 0 deletions src/test/resources/30/single/opf/invalid/guide-duplicates.opf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<?oxygen RNGSchema="../../../src/schema/package-30.rnc" type="compact"?>
<?oxygen SCHSchema="../../../src/schema/package-30.sch"?>
<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">urn:uuid:550e8412-e29b-41d4-a716-446655441234</dc:identifier>
<dc:title>Norwegian Wood</dc:title>
<dc:language>en</dc:language>
<meta property="dcterms:modified">2011-08-19T12:00:00Z</meta>
</metadata>
<manifest>
<item id="t001" href="contents.xhtml" properties="nav" media-type="application/xhtml+xml" />
</manifest>
<spine>
<itemref idref="t001" />
</spine>
<guide>
<reference href="contents.xhtml" type="cover" title="Cover"/>
<reference href="cover.xhtml" type="cover" title="Cover"/>
<reference href="contents.xhtml" type="cover"/>
</guide>
</package>

0 comments on commit 25f28c0

Please sign in to comment.