Search in sources :

Example 6 with FileSystemResource

use of com.helger.commons.io.resource.FileSystemResource in project ph-schematron by phax.

the class DocumentationExamples method validateXMLViaPureSchematron2.

public static boolean validateXMLViaPureSchematron2(@Nonnull final File aSchematronFile, @Nonnull final File aXMLFile) throws Exception {
    // Read the schematron from file
    final PSSchema aSchema = new PSReader(new FileSystemResource(aSchematronFile)).readSchema();
    if (!aSchema.isValid(new DoNothingPSErrorHandler()))
        throw new IllegalArgumentException("Invalid Schematron!");
    // Resolve the query binding to use
    final IPSQueryBinding aQueryBinding = PSQueryBindingRegistry.getQueryBindingOfNameOrThrow(aSchema.getQueryBinding());
    // Pre-process schema
    final PSPreprocessor aPreprocessor = new PSPreprocessor(aQueryBinding);
    aPreprocessor.setKeepTitles(true);
    final PSSchema aPreprocessedSchema = aPreprocessor.getAsPreprocessedSchema(aSchema);
    // Bind the pre-processed schema
    final IPSBoundSchema aBoundSchema = aQueryBinding.bind(aPreprocessedSchema, null, null, null, null);
    // Read the XML file
    final Document aXMLNode = DOMReader.readXMLDOM(aXMLFile);
    if (aXMLNode == null)
        return false;
    // Perform the validation
    return aBoundSchema.validatePartially(aXMLNode, FileHelper.getAsURLString(aXMLFile)).isValid();
}
Also used : DoNothingPSErrorHandler(com.helger.schematron.pure.errorhandler.DoNothingPSErrorHandler) IPSQueryBinding(com.helger.schematron.pure.binding.IPSQueryBinding) IPSBoundSchema(com.helger.schematron.pure.bound.IPSBoundSchema) PSReader(com.helger.schematron.pure.exchange.PSReader) FileSystemResource(com.helger.commons.io.resource.FileSystemResource) PSPreprocessor(com.helger.schematron.pure.preprocess.PSPreprocessor) Document(org.w3c.dom.Document) PSSchema(com.helger.schematron.pure.model.PSSchema)

Example 7 with FileSystemResource

use of com.helger.commons.io.resource.FileSystemResource in project ph-schematron by phax.

the class Issue44Test 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());
}
Also used : SchematronOutputType(org.oclc.purl.dsdl.svrl.SchematronOutputType) ISchematronResource(com.helger.schematron.ISchematronResource) SVRLMarshaller(com.helger.schematron.svrl.SVRLMarshaller) FileSystemResource(com.helger.commons.io.resource.FileSystemResource)

Example 8 with FileSystemResource

use of com.helger.commons.io.resource.FileSystemResource in project ph-schematron by phax.

the class Issue48Test 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));
}
Also used : SchematronOutputType(org.oclc.purl.dsdl.svrl.SchematronOutputType) XMLWriterSettings(com.helger.xml.serialize.write.XMLWriterSettings) SchematronResourceSCH(com.helger.schematron.xslt.SchematronResourceSCH) PSWriter(com.helger.schematron.pure.exchange.PSWriter) PSWriterSettings(com.helger.schematron.pure.exchange.PSWriterSettings) ReadableResourceString(com.helger.commons.io.resource.inmemory.ReadableResourceString) SVRLMarshaller(com.helger.schematron.svrl.SVRLMarshaller) PSReader(com.helger.schematron.pure.exchange.PSReader) FileSystemResource(com.helger.commons.io.resource.FileSystemResource) ReadableResourceString(com.helger.commons.io.resource.inmemory.ReadableResourceString) PSPreprocessor(com.helger.schematron.pure.preprocess.PSPreprocessor) PSSchema(com.helger.schematron.pure.model.PSSchema)

Example 9 with FileSystemResource

use of com.helger.commons.io.resource.FileSystemResource in project ph-schematron by phax.

the class IssueGC6Test 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));
}
Also used : SchematronOutputType(org.oclc.purl.dsdl.svrl.SchematronOutputType) IReadableResource(com.helger.commons.io.resource.IReadableResource) SVRLMarshaller(com.helger.schematron.svrl.SVRLMarshaller) FileSystemResource(com.helger.commons.io.resource.FileSystemResource) AbstractSchematronResource(com.helger.schematron.AbstractSchematronResource) SchematronResourcePure(com.helger.schematron.pure.SchematronResourcePure)

Example 10 with FileSystemResource

use of com.helger.commons.io.resource.FileSystemResource in project ph-schematron by phax.

the class IssueGC7Test 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));
}
Also used : SchematronOutputType(org.oclc.purl.dsdl.svrl.SchematronOutputType) IReadableResource(com.helger.commons.io.resource.IReadableResource) SVRLMarshaller(com.helger.schematron.svrl.SVRLMarshaller) FileSystemResource(com.helger.commons.io.resource.FileSystemResource) AbstractSchematronResource(com.helger.schematron.AbstractSchematronResource) SchematronResourcePure(com.helger.schematron.pure.SchematronResourcePure)

Aggregations

FileSystemResource (com.helger.commons.io.resource.FileSystemResource)25 SchematronOutputType (org.oclc.purl.dsdl.svrl.SchematronOutputType)18 SVRLMarshaller (com.helger.schematron.svrl.SVRLMarshaller)14 SchematronResourcePure (com.helger.schematron.pure.SchematronResourcePure)13 IReadableResource (com.helger.commons.io.resource.IReadableResource)8 AbstractSchematronResource (com.helger.schematron.AbstractSchematronResource)6 SchematronResourceSCH (com.helger.schematron.xslt.SchematronResourceSCH)6 LoggingPSErrorHandler (com.helger.schematron.pure.errorhandler.LoggingPSErrorHandler)5 ISchematronResource (com.helger.schematron.ISchematronResource)4 PSReader (com.helger.schematron.pure.exchange.PSReader)4 PSSchema (com.helger.schematron.pure.model.PSSchema)4 File (java.io.File)4 Test (org.junit.Test)4 PSPreprocessor (com.helger.schematron.pure.preprocess.PSPreprocessor)3 XMLWriterSettings (com.helger.xml.serialize.write.XMLWriterSettings)3 ICommonsList (com.helger.commons.collection.impl.ICommonsList)2 IError (com.helger.commons.error.IError)2 EErrorLevel (com.helger.commons.error.level.EErrorLevel)2 IErrorList (com.helger.commons.error.list.IErrorList)2 StringHelper (com.helger.commons.string.StringHelper)2