Search in sources :

Example 1 with ILocation

use of com.helger.commons.location.ILocation 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;
}
Also used : MapBasedNamespaceContext(com.helger.xml.namespace.MapBasedNamespaceContext) XPath(javax.xml.xpath.XPath) XPathExpressionException(javax.xml.xpath.XPathExpressionException) ErrorReporter(net.sf.saxon.lib.ErrorReporter) LoggerFactory(org.slf4j.LoggerFactory) PSPhase(com.helger.schematron.pure.model.PSPhase) ToStringGenerator(com.helger.commons.string.ToStringGenerator) AbstractPSBoundSchema(com.helger.schematron.pure.bound.AbstractPSBoundSchema) Configuration(net.sf.saxon.Configuration) XmlProcessingError(net.sf.saxon.s9api.XmlProcessingError) PSRule(com.helger.schematron.pure.model.PSRule) XPathFactoryConfigurationException(javax.xml.xpath.XPathFactoryConfigurationException) PSSchema(com.helger.schematron.pure.model.PSSchema) IXPathConfig(com.helger.schematron.pure.xpath.IXPathConfig) XPathHelper(com.helger.xml.xpath.XPathHelper) IPSElement(com.helger.schematron.pure.model.IPSElement) Map(java.util.Map) IPSErrorHandler(com.helger.schematron.pure.errorhandler.IPSErrorHandler) PSName(com.helger.schematron.pure.model.PSName) ILocation(com.helger.commons.location.ILocation) IPSQueryBinding(com.helger.schematron.pure.binding.IPSQueryBinding) XPathFunctionResolver(javax.xml.xpath.XPathFunctionResolver) SchematronValidationException(com.helger.schematron.pure.validation.SchematronValidationException) IPSHasMixedContent(com.helger.schematron.pure.model.IPSHasMixedContent) XPathConfigBuilder(com.helger.schematron.pure.xpath.XPathConfigBuilder) SingleError(com.helger.commons.error.SingleError) XPathVariableResolver(javax.xml.xpath.XPathVariableResolver) ICommonsList(com.helger.commons.collection.impl.ICommonsList) XPathEvaluator(net.sf.saxon.xpath.XPathEvaluator) SchematronBindException(com.helger.schematron.pure.binding.SchematronBindException) ICommonsMap(com.helger.commons.collection.impl.ICommonsMap) XPath(javax.xml.xpath.XPath) PSXPathVariables(com.helger.schematron.pure.binding.xpath.PSXPathVariables) SaxonNamespaceContext(com.helger.schematron.saxon.SaxonNamespaceContext) XPathExpression(javax.xml.xpath.XPathExpression) Function(java.util.function.Function) Node(org.w3c.dom.Node) IPSValidationHandler(com.helger.schematron.pure.validation.IPSValidationHandler) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) EErrorLevel(com.helger.commons.error.level.EErrorLevel) Logger(org.slf4j.Logger) NodeList(org.w3c.dom.NodeList) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) MapBasedNamespaceContext(com.helger.xml.namespace.MapBasedNamespaceContext) PSDiagnostic(com.helger.schematron.pure.model.PSDiagnostic) ValueEnforcer(com.helger.commons.ValueEnforcer) CommonsHashMap(com.helger.commons.collection.impl.CommonsHashMap) PSPattern(com.helger.schematron.pure.model.PSPattern) PSValueOf(com.helger.schematron.pure.model.PSValueOf) PSAssertReport(com.helger.schematron.pure.model.PSAssertReport) XPathEvaluationHelper(com.helger.schematron.pure.xpath.XPathEvaluationHelper) SimpleLocation(com.helger.commons.location.SimpleLocation) NotThreadSafe(javax.annotation.concurrent.NotThreadSafe) XmlProcessingError(net.sf.saxon.s9api.XmlProcessingError) IPSErrorHandler(com.helger.schematron.pure.errorhandler.IPSErrorHandler) ILocation(com.helger.commons.location.ILocation) Configuration(net.sf.saxon.Configuration) SaxonNamespaceContext(com.helger.schematron.saxon.SaxonNamespaceContext) XPathEvaluator(net.sf.saxon.xpath.XPathEvaluator) SimpleLocation(com.helger.commons.location.SimpleLocation) Nonnull(javax.annotation.Nonnull)

