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 issue #859: Saxon warning from Jing's Schematron XSLT #910

Merged
merged 1 commit into from
Nov 22, 2018
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,19 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.1</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>xml-maven-plugin</artifactId>
Expand Down
19 changes: 18 additions & 1 deletion src/main/java/com/adobe/epubcheck/xml/XMLValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.net.URISyntaxException;
import java.net.URL;

import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;

import org.idpf.epubcheck.util.saxon.ColumnNumberFunction;
Expand All @@ -54,10 +55,12 @@

import net.sf.saxon.Configuration;
import net.sf.saxon.TransformerFactoryImpl;
import net.sf.saxon.lib.FeatureKeys;
import net.sf.saxon.lib.StandardErrorListener;
import net.sf.saxon.sxpath.IndependentContext;
import net.sf.saxon.sxpath.XPathStaticContext;
import net.sf.saxon.trans.SymbolicName;
import net.sf.saxon.om.StandardNames;
import net.sf.saxon.trans.XPathException;


public class XMLValidator
Expand Down Expand Up @@ -193,6 +196,20 @@ public void initTransformerFactory(TransformerFactory factory)
{
configuration.registerExtensionFunction(new SystemIdFunction());
}
// Used to silence Saxon's warning about an XPath expression in Jing's built-in Schematron XSLT
// See issue #859
factory.setAttribute(FeatureKeys.XSLT_STATIC_ERROR_LISTENER_CLASS, SilencingErrorListener.class.getName());
}
}
}

public static class SilencingErrorListener extends StandardErrorListener {

@Override
public void warning(TransformerException exception) {
XPathException xe = XPathException.makeXPathException(exception);
if (!"SXWN9000".equals(xe.getErrorCodeLocalPart())) {
super.warning(exception);
}
}
}
Expand Down
59 changes: 59 additions & 0 deletions src/test/java/com/adobe/epubcheck/cli/CheckerIT.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.adobe.epubcheck.cli;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

import java.io.IOException;
import java.io.InputStream;

import org.junit.Test;

import com.google.common.collect.ObjectArrays;

public class CheckerIT
{

private static final String[] cmd = new String[] { "java", "-jar", "target/epubcheck.jar" };
private static String valid30EPUB = "src/test/resources/30/epub/valid/";

@Test
public void testValidEPUB()
{
try
{
Process process = run(valid30EPUB + "lorem.epub");
InputStream stderr = process.getErrorStream();
process.waitFor();
assertEmpty(stderr);
assertEquals(0, process.exitValue());
} catch (Exception e)
{
fail(e.getMessage());
}
}

private static Process run(String epub)
{
ProcessBuilder builder = new ProcessBuilder(ObjectArrays.concat(cmd, epub));
try
{
return builder.start();
} catch (IOException e)
{
fail(e.getMessage());
return null;
}
}

private static void assertEmpty(InputStream inputStream)
{
try
{
if (inputStream.read() == -1) return;
fail("stream is not empty");
} catch (IOException e)
{
fail(e.getMessage());
}
}
}