Skip to content

Commit

Permalink
feat: Dublin Core elements ns must not declared as a vocab
Browse files Browse the repository at this point in the history
EPUB 3 Vocabularies section currently contains the following statemnt:

> For future compatibility with alternative serializations of the package
> document, EPUB creators MUST NOT declare a prefix for the Dublin Core
> `/elements/1.1/` namespace.

This commit implements a check for that statement in the prefix parsing
code, reported as a new error message OPF-007c.
  • Loading branch information
rdeltour committed Dec 23, 2024
1 parent 92c3d90 commit 6ae1d24
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ private void initialize()
severities.put(MessageId.OPF_007, Severity.WARNING);
severities.put(MessageId.OPF_007a, Severity.ERROR);
severities.put(MessageId.OPF_007b, Severity.ERROR);
severities.put(MessageId.OPF_007c, Severity.ERROR);
severities.put(MessageId.OPF_008, Severity.SUPPRESSED);
severities.put(MessageId.OPF_009, Severity.SUPPRESSED);
severities.put(MessageId.OPF_010, Severity.ERROR);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/adobe/epubcheck/messages/MessageId.java
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ public enum MessageId implements Comparable<MessageId>
OPF_007("OPF-007"),
OPF_007a("OPF-007a"),
OPF_007b("OPF-007b"),
OPF_007c("OPF-007c"),
OPF_008("OPF-008"),
OPF_009("OPF-009"),
OPF_010("OPF-010"),
Expand Down
34 changes: 19 additions & 15 deletions src/main/java/com/adobe/epubcheck/vocab/VocabUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ private enum EMPTY
* Parses a single property value and report validation errors on the fly.
*
* @param value
* the value to parse.
* the value to parse.
* @param vocabs
* a map of prefix to vocabularies.
* a map of prefix to vocabularies.
* @param context
* the validation context (report, locale, path, etc).
* the validation context (report, locale, path, etc).
* @param location
* the location in the validated file.
* the location in the validated file.
* @return an {@link Optional} containing the property if it was parsed
* successfully or nothing if there was a parsing error
* successfully or nothing if there was a parsing error
*/
public static Optional<Property> parseProperty(String value, Map<String, Vocab> vocabs,
ValidationContext context, EPUBLocation location)
Expand All @@ -64,13 +64,13 @@ public static Optional<Property> parseProperty(String value, Map<String, Vocab>
* errors on the fly.
*
* @param value
* the value to parse.
* the value to parse.
* @param vocabs
* a map of prefix to vocabularies.
* a map of prefix to vocabularies.
* @param context
* the validation context (report, locale, path, etc).
* the validation context (report, locale, path, etc).
* @param location
* the location in the validated file.
* the location in the validated file.
* @return
*/
public static Set<Property> parsePropertyList(String value, Map<String, ? extends Vocab> vocabs,
Expand Down Expand Up @@ -158,17 +158,17 @@ private static Set<Property> parseProperties(String value, Map<String, ? extends
* vocabularies, and default vocabularies that cannot be re-declared.
*
* @param value
* the prefix declaration to parse.
* the prefix declaration to parse.
* @param predefined
* a map of reserved prefixes to associated vocabularies.
* a map of reserved prefixes to associated vocabularies.
* @param known
* a map of known URIs to known vocabularies.
* a map of known URIs to known vocabularies.
* @param forbidden
* a set of URIs of default vocabularies that cannot be re-declared.
* a set of URIs of default vocabularies that cannot be re-declared.
* @param report
* to report errors on the fly.
* to report errors on the fly.
* @param location
* the location of the attribute in the source file.
* the location of the attribute in the source file.
* @return
*/
public static Map<String, Vocab> parsePrefixDeclaration(String value,
Expand All @@ -192,6 +192,10 @@ else if (forbidden.contains(uri))
// must not declare a default vocab
report.message(MessageId.OPF_007b, location, prefix);
}
else if ("http://purl.org/dc/elements/1.1/".equals(uri))
{
report.message(MessageId.OPF_007c, location);
}
else
{
if (predefined.containsKey(prefix)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ OPF_006=Invalid prefix declaration: URI "%1$s" is not a valid URI.
OPF_007=Re-declaration of reserved prefix "%1$s".
OPF_007a=Invalid prefix mapping: prefix "_" must not be declared.
OPF_007b=Invalid prefix mapping: default vocabulary "%1$s" must not be re-declared.
OPF_007c=Invalid prefix mapping: a prefix to the Dublin Core /elements/1.1/ namespace must not be declared
OPF_010=Error resolving reference: "%1$s".
OPF_011=itemref can’t have both page-spread-right and page-spread-left properties.
OPF_012=Item property "%1$s" is not defined for media type "%2$s".
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/"
prefix="dc: http://purl.org/dc/elements/1.1/">
<metadata>
<dc:title>Title</dc:title>
<dc:language>en</dc:language>
<dc:identifier id="uid">NOID</dc:identifier>
<meta property="dcterms:modified">2019-01-01T12:00:00Z</meta>
</metadata>
<manifest>
<item id="t001" href="contents.xhtml" properties="nav" media-type="application/xhtml+xml"/>
</manifest>
<spine>
<itemref idref="t001"/>
</spine>
</package>
6 changes: 6 additions & 0 deletions src/test/resources/epub3/D-vocabularies/vocabularies.feature
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ Feature: EPUB 3 — Vocabularies — Vocabulary association

Rule: EPUB creators MUST NOT declare a prefix for the Dublin Core `/elements/1.1/` namespace.

@spec @xref:sec-prefix-attr
Example: Report a prefix mapping to the Dublic Core elements namespace
When checking file 'prefix-mapping-dc-elements-error.opf'
Then error OPF-007c is reported
And no other errors or warnings are reported


## D.1.5 Reserved prefixes

Expand Down

0 comments on commit 6ae1d24

Please sign in to comment.