Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a variety of JSON report issues #1525

Merged
merged 7 commits into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main/java/com/adobe/epubcheck/css/CSSHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ else if (propertyName.equals("src"))
URL fontURL = parsedURLs.get(((CssURI) construct).toUriString());
if (fontURL != null && context.resourceRegistry.isPresent())
{
fontURI = context.relativize(fontURL);
// check font mimetypes
String fontMimeType = context.getMimeType(fontURL);
if (fontMimeType != null)
Expand Down
74 changes: 58 additions & 16 deletions src/main/java/com/adobe/epubcheck/opf/OPFHandler30.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import com.adobe.epubcheck.api.QuietReport;
import com.adobe.epubcheck.messages.LocalizedMessages;
import com.adobe.epubcheck.messages.MessageId;
import com.adobe.epubcheck.opf.MetadataSet.Metadata;
import com.adobe.epubcheck.opf.ResourceCollection.Roles;
import com.adobe.epubcheck.util.EpubConstants;
import com.adobe.epubcheck.util.FeatureEnum;
Expand Down Expand Up @@ -96,7 +97,8 @@ public class OPFHandler30 extends OPFHandler
.put(DCTERMS_PREFIX, DCTERMS_VOCAB).put(MARC_PREFIX, MARC_VOCAB).put(ONIX_PREFIX, ONIX_VOCAB)
.put(SCHEMA_PREFIX, SCHEMA_VOCAB).put(XSD_PREFIX, XSD_VOCAB).build();
private static final Map<String, Vocab> RESERVED_META_VOCABS = new ImmutableMap.Builder<String, Vocab>()
.put("", AggregateVocab.of(META_VOCAB, META_VOCAB_CAMEL)).put(AccessibilityVocab.PREFIX, AccessibilityVocab.META_VOCAB)
.put("", AggregateVocab.of(META_VOCAB, META_VOCAB_CAMEL))
.put(AccessibilityVocab.PREFIX, AccessibilityVocab.META_VOCAB)
.put(MediaOverlaysVocab.PREFIX, MediaOverlaysVocab.VOCAB)
.put(RenditionVocabs.PREFIX, RenditionVocabs.META_VOCAB).putAll(RESERVED_VOCABS).build();
private static final Map<String, Vocab> RESERVED_ITEM_VOCABS = new ImmutableMap.Builder<String, Vocab>()
Expand Down Expand Up @@ -646,32 +648,72 @@ private void checkLanguageTag(String language)

protected void reportMetadata()
{
// Report publication rendition layout
if (getMetadata().containsPrimary(
RenditionVocabs.META_VOCAB.get(RenditionVocabs.META_PROPERTIES.LAYOUT), "pre-paginated"))
{
report.info(null, FeatureEnum.HAS_FIXED_LAYOUT, "pre-paginated");
report.info(null, FeatureEnum.RENDITION_LAYOUT, "pre-paginated");
report.info(null, FeatureEnum.HAS_FIXED_LAYOUT, "true");
}
// Report publication rendition orientation (if set)
Optional<Metadata> orientation = MetadataSet.tryFind(getMetadata().getAll(),
RenditionVocabs.META_VOCAB.get(RenditionVocabs.META_PROPERTIES.ORIENTATION),
Optional.absent());
if (orientation.isPresent())
{
report.info(null, FeatureEnum.RENDITION_ORIENTATION, orientation.get().getValue());
}
// Report publication rendition spread (if set)
Optional<Metadata> spread = MetadataSet.tryFind(getMetadata().getAll(),
RenditionVocabs.META_VOCAB.get(RenditionVocabs.META_PROPERTIES.SPREAD),
Optional.absent());
if (spread.isPresent())
{
report.info(null, FeatureEnum.RENDITION_SPREAD, spread.get().getValue());
}
}

@Override
protected void reportItem(OPFItem item)
{
super.reportItem(item);
boolean isFixed = getMetadata().containsPrimary(
RenditionVocabs.META_VOCAB.get(RenditionVocabs.META_PROPERTIES.LAYOUT), "pre-paginated");
if (item.getProperties().contains(
RenditionVocabs.ITEMREF_VOCAB.get(RenditionVocabs.ITEMREF_PROPERTIES.LAYOUT_PRE_PAGINATED)))
{
isFixed = true;
}
else if (item.getProperties().contains(
RenditionVocabs.ITEMREF_VOCAB.get(RenditionVocabs.ITEMREF_PROPERTIES.LAYOUT_REFLOWABLE)))
{
isFixed = false;
}
if (isFixed)

// Report rendition properties overrides
Set<RenditionVocabs.ITEMREF_PROPERTIES> properties = Property.filter(item.getProperties(),
RenditionVocabs.ITEMREF_PROPERTIES.class);
for (RenditionVocabs.ITEMREF_PROPERTIES property : properties)
{
report.info(item.getPath(), FeatureEnum.HAS_FIXED_LAYOUT, String.valueOf(true));
switch (property)
{
// Rendition layout properties
case LAYOUT_PRE_PAGINATED:
report.info(item.getPath(), FeatureEnum.RENDITION_LAYOUT, "pre-paginated");
report.info(item.getPath(), FeatureEnum.HAS_FIXED_LAYOUT, "true");
break;
case LAYOUT_REFLOWABLE:
report.info(item.getPath(), FeatureEnum.RENDITION_LAYOUT, "reflowable");
report.info(item.getPath(), FeatureEnum.HAS_FIXED_LAYOUT, "false");
break;
// Orientation properties
case ORIENTATION_AUTO:
case ORIENTATION_LANDSCAPE:
case ORIENTATION_PORTRAIT:
report.info(item.getPath(), FeatureEnum.RENDITION_ORIENTATION,
property.name().substring(12).toLowerCase(Locale.ROOT));
break;
// Spread properties
case SPREAD_AUTO:
case SPREAD_BOTH:
case SPREAD_LANDSCAPE:
case SPREAD_NONE:
case SPREAD_PORTRAIT:
report.info(item.getPath(), FeatureEnum.RENDITION_SPREAD,
property.name().substring(7).toLowerCase(Locale.ROOT));
break;

default:
break;
}
}
}
}
36 changes: 0 additions & 36 deletions src/main/java/com/adobe/epubcheck/reporting/ItemMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import com.adobe.epubcheck.util.FeatureEnum;

