Search in sources :

Example 26 with ClassPathResource

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);
}
Also used : Transform(net.sf.saxon.Transform) File(java.io.File) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 27 with ClassPathResource

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;
}
Also used : CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) ClassPathHelper(com.helger.commons.lang.ClassPathHelper) StringHelper(com.helger.commons.string.StringHelper) IReadableResource(com.helger.commons.io.resource.IReadableResource) IMicroDocument(com.helger.xml.microdom.IMicroDocument) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) File(java.io.File) ValueEnforcer(com.helger.commons.ValueEnforcer) FileSystemRecursiveIterator(com.helger.commons.io.file.FileSystemRecursiveIterator) ICommonsList(com.helger.commons.collection.impl.ICommonsList) Nonempty(com.helger.commons.annotation.Nonempty) IMicroElement(com.helger.xml.microdom.IMicroElement) MicroReader(com.helger.xml.microdom.serialize.MicroReader) Nonnull(javax.annotation.Nonnull) FileSystemRecursiveIterator(com.helger.commons.io.file.FileSystemRecursiveIterator) IMicroElement(com.helger.xml.microdom.IMicroElement) IMicroDocument(com.helger.xml.microdom.IMicroDocument) File(java.io.File) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) Nonnull(javax.annotation.Nonnull)

Example 28 with ClassPathResource

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());
    }
}
Also used : Validator(javax.xml.validation.Validator) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) SAXException(org.xml.sax.SAXException) Test(org.junit.Test)

Example 29 with ClassPathResource

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);
}
Also used : SchematronOutputType(org.oclc.purl.dsdl.svrl.SchematronOutputType) ISchematronResource(com.helger.schematron.ISchematronResource) Document(org.w3c.dom.Document) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) Test(org.junit.Test)

Example 30 with ClassPathResource

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());
}
Also used : CascadingStyleSheet(com.helger.css.decl.CascadingStyleSheet) IReadableResource(com.helger.commons.io.resource.IReadableResource) CSSWriter(com.helger.css.writer.CSSWriter) CSSReaderSettings(com.helger.css.reader.CSSReaderSettings) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) LoggingCSSParseErrorHandler(com.helger.css.reader.errorhandler.LoggingCSSParseErrorHandler) Test(org.junit.Test)

Aggregations

ClassPathResource (com.helger.commons.io.resource.ClassPathResource)35 Test (org.junit.Test)33 IReadableResource (com.helger.commons.io.resource.IReadableResource)18 SchematronOutputType (org.oclc.purl.dsdl.svrl.SchematronOutputType)14 CascadingStyleSheet (com.helger.css.decl.CascadingStyleSheet)13 LoggingCSSParseErrorHandler (com.helger.css.reader.errorhandler.LoggingCSSParseErrorHandler)12 CSSWriter (com.helger.css.writer.CSSWriter)8 CSSReaderSettings (com.helger.css.reader.CSSReaderSettings)6 Document (org.w3c.dom.Document)6 ISchematronResource (com.helger.schematron.ISchematronResource)4 SchematronResourcePure (com.helger.schematron.pure.SchematronResourcePure)3 IMicroDocument (com.helger.xml.microdom.IMicroDocument)3 File (java.io.File)3 Ignore (org.junit.Ignore)3 PSReader (com.helger.schematron.pure.exchange.PSReader)2 PSSchema (com.helger.schematron.pure.model.PSSchema)2 SVRLFailedAssert (com.helger.schematron.svrl.SVRLFailedAssert)2 SVRLMarshaller (com.helger.schematron.svrl.SVRLMarshaller)2 ValueEnforcer (com.helger.commons.ValueEnforcer)1 Nonempty (com.helger.commons.annotation.Nonempty)1