use of com.helger.schematron.svrl.jaxb.SchematronOutputType in project ph-schematron by phax.
the class Issue048Test method validateAndProduceSVRL.
public static void validateAndProduceSVRL(@Nonnull final File aSchematron, final File aXML) throws Exception {
final PSSchema aSchema = new PSReader(new FileSystemResource(aSchematron)).readSchema();
final PSPreprocessor aPreprocessor = new PSPreprocessor(PSXPathQueryBinding.getInstance());
final PSSchema aPreprocessedSchema = aPreprocessor.getAsPreprocessedSchema(aSchema);
final String sSCH = new PSWriter(new PSWriterSettings().setXMLWriterSettings(new XMLWriterSettings())).getXMLString(aPreprocessedSchema);
if (false)
System.out.println(sSCH);
final SchematronResourceSCH aSCH = new SchematronResourceSCH(new ReadableResourceString(sSCH, StandardCharsets.UTF_8));
// Perform validation
final SchematronOutputType aSVRL = aSCH.applySchematronValidationToSVRL(new FileSystemResource(aXML));
assertNotNull(aSVRL);
if (false)
System.out.println(new SVRLMarshaller().getAsString(aSVRL));
}
use of com.helger.schematron.svrl.jaxb.SchematronOutputType in project ph-schematron by phax.
the class Issue006Test method validateAndProduceSVRL.
@SuppressFBWarnings("BC_IMPOSSIBLE_INSTANCEOF")
public static void validateAndProduceSVRL(final File schematron, final File xml) throws Exception {
final IReadableResource aSchematron = new FileSystemResource(schematron.getAbsoluteFile());
final IReadableResource anXMLSource = new FileSystemResource(xml.getAbsoluteFile());
final AbstractSchematronResource aSCH = new SchematronResourceSCH(aSchematron);
if (aSCH instanceof SchematronResourcePure)
((SchematronResourcePure) aSCH).setErrorHandler(new LoggingPSErrorHandler());
else
System.out.println(XMLWriter.getNodeAsString(((SchematronResourceSCH) aSCH).getXSLTProvider().getXSLTDocument()));
final SchematronOutputType aSVRL = aSCH.applySchematronValidationToSVRL(anXMLSource);
assertNotNull(aSVRL);
if (false)
System.out.println(new SVRLMarshaller().getAsString(aSVRL));
}
use of com.helger.schematron.svrl.jaxb.SchematronOutputType in project ph-schematron by phax.
the class PSXPathValidationHandlerSVRL method onStart.
@Override
public void onStart(@Nonnull final PSSchema aSchema, @Nullable final PSPhase aActivePhase, @Nullable final String sBaseURI) throws SchematronValidationException {
final SchematronOutputType aSchematronOutput = new SchematronOutputType();
if (aActivePhase != null)
aSchematronOutput.setPhase(aActivePhase.getID());
aSchematronOutput.setSchemaVersion(aSchema.getSchemaVersion());
aSchematronOutput.setTitle(_getTitleAsString(aSchema.getTitle()));
// Add namespace prefixes
for (final Map.Entry<String, String> aEntry : aSchema.getAsNamespaceContext().getPrefixToNamespaceURIMap().entrySet()) {
final NsPrefixInAttributeValues aNsPrefix = new NsPrefixInAttributeValues();
aNsPrefix.setPrefix(aEntry.getKey());
aNsPrefix.setUri(aEntry.getValue());
aSchematronOutput.getNsPrefixInAttributeValues().add(aNsPrefix);
}
m_aSchematronOutput = aSchematronOutput;
m_aSchema = aSchema;
m_sBaseURI = sBaseURI;
}
use of com.helger.schematron.svrl.jaxb.SchematronOutputType in project ph-schematron by phax.
the class SchematronResourcePureTest method testResolveVariables.
@Test
public void testResolveVariables() throws SchematronException, XPathFactoryConfigurationException {
final String sTest = "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n" + "<iso:schema xmlns=\"http://purl.oclc.org/dsdl/schematron\" \n" + " xmlns:iso=\"http://purl.oclc.org/dsdl/schematron\" \n" + " xmlns:sch=\"http://www.ascc.net/xml/schematron\"\n" + " queryBinding='xslt2'\n" + " schemaVersion=\"ISO19757-3\">\n" + " <iso:title>Test ISO schematron file. Introduction mode</iso:title>\n" + " <iso:ns prefix=\"dp\" uri=\"http://www.dpawson.co.uk/ns#\" />\n" + " <iso:ns prefix=\"java\" uri=\"http://helger.com/schematron/test\" />\n" + " <iso:pattern >\n" + " <iso:title>A very simple pattern with a title</iso:title>\n" + " <iso:rule context=\"chapter\">\n" + " <iso:assert test=\"$title-element\">Chapter should have a title</iso:assert>\n" + " <iso:report test=\"java:my-count(para) = 2\">\n" + " <iso:value-of select=\"java:my-count(para)\"/> paragraphs found</iso:report>\n" + " </iso:rule>\n" + " </iso:pattern>\n" + "\n" + "</iso:schema>";
// Test without variable and function resolver
// -> an error is expected, but we don't need to log it
assertFalse(SchematronResourcePure.fromString(sTest, StandardCharsets.UTF_8).setErrorHandler(new DoNothingPSErrorHandler()).isValidSchematron());
// Test with variable and function resolver
final MapBasedXPathVariableResolver aVarResolver = new MapBasedXPathVariableResolver();
aVarResolver.addUniqueVariable("title-element", "title");
final MapBasedXPathFunctionResolver aFunctionResolver = new MapBasedXPathFunctionResolver();
aFunctionResolver.addUniqueFunction("http://helger.com/schematron/test", "my-count", 1, args -> {
final List<?> aArg = (List<?>) args.get(0);
return Integer.valueOf(aArg.size());
});
final IXPathConfig aXPathConfig = new XPathConfigBuilder().setXPathVariableResolver(aVarResolver).setXPathFunctionResolver(aFunctionResolver).build();
final Document aTestDoc = DOMReader.readXMLDOM("<?xml version='1.0'?><chapter><title /><para>First para</para><para>Second para</para></chapter>");
final SchematronOutputType aOT = SchematronResourcePure.fromString(sTest, StandardCharsets.UTF_8).setXPathConfig(aXPathConfig).applySchematronValidationToSVRL(aTestDoc, null);
assertNotNull(aOT);
assertEquals(0, SVRLHelper.getAllFailedAssertions(aOT).size());
assertEquals(1, SVRLHelper.getAllSuccessfulReports(aOT).size());
// Note: the text contains all whitespaces!
assertEquals("\n 2 paragraphs found".trim(), SVRLHelper.getAllSuccessfulReports(aOT).get(0).getText());
}
use of com.helger.schematron.svrl.jaxb.SchematronOutputType in project ph-schematron by phax.
the class Issue099Test method _validateAndProduceSVRL.
private static void _validateAndProduceSVRL(@Nonnull final File aSchematron, @Nonnull final File aXML) throws Exception {
SchematronDebug.setSaveIntermediateXSLTFiles(true);
final StopWatch aSW = StopWatch.createdStarted();
LOGGER.info("Start");
final ISchematronResource aSCH = SchematronResourcePure.fromFile(aSchematron);
if (aSCH instanceof SchematronResourcePure)
((SchematronResourcePure) aSCH).setCustomValidationHandler(new LoggingPSValidationHandler());
// Perform validation
final SchematronOutputType aSVRL = aSCH.applySchematronValidationToSVRL(new FileSystemResource(aXML));
assertNotNull(aSVRL);
aSW.stop();
LOGGER.info("Took " + aSW.getDuration());
LOGGER.info("SVRL:\n" + new SVRLMarshaller().getAsString(aSVRL));
assertTrue(SVRLHelper.getAllFailedAssertionsAndSuccessfulReports(aSVRL).isEmpty());
}
Aggregations