use of net.sf.saxon.s9api.XmlProcessingError 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;
}
Aggregations