use of com.helger.schematron.svrl.jaxb.SchematronOutputType in project ph-schematron by phax.
the class Issue044Test method validateAndProduceSVRL.
public static void validateAndProduceSVRL(@Nonnull final File aSchematron, final File aXML) throws Exception {
// SchematronResourcePure fails!
ISchematronResource aSCH = SchematronResourcePure.fromFile(aSchematron);
// Parsing Schematron works!
aSCH = SchematronResourceSCH.fromFile(aSchematron);
// Perform validation
final SchematronOutputType aSVRL = aSCH.applySchematronValidationToSVRL(new FileSystemResource(aXML));
assertNotNull(aSVRL);
if (false)
System.out.println(new SVRLMarshaller().getAsString(aSVRL));
assertEquals(3, SVRLHelper.getAllFailedAssertionsAndSuccessfulReports(aSVRL).size());
}
use of com.helger.schematron.svrl.jaxb.SchematronOutputType in project ph-schematron by phax.
the class Issue064Test method validateAndProduceSVRL.
public static void validateAndProduceSVRL(@Nonnull final File aSchematron, final File aXML) throws Exception {
final SchematronResourcePure aSCH = SchematronResourcePure.fromFile(aSchematron);
aSCH.setErrorHandler(new LoggingPSErrorHandler());
// Perform validation
final SchematronOutputType aSVRL = aSCH.applySchematronValidationToSVRL(new FileSystemResource(aXML));
assertNotNull(aSVRL);
}
use of com.helger.schematron.svrl.jaxb.SchematronOutputType in project ph-schematron by phax.
the class Issue088Test method _validateAndProduceSVRL.
private static void _validateAndProduceSVRL(@Nonnull final File aSchematron, @Nonnull final File aXML) throws Exception {
final SchematronResourcePure aSCH = SchematronResourcePure.fromFile(aSchematron);
aSCH.setCustomValidationHandler(new LoggingPSValidationHandler());
// Perform validation
final SchematronOutputType aSVRL = aSCH.applySchematronValidationToSVRL(new FileSystemResource(aXML));
assertNotNull(aSVRL);
final String sSVRL = new SVRLMarshaller().getAsString(aSVRL);
assertNotNull(sSVRL);
if (false)
LOGGER.info("SVRL:\n" + sSVRL);
assertTrue(SVRLHelper.getAllFailedAssertionsAndSuccessfulReports(aSVRL).isEmpty());
}
use of com.helger.schematron.svrl.jaxb.SchematronOutputType in project ph-schematron by phax.
the class Issue20140523Test method validateAndProduceSVRL.
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 pure = new SchematronResourcePure(aSchematron);
final SchematronOutputType aSVRL = pure.applySchematronValidationToSVRL(anXMLSource);
assertNotNull(aSVRL);
if (false)
System.out.println(new SVRLMarshaller().getAsString(aSVRL));
}
use of com.helger.schematron.svrl.jaxb.SchematronOutputType in project mustangproject by ZUGFeRD.
the class XMLValidator method validateSchematron.
/**
* validate using a xslt file generated from a schematron in the build preparation of this software
* @param xml the xml to be checked
* @param xsltFilename the filename of the intermediate XSLT file
* @param section the error type code, if one arises
* @param severity how serious a error should be treated - may only be notice
* @throws IrrecoverableValidationError if anything happened that prevents further checks
*/
public void validateSchematron(String xml, String xsltFilename, int section, ESeverity severity) throws IrrecoverableValidationError {
ISchematronResource aResSCH = null;
aResSCH = SchematronResourceXSLT.fromClassPath(xsltFilename);
if (aResSCH != null) {
if (!aResSCH.isValidSchematron()) {
throw new IllegalArgumentException(xsltFilename + " is invalid Schematron!");
}
final SchematronOutputType sout;
try {
sout = aResSCH.applySchematronValidationToSVRL(new StreamSource(new StringReader(xml)));
} catch (final Exception e) {
throw new IrrecoverableValidationError(e.getMessage());
}
final List<Object> failedAsserts = sout.getActivePatternAndFiredRuleAndFailedAssert();
if (failedAsserts.size() > 0) {
for (final Object object : failedAsserts) {
if (object instanceof FailedAssert) {
final FailedAssert failedAssert = (FailedAssert) object;
LOGGER.info("FailedAssert ", failedAssert);
context.addResultItem(new ValidationResultItem(severity, SVRLHelper.getAsString(failedAssert.getText()) + " (From " + xsltFilename + ")").setLocation(failedAssert.getLocation()).setCriterion(failedAssert.getTest()).setSection(section).setPart(EPart.fx));
failedRules++;
} else if (object instanceof FiredRule) {
firedRules++;
}
}
}
if (firedRules == 0) {
context.addResultItem(new ValidationResultItem(ESeverity.error, "No rules matched, XML to minimal?").setSection(26).setPart(EPart.fx));
}
// for (String currentString : sout.getText()) {
// schematronValidationString += "<output>" + currentString + "</output>";
// }
// schematronValidationString += new SVRLMarshaller ().getAsString (sout);
// returns the complete SVRL
}
}
Aggregations