use of com.helger.commons.location.SimpleLocation in project ph-schematron by phax.
the class AbstractCollectingPSErrorHandler method handle.
@Override
protected void handle(@Nullable final IReadableResource aRes, @Nonnull final IErrorLevel aErrorLevel, @Nullable final IPSElement aSourceElement, @Nonnull final String sMessage, @Nullable final Throwable t) {
final SingleErrorBuilder aBuilder = SingleError.builder().setErrorLevel(aErrorLevel).setErrorLocation(aRes == null ? null : new SimpleLocation(aRes.getResourceID())).setErrorText(sMessage).setLinkedException(t);
if (aSourceElement != null) {
String sField = ClassHelper.getClassLocalName(aSourceElement);
if (aSourceElement instanceof IPSHasID && ((IPSHasID) aSourceElement).hasID())
sField += " [ID=" + ((IPSHasID) aSourceElement).getID() + "]";
aBuilder.setErrorFieldName(sField);
}
m_aErrorList.add(aBuilder.build());
}
use of com.helger.commons.location.SimpleLocation 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 com.helger.commons.location.SimpleLocation in project phive by phax.
the class ValidationExecutorXSD method applyValidation.
@Nonnull
public ValidationResult applyValidation(@Nonnull final IValidationSourceXML aSource, @Nullable final Locale aLocale) {
ValueEnforcer.notNull(aSource, "Source");
final IValidationArtefact aVA = getValidationArtefact();
// Find the XML schema required for validation
// as we don't have a node, we need to trust the implementation class
final Schema aSchema = m_aSchemaProvider.get();
assert aSchema != null;
final ErrorList aErrorList = new ErrorList();
try {
// Apply the XML schema validation
XMLSchemaValidationHelper.validate(aSchema, aSource.getAsTransformSource(), aErrorList, aLocale);
} catch (final IllegalArgumentException ex) {
// Happens when non-XML document is trying to be parsed
if (ex.getCause() instanceof SAXParseException) {
aErrorList.add(AbstractSAXErrorHandler.getSaxParseError(EErrorLevel.FATAL_ERROR, (SAXParseException) ex.getCause()));
} else {
aErrorList.add(SingleError.builderFatalError().errorLocation(new SimpleLocation(aVA.getRuleResourcePath())).errorText("The document to be validated is not an XML document").linkedException(ex).build());
}
}
// Build result object
return new ValidationResult(aVA, aErrorList.getAllFailures());
}
use of com.helger.commons.location.SimpleLocation in project phive by phax.
the class PhiveJsonHelperTest method testSVRLError.
@Test
public void testSVRLError() {
final IError aError = new SVRLResourceError(EErrorLevel.ERROR, "id2", "field1", new SimpleLocation("res12", 3, 4), new ConstantHasErrorText("bla failed"), null, " my test <>");
// To Json
final IJsonObject aJson = PhiveJsonHelper.getJsonError(aError, Locale.US);
assertNotNull(aJson);
// And back
final IError aError2 = PhiveJsonHelper.getAsIError(aJson);
assertNotNull(aError2);
// And forth
final IJsonObject aJson2 = PhiveJsonHelper.getJsonError(aError2, Locale.US);
assertNotNull(aJson2);
CommonsTestHelper.testDefaultImplementationWithEqualContentObject(aJson, aJson2);
CommonsTestHelper.testDefaultImplementationWithEqualContentObject(aError, aError2);
}
use of com.helger.commons.location.SimpleLocation in project ph-schematron by phax.
the class PSReader method _warn.
/**
* Emit a warning with the registered error handler.
*
* @param aSourceElement
* The source element where the error occurred.
* @param sMessage
* The main warning message.
*/
private void _warn(@Nonnull final IPSElement aSourceElement, @Nonnull final String sMessage) {
ValueEnforcer.notNull(aSourceElement, "SourceElement");
ValueEnforcer.notNull(sMessage, "Message");
m_aErrorHandler.handleError(SingleError.builderWarn().errorLocation(new SimpleLocation(m_aResource.getPath())).errorFieldName(IPSErrorHandler.getErrorFieldName(aSourceElement)).errorText(sMessage).build());
}
Aggregations