@Override protected Templates createResource(Object... params) { try { LOG.debug("Creating new Schematron stylesheet"); Source rules = resourceContent(params); Map<String, Object> parameters = resourceParameters(params); LOG.debug("step 1 of 3"); Source source = step(xsltTransmogrifier, rules, "/schematron/iso_dsdl_include.xsl", parameters); LOG.debug("step 2 of 3"); source = step(xsltTransmogrifier, source, "/schematron/iso_abstract_expand.xsl", parameters); LOG.debug("step 3 of 3"); source = step(xsltTransmogrifier, source, "/schematron/iso_svrl_for_xslt2.xsl", parameters); Templates template = getFactory().newTemplates(source); LOG.debug("done!"); return template; } catch (Exception e) { throw new IllegalArgumentException("The schematron rules resource " + resourceLocation(params) + " is not valid", e); } }
/** * Specifies that a schematron validation report is generated */ public TransmogrifierAdapterDefinition schematron() { transmogrifier = new SchematronTransmogrifier<>(String.class); return (TransmogrifierAdapterDefinition)input(bodyAs(StreamSource.class)); }
public void validate(Source message, SchematronProfile profile) { SchematronOutput svrl = schematronTransmogrifier.zap(message, profile); List<ValidationException> exceptions = new ArrayList<>(); svrl.getActivePatternAndFiredRuleAndFailedAssert().stream() .filter(o -> o instanceof FailedAssert) .forEach(o -> { FailedAssert failedAssert = (FailedAssert) o; exceptions.add(new ValidationException(message(failedAssert))); }); if (!exceptions.isEmpty()) { throw new SchematronValidationException(exceptions, svrl); } }
@Override protected String resourceCacheKey(Object... params) { String phase = null; if (params[0] instanceof SchematronProfile) { SchematronProfile schematronProfile = (SchematronProfile) params[0]; Map<String, Object> parameters = schematronProfile.getParameters(); if (parameters != null) { phase = (String) parameters.get("phase"); } } return (phase != null) ? resourceLocation(params) + '\n' + phase : resourceLocation(params); }
/** * Specifies that a schematron validation report is generated * @param clazz * the resulting type of the message bodyf after the transformation */ public <T> TransmogrifierAdapterDefinition schematron(Class<T> clazz) { transmogrifier = new SchematronTransmogrifier<>(clazz); return (TransmogrifierAdapterDefinition)input(bodyAs(StreamSource.class)); }
@Test public void testConvert() throws IOException { Source testXml = new StreamSource(getClass().getResourceAsStream("/schematron/schematron-test.xml")); String result = svi.zap(testXml, "/schematron/schematron-test-rules.xml"); assertFalse(result.contains("svrl:failed-assert")); }
@Before public void setUp() throws Exception { svi = new SchematronTransmogrifier<>(String.class); }
@Test public void testConvertFail() throws IOException { Source testXml = new StreamSource(getClass().getResourceAsStream("/schematron/schematron-test-fail.xml")); String result = svi.zap(testXml, "/schematron/schematron-test-rules.xml"); assertTrue(result.contains("<svrl:failed-assert")); // 3 occurrences } }