use of com.helger.schematron.sch.SchematronResourceSCH in project ph-schematron by phax.
the class Issue085Test method validateAndProduceSVRL.
public static void validateAndProduceSVRL(@Nonnull final File aSchematron, final File aXML) throws Exception {
final SchematronResourceSCH aSCH = SchematronResourceSCH.fromFile(aSchematron);
if (false)
System.out.println(XMLWriter.getNodeAsString(aSCH.getXSLTProvider().getXSLTDocument()));
// 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.sch.SchematronResourceSCH in project ph-schematron by phax.
the class Issue126Test method _validateAndProduceSVRL.
private static void _validateAndProduceSVRL(@Nonnull final File aSchematron, @Nonnull final File aXML) throws Exception {
final SchematronResourceSCH aSCH = SchematronResourceSCH.fromFile(aSchematron);
aSCH.setAllowForeignElements(true);
// Perform validation
final SchematronOutputType aSVRL = aSCH.applySchematronValidationToSVRL(new FileSystemResource(aXML));
assertNotNull(aSVRL);
final String sSVRL = new SVRLMarshaller().getAsString(aSVRL);
assertNotNull(sSVRL);
if (true)
LOGGER.info("SVRL:\n" + sSVRL);
assertEquals(1, SVRLHelper.getAllFailedAssertionsAndSuccessfulReports(aSVRL).size());
}
use of com.helger.schematron.sch.SchematronResourceSCH in project ph-schematron by phax.
the class IssueSO32784781Test method testBasic.
@Test
public void testBasic() {
final String sSCH = "<schema xmlns=\"http://purl.oclc.org/dsdl/schematron\">\r\n" + " <ns prefix=\"m\" uri=\"http://www.ociweb.com/movies\"/>\r\n" + " <pattern name=\"all\">\r\n" + " <rule context=\"m:actor\">\r\n" + " <report test=\"@role=preceding-sibling::m:actor/@role\"\r\n" + " diagnostics=\"duplicateActorRole\">\r\n" + " Duplicate role!\r\n" + " </report>\r\n" + " </rule>\r\n" + " </pattern>\r\n" + " <diagnostics>\r\n" + " <diagnostic id=\"duplicateActorRole\">\r\n" + " More than one actor plays the role<value-of select=\"@role\"/>.\r\n" + " A duplicate is named<value-of select=\"@name\"/>.\r\n" + " </diagnostic>\r\n" + " </diagnostics>\r\n" + "</schema>";
final ISchematronResource isr = new SchematronResourceSCH(new ReadableResourceString(sSCH, StandardCharsets.UTF_8));
assertTrue(isr.isValidSchematron());
}
use of com.helger.schematron.sch.SchematronResourceSCH in project phive by phax.
the class ValidationExecutorSchematron method _createSchematronResource.
@Nonnull
private AbstractSchematronResource _createSchematronResource(@Nullable final Locale aLocale, @Nonnull final ErrorList aErrorList, @Nonnull final Consumer<ESchematronOutput> aSpecialOutputHdl) {
final IValidationArtefact aArtefact = getValidationArtefact();
// get the Schematron resource to be used for this validation artefact
final IReadableResource aSCHRes = aArtefact.getRuleResource();
final IValidationType aVT = aArtefact.getValidationArtefactType();
if (aVT == EValidationType.SCHEMATRON_PURE) {
final SchematronResourcePure aPureSCH = new SchematronResourcePure(aSCHRes);
aPureSCH.setErrorHandler(new WrappedCollectingPSErrorHandler(aErrorList));
// consecutive calls!
return aPureSCH;
}
if (aVT == EValidationType.SCHEMATRON_SCH) {
final SchematronResourceSCH aSCHSCH = new SchematronResourceSCH(aSCHRes);
aSCHSCH.setErrorListener(new WrappedCollectingTransformErrorListener(aErrorList));
if (aLocale != null && StringHelper.hasText(aLocale.getLanguage()))
aSCHSCH.setLanguageCode(aLocale.getLanguage());
return aSCHSCH;
}
if (aVT == EValidationType.SCHEMATRON_SCHXSLT) {
final SchematronResourceSchXslt_XSLT2 aSCHSCH = new SchematronResourceSchXslt_XSLT2(aSCHRes);
aSCHSCH.setErrorListener(new WrappedCollectingTransformErrorListener(aErrorList));
if (aLocale != null && StringHelper.hasText(aLocale.getLanguage()))
aSCHSCH.setLanguageCode(aLocale.getLanguage());
return aSCHSCH;
}
if (aVT == EValidationType.SCHEMATRON_XSLT) {
final SchematronResourceXSLT aSCHXSLT = new SchematronResourceXSLT(aSCHRes);
aSCHXSLT.setErrorListener(new WrappedCollectingTransformErrorListener(aErrorList));
return aSCHXSLT;
}
if (aVT == EValidationType.SCHEMATRON_OIOUBL) {
final SchematronResourceXSLT aSCHXSLT = new SchematronResourceXSLT(aSCHRes);
aSCHXSLT.setErrorListener(new WrappedCollectingTransformErrorListener(aErrorList));
// Special output layout
aSpecialOutputHdl.accept(ESchematronOutput.OIOUBL);
return aSCHXSLT;
}
throw new IllegalStateException("Unsupported Schematron validation type: " + aVT);
}
use of com.helger.schematron.sch.SchematronResourceSCH 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));
}
Aggregations