Example 2 with ILocation

use of com.helger.commons.location.ILocation in project phive by phax.

the class PhiveJsonHelper method getAsIError.

@Nonnull
public static IError getAsIError(@Nonnull final IJsonObject aObj) {
    final IErrorLevel aErrorLevel = getAsErrorLevel(aObj.getAsString(JSON_ERROR_LEVEL));
    final String sErrorID = aObj.getAsString(JSON_ERROR_ID);
    final String sErrorFieldName = aObj.getAsString(JSON_ERROR_FIELD_NAME);
    // Try new structured version
    ILocation aErrorLocation = getAsErrorLocation(aObj.getAsObject(JSON_ERROR_LOCATION_OBJ));
    if (aErrorLocation == null) {
        final IJsonValue aErrorLocationValue = aObj.getAsValue(JSON_ERROR_LOCATION_STR);
        if (aErrorLocationValue != null) {
            // It's a string - old version
            aErrorLocation = new SimpleLocation(aErrorLocationValue.getAsString());
        }
    }
    final String sErrorText = aObj.getAsString(JSON_ERROR_TEXT);
    final String sTest = aObj.getAsString(JSON_TEST);
    final PhiveRestoredException aLinkedException = PhiveRestoredException.createFromJson(aObj.getAsObject(JSON_EXCEPTION));
    if (sTest != null)
        return new SVRLResourceError(aErrorLevel, sErrorID, sErrorFieldName, aErrorLocation, new ConstantHasErrorText(sErrorText), aLinkedException, sTest);
    return new SingleError(aErrorLevel, sErrorID, sErrorFieldName, aErrorLocation, new ConstantHasErrorText(sErrorText), aLinkedException);
}
Also used : IJsonValue(com.helger.json.IJsonValue) SingleError(com.helger.commons.error.SingleError) ILocation(com.helger.commons.location.ILocation) IErrorLevel(com.helger.commons.error.level.IErrorLevel) SimpleLocation(com.helger.commons.location.SimpleLocation) SVRLResourceError(com.helger.schematron.svrl.SVRLResourceError) ConstantHasErrorText(com.helger.commons.error.text.ConstantHasErrorText) Nonnull(javax.annotation.Nonnull)

Aggregations

SingleError (com.helger.commons.error.SingleError)2 ILocation (com.helger.commons.location.ILocation)2 SimpleLocation (com.helger.commons.location.SimpleLocation)2 Nonnull (javax.annotation.Nonnull)2 ValueEnforcer (com.helger.commons.ValueEnforcer)1 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)1 CommonsHashMap (com.helger.commons.collection.impl.CommonsHashMap)1 ICommonsList (com.helger.commons.collection.impl.ICommonsList)1 ICommonsMap (com.helger.commons.collection.impl.ICommonsMap)1 EErrorLevel (com.helger.commons.error.level.EErrorLevel)1 IErrorLevel (com.helger.commons.error.level.IErrorLevel)1 ConstantHasErrorText (com.helger.commons.error.text.ConstantHasErrorText)1 ToStringGenerator (com.helger.commons.string.ToStringGenerator)1 IJsonValue (com.helger.json.IJsonValue)1 IPSQueryBinding (com.helger.schematron.pure.binding.IPSQueryBinding)1 SchematronBindException (com.helger.schematron.pure.binding.SchematronBindException)1 PSXPathVariables (com.helger.schematron.pure.binding.xpath.PSXPathVariables)1 AbstractPSBoundSchema (com.helger.schematron.pure.bound.AbstractPSBoundSchema)1 IPSErrorHandler (com.helger.schematron.pure.errorhandler.IPSErrorHandler)1 IPSElement (com.helger.schematron.pure.model.IPSElement)1