use of com.helger.commons.io.resource.ClassPathResource in project ph-schematron by phax.
the class XlstSchematronFuncTest method testXsltSchematron.
@Test
@Ignore("Does not work on the commandline, because the XSLT resources are only available in the classpath")
public void testXsltSchematron() throws IOException {
final Transform saxonTransform = new Transform();
final String sourcePath = new File("src/test/resources/schematron/check-classifications.sch").getCanonicalPath();
final String step1Path = new ClassPathResource(SchematronProviderXSLTFromSCH.XSLT2_STEP1).getAsURL().toExternalForm();
final String step2Path = new ClassPathResource(SchematronProviderXSLTFromSCH.XSLT2_STEP2).getAsURL().toExternalForm();
final String step3Path = new ClassPathResource(SchematronProviderXSLTFromSCH.XSLT2_STEP3).getAsURL().toExternalForm();
final String outputPath = new File("target/test/schematron-via-xslt/").getCanonicalPath();
final String[] step1Commands = { "-xsl:" + step1Path, "-s:" + sourcePath, "-o:" + outputPath + "/step1.sch" };
final String[] step2Commands = { "-xsl:" + step2Path, "-s:" + outputPath + "/step1.sch", "-o:" + outputPath + "/step2.sch" };
final String[] step3Commands = { "-xsl:" + step3Path, "-s:" + outputPath + "/step2.sch", "-o:" + outputPath + "/check-classifications.xslt" };
saxonTransform.doTransform(step1Commands, TEST_XSLT_SCHEMATRON);
saxonTransform.doTransform(step2Commands, TEST_XSLT_SCHEMATRON);
saxonTransform.doTransform(step3Commands, TEST_XSLT_SCHEMATRON);
}
use of com.helger.commons.io.resource.ClassPathResource in project ph-schematron by phax.
the class SchematronTestHelper method _readDI.
@Nonnull
private static ICommonsList<SchematronTestFile> _readDI(@Nonnull final IReadableResource aRes) {
if (false)
ClassPathHelper.getAllClassPathEntries().forEach(x -> {
System.out.println(x);
if (new File(x).isDirectory()) {
final FileSystemRecursiveIterator it = new FileSystemRecursiveIterator(new File(x));
it.forEach(y -> System.out.println(StringHelper.getRepeated(" ", it.getLevel()) + y));
}
});
ValueEnforcer.notNull(aRes, "Resource");
ValueEnforcer.isTrue(aRes.exists(), () -> "Resource " + aRes + " does not exist!");
final ICommonsList<SchematronTestFile> ret = new CommonsArrayList<>();
final IMicroDocument aDoc = MicroReader.readMicroXML(aRes);
if (aDoc == null)
throw new IllegalArgumentException("Failed to open/parse " + aRes + " as XML");
String sLastParentDirBaseName = null;
for (final IMicroElement eItem : aDoc.getDocumentElement().getAllChildElements()) if (eItem.getTagName().equals("directory"))
sLastParentDirBaseName = eItem.getAttributeValue("basename");
else if (eItem.getTagName().equals("file"))
ret.add(new SchematronTestFile(sLastParentDirBaseName, new ClassPathResource(eItem.getAttributeValue("name")), eItem.getAttributeValue("basename")));
else
throw new IllegalArgumentException("Cannot handle " + eItem);
return ret;
}
use of com.helger.commons.io.resource.ClassPathResource in project ph-schematron by phax.
the class RelaxNGCompactSchemaCacheTest method testSVRL.
@Test
public void testSVRL() throws IOException {
// Check the document
try {
// Get a validator from the schema.
final Validator aValidator = RelaxNGCompactSchemaCache.getInstance().getValidator(new ClassPathResource("schemas/svrl-2006.rnc"));
aValidator.validate(TransformSourceFactory.create(new ClassPathResource("test-svrl/test1.svrl")));
// Success
} catch (final SAXException ex) {
fail(ex.getMessage());
}
}
use of com.helger.commons.io.resource.ClassPathResource in project ph-schematron by phax.
the class SVRLMarshallerTest method testCreate.
@Test
public void testCreate() throws Exception {
final ISchematronResource aSV = SchematronResourceSCH.fromClassPath(VALID_SCHEMATRON);
assertNotNull("Failed to parse Schematron", aSV);
final Document aDoc = aSV.applySchematronValidation(new ClassPathResource(VALID_XMLINSTANCE));
assertNotNull("Failed to parse demo XML", aDoc);
final SchematronOutputType aSO = new SVRLMarshaller().read(aDoc);
assertNotNull("Failed to parse Schematron output", aSO);
}
use of com.helger.commons.io.resource.ClassPathResource in project ph-css by phax.
the class Issue19Test method testIssue.
@Test
public void testIssue() {
// Multiple errors contained
final IReadableResource aRes = new ClassPathResource("testfiles/css30/bad_but_browsercompliant/issue19.css");
assertTrue(aRes.exists());
final CascadingStyleSheet aCSS = CSSReader.readFromStream(aRes, new CSSReaderSettings().setFallbackCharset(StandardCharsets.UTF_8).setCSSVersion(ECSSVersion.CSS30).setCustomErrorHandler(new LoggingCSSParseErrorHandler()).setBrowserCompliantMode(true));
assertNotNull(aCSS);
if (false)
System.out.println(new CSSWriter(ECSSVersion.CSS30).getCSSAsString(aCSS));
assertEquals(1, aCSS.getRuleCount());
assertEquals(1, aCSS.getStyleRuleCount());
}
Aggregations