@SuppressWarnings("FieldCanBeLocal")
public class ItemMetadata implements Comparable<ItemMetadata>
{
@JsonProperty
Expand All @@ -32,26 +31,15 @@ public class ItemMetadata implements Comparable<ItemMetadata>
@JsonProperty
private boolean isLinear;
@JsonProperty
private Integer navigationOrder = null;
@JsonProperty
private boolean isHTML5;
@JsonProperty
private Boolean isFixedFormat = null;
@JsonProperty
private boolean isScripted;
@JsonProperty
private boolean scriptSrc;
@JsonProperty
private boolean scriptTag;
@JsonProperty
private boolean scriptInline;
@JsonProperty
private String renditionLayout;
@JsonProperty
private String renditionOrientation;
@JsonProperty
private String renditionSpread;
@SuppressWarnings("MismatchedQueryAndUpdateOfCollection")
@JsonProperty
private final SortedSet<String> referencedItems = new TreeSet<String>();

Expand Down Expand Up @@ -171,27 +159,6 @@ public void handleInfo(FeatureEnum feature, String value)
case SPINE_INDEX:
this.spineIndex = Integer.parseInt(value.trim());
break;
case HAS_HTML5:
this.isHTML5 = true;
break;
case SCRIPT:
if (value.equals("inline"))
{
this.scriptInline = true;
}
else if (value.equals("external"))
{
this.scriptSrc = true;
}
else if (value.equals("javascript"))
{
this.scriptSrc = true;
}
else if (value.equals("tag"))
{
this.scriptTag = true;
}
break;
case RENDITION_LAYOUT:
this.renditionLayout = value;
break;
Expand All @@ -201,9 +168,6 @@ else if (value.equals("tag"))
case RENDITION_SPREAD:
this.renditionSpread = value;
break;
case NAVIGATION_ORDER:
this.navigationOrder = Integer.parseInt(value.trim());
break;
default:
//System.err.printf("unhandled info message feature: found '%s' with value '%s'", feature.toString(), value != null ? value : "null");
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
/**
* This is information about the publication in general. It is intended to be serialized into json.
*/
@SuppressWarnings({"FieldCanBeLocal", "MismatchedQueryAndUpdateOfCollection"})
class PublicationMetadata
{
@JsonProperty
Expand Down Expand Up @@ -131,12 +130,6 @@ public void handleInfo(String resource, FeatureEnum feature, String value)
this.hasFixedFormat = true;
this.isBackwardCompatible = false;
break;
case HAS_HTML5:
if (resource == null)
{
this.isBackwardCompatible = false;
}
break;
case IS_SPINEITEM:
this.nSpines++;
break;
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/com/adobe/epubcheck/util/FeatureEnum.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ public enum FeatureEnum
FORMAT_VERSION("format version"),
HAS_ENCRYPTION("hasEncryption"),
HAS_FIXED_LAYOUT("hasFixedLayout"),
HAS_HTML4("html 4"),
HAS_HTML5("html 5"),
HAS_MICRODATA("microdata"),
HAS_NCX("Has ncx file"),
HAS_RDFA("RDFa"),
Expand All @@ -67,7 +65,6 @@ public enum FeatureEnum
MEDIA_OVERLAYS_ACTIVE_CLASS("media:active-class"),
MEDIA_OVERLAYS_PLAYBACK_ACTIVE_CLASS("media:playback-active-class"),
MODIFIED_DATE("modification date"),
NAVIGATION_ORDER("navigation order"),
PAGE_BREAK("epub:page-break"),
PAGE_LIST("epub:page-list"),
PAGES_COUNT("pages count"),
Expand All @@ -76,7 +73,6 @@ public enum FeatureEnum
RENDITION_ORIENTATION("rendition:orientation"),
RENDITION_SPREAD("rendition:spread"),
RESOURCE("resource"),
SCRIPT("script"),
SECTIONS("sections"),
SHA_256("SHA-256"),
SIZE("size"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import com.adobe.epubcheck.opf.OPFChecker30;
import com.adobe.epubcheck.opf.ValidationContext;
import com.adobe.epubcheck.util.EPUBVersion;
import com.adobe.epubcheck.util.FeatureEnum;
import com.google.common.base.Preconditions;

import io.mola.galimatias.URL;
Expand Down Expand Up @@ -108,6 +109,9 @@ public void check()

private void checkReference(Reference reference)
{
// Report the reference
report.info(reference.location.getPath(), FeatureEnum.RESOURCE, container.relativize(reference.url));

// Retrieve the target resource
Optional<Resource> targetResource = resourceRegistry.getResource(reference.targetResource);
try
Expand Down
34 changes: 34 additions & 0 deletions src/test/java/org/w3c/epubcheck/test/JSONReportAssertionSteps.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasJsonPath;
import static com.jayway.jsonpath.matchers.JsonPathMatchers.isJson;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.everyItem;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;

import java.util.List;

import io.cucumber.java.en.Then;

public class JSONReportAssertionSteps
Expand Down Expand Up @@ -40,6 +44,24 @@ public void jsonValueIs(String path, String value)
assertThat(report.getOutput(), hasJsonPath(path, equalTo(value)));
}

@Then("JSON at {string} is {bool}")
public void jsonValueIs(String path, Boolean value)
{
assertThat(report.getOutput(), hasJsonPath(path, equalTo(value)));
}

@Then("JSON at {string} is:")
public void jsonValueIs(String path, List<String> values)
{
assertThat(report.getOutput(), hasJsonPath(path, equalTo(values)));
}

@Then("JSON at {string} is empty")
public void jsonValueIs(String path)
{
assertThat(report.getOutput(), hasJsonPath(path, is(empty())));
}

@Then("JSON at {string} is not null")
public void jsonValueIsNotNull(String path)
{
Expand All @@ -51,4 +73,16 @@ public void jsonValuesAreNotNull(String path)
{
assertThat(report.getOutput(), hasJsonPath(path, everyItem(notNullValue())));
}

@Then("JSON at {string} are all {string}")
public void jsonValuesAreAll(String path, String value)
{
assertThat(report.getOutput(), hasJsonPath(path, everyItem(equalTo(value))));
}

@Then("JSON at {string} are all {bool}")
public void jsonValuesAreAll(String path, Boolean value)
{
assertThat(report.getOutput(), hasJsonPath(path, everyItem(equalTo(value))));
}
}
5 changes: 5 additions & 0 deletions src/test/java/org/w3c/epubcheck/test/ParameterTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public MessageId apply(String input)
}

};

@ParameterType("true|false")
public Boolean bool(String value) {
return Boolean.valueOf(value);
}

@ParameterType("?i:(full publication|((Media Overlays|Navigation|Package|SVG Content|XHTML Content) Document))")
public CheckerMode checkerMode(String mode)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta charset="utf-8" />
<title>Minimal EPUB</title>
</head>
<body>
<h1>Loomings</h1>
<p>Call me Ishmael.</p>
</body>
</html>
Empty file.
14 changes: 14 additions & 0 deletions src/test/resources/reporting/files/fonts-embedded/EPUB/nav.xhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="en" lang="en">
<head>
<meta charset="utf-8"/>
<title>Minimal Nav</title>
</head>
<body>
<nav epub:type="toc">
<ol>
<li><a href="content_001.xhtml">content 001</a></li>
</ol>
</nav>
</body>
</html>
18 changes: 18 additions & 0 deletions src/test/resources/reporting/files/fonts-embedded/EPUB/package.opf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<package xmlns="http://www.idpf.org/2007/opf" version="3.0" xml:lang="en" unique-identifier="q">
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/">
<dc:title id="title">Minimal EPUB 3.0</dc:title>
<dc:language>en</dc:language>
<dc:identifier id="q">NOID</dc:identifier>
<meta property="dcterms:modified">2017-06-14T00:00:01Z</meta>
</metadata>
<manifest>
<item id="content_001" href="content_001.xhtml" media-type="application/xhtml+xml"/>
<item id="nav" href="nav.xhtml" media-type="application/xhtml+xml" properties="nav"/>
<item id="css" href="style.css" media-type="text/css" properties="remote-resources"/>
<item id="font" href="font.woff" media-type="font/woff"/>
</manifest>
<spine>
<itemref idref="content_001" />
</spine>
</package>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@font-face {
font-family: "Open Sans";
src: url("font.woff") format("woff");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?>
<container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">
<rootfiles>
<rootfile full-path="EPUB/package.opf" media-type="application/oebps-package+xml"/>
</rootfiles>
</container>
1 change: 1 addition & 0 deletions src/test/resources/reporting/files/fonts-embedded/mimetype
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
application/epub+zip
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta charset="utf-8" />
<title>Minimal EPUB</title>
</head>
<body>
<h1>Loomings</h1>
<p>Call me Ishmael.</p>
</body>
</html>