use of com.helger.schematron.pure.SchematronResourcePure in project ph-schematron by phax.
the class Schematron method execute.
@Override
public void execute() throws BuildException {
boolean bCanRun = false;
if (m_aSchematronFile == null)
_error("No Schematron file specified!");
else if (m_aSchematronFile.exists() && !m_aSchematronFile.isFile())
_error("The specified Schematron file " + m_aSchematronFile + " is not a file!");
else if (m_eSchematronProcessingEngine == null)
_error("An invalid Schematron processing instance is specified! Only one of the following values is allowed: " + StringHelper.getImplodedMapped(", ", ESchematronMode.values(), x -> "'" + x.getID() + "'"));
else if (m_aResCollections.isEmpty())
_error("No XML resources to be validated specified! Add e.g. a <fileset> element.");
else if (m_aSvrlDirectory != null && !m_aSvrlDirectory.exists() && !m_aSvrlDirectory.mkdirs())
_error("Failed to create the SVRL directory " + m_aSvrlDirectory);
else
bCanRun = true;
if (bCanRun) {
// 1. Parse Schematron file
final Locale aDisplayLocale = Locale.US;
ISchematronResource aSch = null;
IErrorList aSCHErrors = null;
switch(m_eSchematronProcessingEngine) {
case PURE:
{
// pure
final CollectingPSErrorHandler aErrorHdl = new CollectingPSErrorHandler();
final SchematronResourcePure aRealSCH = new SchematronResourcePure(new FileSystemResource(m_aSchematronFile));
aRealSCH.setPhase(m_sPhaseName);
aRealSCH.setErrorHandler(aErrorHdl);
aRealSCH.setEntityResolver(getEntityResolver());
aRealSCH.validateCompletely();
aSch = aRealSCH;
aSCHErrors = aErrorHdl.getAllErrors();
break;
}
case SCHEMATRON:
{
// SCH
final CollectingTransformErrorListener aErrorHdl = new CollectingTransformErrorListener();
final SchematronResourceSCH aRealSCH = new SchematronResourceSCH(new FileSystemResource(m_aSchematronFile));
aRealSCH.setPhase(m_sPhaseName);
aRealSCH.setLanguageCode(m_sLanguageCode);
aRealSCH.setErrorListener(aErrorHdl);
aRealSCH.setURIResolver(getURIResolver());
aRealSCH.setEntityResolver(getEntityResolver());
aRealSCH.isValidSchematron();
aSch = aRealSCH;
aSCHErrors = aErrorHdl.getErrorList();
break;
}
case XSLT:
{
// SCH
final CollectingTransformErrorListener aErrorHdl = new CollectingTransformErrorListener();
final SchematronResourceXSLT aRealSCH = new SchematronResourceXSLT(new FileSystemResource(m_aSchematronFile));
// phase and language are ignored because this was decided when the
// XSLT
// was created
aRealSCH.setErrorListener(aErrorHdl);
aRealSCH.setURIResolver(getURIResolver());
aRealSCH.setEntityResolver(getEntityResolver());
aRealSCH.isValidSchematron();
aSch = aRealSCH;
aSCHErrors = aErrorHdl.getErrorList();
break;
}
default:
_error("No handler for processing engine '" + m_eSchematronProcessingEngine + "'");
break;
}
if (aSCHErrors != null) {
// Error validating the Schematrons!!
boolean bAnyParsingError = false;
for (final IError aError : aSCHErrors) if (aError.getErrorLevel().isGE(EErrorLevel.ERROR)) {
log("Error in Schematron: " + aError.getAsString(aDisplayLocale), Project.MSG_ERR);
bAnyParsingError = true;
} else if (aError.getErrorLevel().isGE(EErrorLevel.WARN))
log("Warning in Schematron: " + aError.getAsString(aDisplayLocale), Project.MSG_WARN);
if (bAnyParsingError)
_error("The provided Schematron file contains errors. See log for details.");
else {
log("Successfully parsed Schematron file '" + m_aSchematronFile.getPath() + "'", Project.MSG_INFO);
// 2. for all XML files that match the pattern
_performValidation(aSch, m_aResCollections, m_aSvrlDirectory, m_bExpectSuccess);
}
}
}
}
use of com.helger.schematron.pure.SchematronResourcePure in project ph-schematron by phax.
the class Issue11Test 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());
assertTrue(aSCH.isValidSchematron());
// 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.pure.SchematronResourcePure in project ph-schematron by phax.
the class Issue36Test method testNestedExtends.
@Test
public void testNestedExtends() throws Exception {
final SchematronResourcePure aResPure = SchematronResourcePure.fromFile("src/test/resources/issues/github36/test2.sch");
aResPure.setErrorHandler(new LoggingPSErrorHandler());
final SchematronOutputType aSOT = aResPure.applySchematronValidationToSVRL(new FileSystemResource("src/test/resources/issues/github36/test.xml"));
assertNotNull(aSOT);
assertFalse(SVRLHelper.getAllFailedAssertions(aSOT).isEmpty());
}
use of com.helger.schematron.pure.SchematronResourcePure in project ph-schematron by phax.
the class Issue36Test method test.
@Test
public void test() throws Exception {
final SchematronResourcePure aResPure = SchematronResourcePure.fromFile("src/test/resources/issues/github36/test.sch");
aResPure.setErrorHandler(new LoggingPSErrorHandler());
final SchematronOutputType aSOT = aResPure.applySchematronValidationToSVRL(new FileSystemResource("src/test/resources/issues/github36/test.xml"));
assertNotNull(aSOT);
assertFalse(SVRLHelper.getAllFailedAssertions(aSOT).isEmpty());
}
use of com.helger.schematron.pure.SchematronResourcePure in project ph-schematron by phax.
the class Issue20150128Test method testEq.
@Test
public void testEq() throws Exception {
final String sTest2 = "<?xml version='1.0' encoding='iso-8859-1'?>\n" + "<schema xmlns='http://purl.oclc.org/dsdl/schematron'>\n" + " <ns prefix='functx' uri='http://www.functx.com' />\n" + " <pattern >\n" + " <title>A very simple pattern with a title</title>\n" + " <rule context='chapter'>\n" + " <assert test='aaa eq 1'>aaa equals 1></assert>\n" + " </rule>\n" + " </pattern>\n" + "\n" + "</schema>";
final CollectingPSErrorHandler aErrorHandler = new CollectingPSErrorHandler();
final MapBasedXPathFunctionResolver aFunctionResolver = new XQueryAsXPathFunctionConverter().loadXQuery(ClassPathResource.getInputStream("xquery/functx-1.0-nodoc-2007-01.xq"));
final SchematronResourcePure resource = SchematronResourcePure.fromString(sTest2, StandardCharsets.ISO_8859_1);
resource.setErrorHandler(aErrorHandler);
resource.setFunctionResolver(aFunctionResolver);
assertTrue(resource.isValidSchematron());
assertEquals(1, aErrorHandler.getErrorList().size());
}
Aggregations