Skip to content

Commit 5045d78

Browse files
committed
fix: silence a Saxon warning (Schematron XSLT)
The Schematron XSLT built in Jing as an `/..` XPath expression which always evaluates to the empty sequence. Saxon 9.8 consequently raises a SXWN9000 warning, when the validators are created (statically, during EPUBCheck's intializations). This PR initalizes Jing's transformer factory with a static error listener that ignores this warning. This is tested as an integration test (since the warning is produced on the standard error stream at initialization time), run via the Maven failsafe plugin. Fixes #859
1 parent f572a86 commit 5045d78

File tree

3 files changed

+90
-1
lines changed

3 files changed

+90
-1
lines changed

pom.xml

+13
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,19 @@
344344
</execution>
345345
</executions>
346346
</plugin>
347+
<plugin>
348+
<groupId>org.apache.maven.plugins</groupId>
349+
<artifactId>maven-failsafe-plugin</artifactId>
350+
<version>2.22.1</version>
351+
<executions>
352+
<execution>
353+
<goals>
354+
<goal>integration-test</goal>
355+
<goal>verify</goal>
356+
</goals>
357+
</execution>
358+
</executions>
359+
</plugin>
347360
<plugin>
348361
<groupId>org.codehaus.mojo</groupId>
349362
<artifactId>xml-maven-plugin</artifactId>

src/main/java/com/adobe/epubcheck/xml/XMLValidator.java

+18-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.net.URISyntaxException;
2929
import java.net.URL;
3030

31+
import javax.xml.transform.TransformerException;
3132
import javax.xml.transform.TransformerFactory;
3233

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

5556
import net.sf.saxon.Configuration;
5657
import net.sf.saxon.TransformerFactoryImpl;
58+
import net.sf.saxon.lib.FeatureKeys;
59+
import net.sf.saxon.lib.StandardErrorListener;
5760
import net.sf.saxon.sxpath.IndependentContext;
5861
import net.sf.saxon.sxpath.XPathStaticContext;
5962
import net.sf.saxon.trans.SymbolicName;
60-
import net.sf.saxon.om.StandardNames;
63+
import net.sf.saxon.trans.XPathException;
6164

6265

6366
public class XMLValidator
@@ -193,6 +196,20 @@ public void initTransformerFactory(TransformerFactory factory)
193196
{
194197
configuration.registerExtensionFunction(new SystemIdFunction());
195198
}
199+
// Used to silence Saxon's warning about an XPath expression in Jing's built-in Schematron XSLT
200+
// See issue #859
201+
factory.setAttribute(FeatureKeys.XSLT_STATIC_ERROR_LISTENER_CLASS, SilencingErrorListener.class.getName());
202+
}
203+
}
204+
}
205+
206+
public static class SilencingErrorListener extends StandardErrorListener {
207+
208+
@Override
209+
public void warning(TransformerException exception) {
210+
XPathException xe = XPathException.makeXPathException(exception);
211+
if (!"SXWN9000".equals(xe.getErrorCodeLocalPart())) {
212+
super.warning(exception);
196213
}
197214
}
198215
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package com.adobe.epubcheck.cli;
2+
3+
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.fail;
5+
6+
import java.io.IOException;
7+
import java.io.InputStream;
8+
9+
import org.junit.Test;
10+
11+
import com.google.common.collect.ObjectArrays;
12+
13+
public class CheckerIT
14+
{
15+
16+
private static final String[] cmd = new String[] { "java", "-jar", "target/epubcheck.jar" };
17+
private static String valid30EPUB = "src/test/resources/30/epub/valid/";
18+
19+
@Test
20+
public void testValidEPUB()
21+
{
22+
try
23+
{
24+
Process process = run(valid30EPUB + "lorem.epub");
25+
InputStream stderr = process.getErrorStream();
26+
process.waitFor();
27+
assertEmpty(stderr);
28+
assertEquals(0, process.exitValue());
29+
} catch (Exception e)
30+
{
31+
fail(e.getMessage());
32+
}
33+
}
34+
35+
private static Process run(String epub)
36+
{
37+
ProcessBuilder builder = new ProcessBuilder(ObjectArrays.concat(cmd, epub));
38+
try
39+
{
40+
return builder.start();
41+
} catch (IOException e)
42+
{
43+
fail(e.getMessage());
44+
return null;
45+
}
46+
}
47+
48+
private static void assertEmpty(InputStream inputStream)
49+
{
50+
try
51+
{
52+
if (inputStream.read() == -1) return;
53+
fail("stream is not empty");
54+
} catch (IOException e)
55+
{
56+
fail(e.getMessage());
57+
}
58+
}
59+
}

0 commit comments

Comments
 (0)