use of com.helger.schematron.pure.model.PSSchema in project ph-schematron by phax.
the class PSReaderTest method testReadAll.
@Test
public void testReadAll() throws Exception {
for (final IReadableResource aRes : SchematronTestHelper.getAllValidSchematronFiles()) {
final PSReader aReader = new PSReader(aRes);
// Parse the schema
final PSSchema aSchema1 = aReader.readSchema();
assertNotNull(aSchema1);
final CollectingPSErrorHandler aLogger = new CollectingPSErrorHandler();
assertTrue(aRes.getPath(), aSchema1.isValid(aLogger));
assertTrue(aLogger.isEmpty());
// Convert back to XML
final IMicroElement e1 = aSchema1.getAsMicroElement();
final String sXML1 = MicroWriter.getNodeAsString(e1);
// Re-read the created XML and re-create it
final PSSchema aSchema2 = aReader.readSchemaFromXML(e1);
final IMicroElement e2 = aSchema2.getAsMicroElement();
final String sXML2 = MicroWriter.getNodeAsString(e2);
// Originally created XML and re-created-written XML must match
assertEquals(sXML1, sXML2);
}
}
use of com.helger.schematron.pure.model.PSSchema in project ph-schematron by phax.
the class PSPreprocessorTest method testWithTitle.
@Test
public void testWithTitle() throws SchematronException {
final PSPreprocessor aPreprocessor = new PSPreprocessor(PSXPathQueryBinding.getInstance()).setKeepTitles(true).setKeepDiagnostics(true);
final IReadableResource aRes = new ClassPathResource("test-sch/example-3-5.sch");
final IMicroDocument aDoc = SchematronHelper.getWithResolvedSchematronIncludes(aRes);
final PSReader aReader = new PSReader(aRes);
final PSSchema aSchema = aReader.readSchemaFromXML(aDoc.getDocumentElement());
final PSSchema aPreprocessedSchema = aPreprocessor.getAsPreprocessedSchema(aSchema);
assertNotNull(aPreprocessedSchema);
assertTrue(aPreprocessedSchema.isValid(new DoNothingPSErrorHandler()));
// Because titles are not in minimal mode
assertFalse(aPreprocessedSchema.isMinimal());
}
use of com.helger.schematron.pure.model.PSSchema in project ph-schematron by phax.
the class PSPreprocessorTest method testBasic.
@Test
public void testBasic() throws Exception {
final PSPreprocessor aPreprocessor = new PSPreprocessor(PSXPathQueryBinding.getInstance());
for (final IReadableResource aRes : SchematronTestHelper.getAllValidSchematronFiles()) {
// Resolve all includes
final IMicroDocument aDoc = SchematronHelper.getWithResolvedSchematronIncludes(aRes);
assertNotNull(aDoc);
// Read to domain object
final PSReader aReader = new PSReader(aRes);
final PSSchema aSchema = aReader.readSchemaFromXML(aDoc.getDocumentElement());
assertNotNull(aSchema);
// Ensure the schema is valid
final CollectingPSErrorHandler aErrHdl = new CollectingPSErrorHandler();
assertTrue(aRes.getPath(), aSchema.isValid(aErrHdl));
assertTrue(aErrHdl.isEmpty());
// Convert to minified schema if not-yet minimal
final PSSchema aPreprocessedSchema = aPreprocessor.getAsMinimalSchema(aSchema);
assertNotNull(aPreprocessedSchema);
if (false) {
final String sXML = MicroWriter.getNodeAsString(aPreprocessedSchema.getAsMicroElement());
SimpleFileIO.writeFile(new File("test-minified", FilenameHelper.getWithoutPath(aRes.getPath()) + ".min-pure.sch"), sXML, XMLWriterSettings.DEFAULT_XML_CHARSET_OBJ);
}
// Ensure it is still valid and minimal
assertTrue(aRes.getPath(), aPreprocessedSchema.isValid(aErrHdl));
assertTrue(aRes.getPath(), aPreprocessedSchema.isMinimal());
}
}
use of com.helger.schematron.pure.model.PSSchema in project ph-schematron by phax.
the class DocumentationExamples method readModifyAndWrite.
public static boolean readModifyAndWrite(@Nonnull final File aSchematronFile) throws Exception {
final PSSchema aSchema = new PSReader(new FileSystemResource(aSchematronFile)).readSchema();
final PSTitle aTitle = new PSTitle();
aTitle.addText("Created by ph-schematron");
aSchema.setTitle(aTitle);
return MicroWriter.writeToFile(aSchema.getAsMicroElement(), aSchematronFile).isSuccess();
}
use of com.helger.schematron.pure.model.PSSchema in project ph-schematron by phax.
the class PSXPathBoundSchemaTest method testBindAllValidSchematrons.
@Test
public void testBindAllValidSchematrons() throws SchematronException {
for (final IReadableResource aRes : SchematronTestHelper.getAllValidSchematronFiles()) {
// Parse the schema
final PSSchema aSchema = new PSReader(aRes).readSchema();
assertNotNull(aSchema);
CommonsTestHelper.testToStringImplementation(aSchema);
final CollectingPSErrorHandler aLogger = new CollectingPSErrorHandler();
assertTrue(aRes.getPath(), aSchema.isValid(aLogger));
assertTrue(aLogger.isEmpty());
// Create a compiled schema
final String sPhaseID = null;
final IPSErrorHandler aErrorHandler = null;
final IPSBoundSchema aBoundSchema = PSXPathQueryBinding.getInstance().bind(aSchema, sPhaseID, aErrorHandler);
assertNotNull(aBoundSchema);
}
}
Aggregations