use of com.helger.schematron.pure.errorhandler.IPSErrorHandler in project ph-schematron by phax.
the class PSXPathBoundSchemaTest method testSchematronValidation.
@Test
public void testSchematronValidation() throws SAXException, SchematronException {
for (int i = 0; i < SCH.length; ++i) {
final IReadableResource aSchRes = new ClassPathResource("test-sch/" + SCH[i]);
final IReadableResource aXmlRes = new ClassPathResource("test-xml/" + XML[i]);
// Resolve all includes
final IMicroDocument aDoc = SchematronHelper.getWithResolvedSchematronIncludes(aSchRes);
assertNotNull(aDoc);
// Read to domain object
final PSReader aReader = new PSReader(aSchRes);
final PSSchema aSchema = aReader.readSchemaFromXML(aDoc.getDocumentElement());
assertNotNull(aSchema);
// Create a compiled schema
final String sPhaseID = null;
final IPSErrorHandler aErrorHandler = null;
final IPSBoundSchema aBoundSchema = PSXPathQueryBinding.getInstance().bind(aSchema, sPhaseID, aErrorHandler);
// Validate completely
final SchematronOutputType aSVRL = aBoundSchema.validateComplete(DOMReader.readXMLDOM(aXmlRes), aXmlRes.getAsURL().toExternalForm());
assertNotNull(aSVRL);
if (false)
System.out.println(new SVRLMarshaller().getAsString(aSVRL));
}
}
use of com.helger.schematron.pure.errorhandler.IPSErrorHandler in project ph-schematron by phax.
the class Issue30Test method testOfSchematronPH.
@Test
public void testOfSchematronPH() throws Exception {
final SchematronResourcePure aResPure = SchematronResourcePure.fromFile("src/test/resources/issues/github30/ph-test.sch");
aResPure.setEntityResolver(DefaultEntityResolver.createOnDemand(aResPure.getResource()));
final IPSErrorHandler aErrorHandler = new IPSErrorHandler() {
@Override
public void warn(final IReadableResource aRes, final IPSElement aSourceElement, final String sMessage) {
s_aLogger.info(sMessage);
}
@Override
public void error(final IReadableResource aRes, final IPSElement aSourceElement, final String sMessage, final Throwable t) {
s_aLogger.info(sMessage);
}
@Override
public void error(final IPSElement aSourceElement, final String sMessage) {
s_aLogger.info(sMessage);
}
};
aResPure.setErrorHandler(aErrorHandler);
aResPure.validateCompletely();
assertFalse(aResPure.isValidSchematron());
}
use of com.helger.schematron.pure.errorhandler.IPSErrorHandler in project ph-schematron by phax.
the class SchematronResourcePure method createBoundSchema.
@Nonnull
protected IPSBoundSchema createBoundSchema() {
final IReadableResource aResource = getResource();
final IPSErrorHandler aErrorHandler = getErrorHandler();
final PSBoundSchemaCacheKey aCacheKey = new PSBoundSchemaCacheKey(aResource, getPhase(), aErrorHandler, getVariableResolver(), getFunctionResolver(), getEntityResolver());
if (aResource instanceof AbstractMemoryReadableResource || !isUseCache()) {
// No need to cache anything for memory resources
try {
return aCacheKey.createBoundSchema();
} catch (final SchematronException ex) {
// Convert to runtime exception
throw new IllegalStateException("Failed to bind Schematron", ex);
}
}
// happens
return PSBoundSchemaCache.getInstance().getFromCache(aCacheKey);
}
use of com.helger.schematron.pure.errorhandler.IPSErrorHandler in project ph-schematron by phax.
the class SchematronResourcePure method validateCompletely.
/**
* Use the internal error handler to validate all elements in the schematron.
* It tries to catch as many errors as possible.
*/
public void validateCompletely() {
// Use the provided error handler (if any)
final IPSErrorHandler aErrorHandler = m_aErrorHandler != null ? m_aErrorHandler : new DoNothingPSErrorHandler();
validateCompletely(aErrorHandler);
}
use of com.helger.schematron.pure.errorhandler.IPSErrorHandler in project ph-schematron by phax.
the class PSXPathBoundSchemaTest method testBindAllValidSchematrons.
@Test
public void testBindAllValidSchematrons() throws SchematronException {
for (final IReadableResource aRes : SchematronTestHelper.getAllValidSchematronFiles()) {
// Parse the schema
final PSSchema aSchema = new PSReader(aRes).readSchema();
assertNotNull(aSchema);
CommonsTestHelper.testToStringImplementation(aSchema);
final CollectingPSErrorHandler aLogger = new CollectingPSErrorHandler();
assertTrue(aRes.getPath(), aSchema.isValid(aLogger));
assertTrue(aLogger.isEmpty());
// Create a compiled schema
final String sPhaseID = null;
final IPSErrorHandler aErrorHandler = null;
final IPSBoundSchema aBoundSchema = PSXPathQueryBinding.getInstance().bind(aSchema, sPhaseID, aErrorHandler);
assertNotNull(aBoundSchema);
}
}
Aggregations