use of net.sf.saxon.lib.ErrorReporter in project ph-schematron by phax.
the class PSXPathBoundSchema method _createXPathContext.
@Nonnull
private XPath _createXPathContext() {
final MapBasedNamespaceContext aNamespaceContext = getNamespaceContext();
final XPath aXPathContext = XPathHelper.createNewXPath(m_aXPathConfig.getXPathFactory(), m_aXPathConfig.getXPathVariableResolver(), m_aXPathConfig.getXPathFunctionResolver(), aNamespaceContext);
if ("net.sf.saxon.xpath.XPathEvaluator".equals(aXPathContext.getClass().getName())) {
// Saxon implementation special handling
final XPathEvaluator aSaxonXPath = (XPathEvaluator) aXPathContext;
// Since 9.7.0-4 it must implement NamespaceResolver
aSaxonXPath.setNamespaceContext(new SaxonNamespaceContext(aNamespaceContext));
// Wrap the PSErrorHandler to a ErrorListener
final Function<Configuration, ? extends ErrorReporter> factory = cfg -> {
final IPSErrorHandler aErrHdl = getErrorHandler();
return (final XmlProcessingError error) -> {
final ILocation aLocation = error.getLocation() == null ? null : new SimpleLocation(error.getLocation().getSystemId(), error.getLocation().getLineNumber(), error.getLocation().getColumnNumber());
aErrHdl.handleError(SingleError.builder().errorLevel(error.isWarning() ? EErrorLevel.WARN : EErrorLevel.ERROR).errorID(error.getErrorCode() != null ? error.getErrorCode().toString() : null).errorLocation(aLocation).errorText(error.getMessage()).linkedException(error.getCause()).build());
};
};
aSaxonXPath.getConfiguration().setErrorReporterFactory(factory);
}
return aXPathContext;
}
use of net.sf.saxon.lib.ErrorReporter in project coffeefilter by nineml.
the class TestDriver method deepEqual.
private boolean deepEqual(XdmValue left, XdmValue right, TestResult result) throws SaxonApiException {
if (result.expected == null) {
result.expected = new ArrayList<>();
result.expected.add(left);
result.actual = new ArrayList<>();
result.actual.add(right);
result.deepEqualMessages = new ArrayList<>();
}
QName a = new QName("", "a");
QName b = new QName("", "b");
XPathCompiler compiler = processor.newXPathCompiler();
compiler.declareVariable(a);
compiler.declareVariable(b);
XPathExecutable exec;
if (runningEE) {
compiler.declareNamespace("saxon", "http://saxon.sf.net/");
exec = compiler.compile("saxon:deep-equal($a,$b, (), '?')");
} else {
exec = compiler.compile("deep-equal($a,$b)");
}
XPathSelector selector = exec.load();
selector.setVariable(a, left);
selector.setVariable(b, right);
CaptureErrors capture = new CaptureErrors();
ErrorReporter saveReporter = selector.getUnderlyingXPathContext().getErrorReporter();
selector.getUnderlyingXPathContext().setErrorReporter(capture);
XdmSequenceIterator<XdmItem> iter = selector.iterator();
XdmAtomicValue item = (XdmAtomicValue) iter.next();
selector.getUnderlyingXPathContext().setErrorReporter(saveReporter);
if (capture.messages.isEmpty()) {
result.deepEqualMessages.add("");
} else {
result.deepEqualMessages.add(capture.messages.get(0));
}
return item.getBooleanValue();
}
Aggregations