Search in sources :

Example 16 with IReadableResource

use of com.helger.commons.io.resource.IReadableResource in project ph-css by phax.

the class Issue22Test method testIssue.

@Test
public void testIssue() {
    // Multiple errors contained
    final IReadableResource aRes = new ClassPathResource("testfiles/css30/good/issue22.css");
    assertTrue(aRes.exists());
    final CascadingStyleSheet aCSS = CSSReader.readFromStream(aRes, new CSSReaderSettings().setFallbackCharset(StandardCharsets.UTF_8).setCustomErrorHandler(new LoggingCSSParseErrorHandler()));
    assertNotNull(aCSS);
    if (false)
        System.out.println(new CSSWriter(ECSSVersion.CSS30).getCSSAsString(aCSS));
}
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)

Example 17 with IReadableResource

use of com.helger.commons.io.resource.IReadableResource in project ph-css by phax.

the class Issue26Test method testIssue.

@Test
public void testIssue() {
    final IReadableResource aRes = new ClassPathResource("testfiles/css30/bad_but_browsercompliant/issue26.css");
    assertTrue(aRes.exists());
    final CascadingStyleSheet aCSS = CSSReader.readFromStream(aRes, new CSSReaderSettings().setFallbackCharset(StandardCharsets.UTF_8).setBrowserCompliantMode(true).setCustomErrorHandler(new LoggingCSSParseErrorHandler()));
    assertNotNull(aCSS);
    if (false)
        System.out.println(new CSSWriter().getCSSAsString(aCSS));
}
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)

Example 18 with IReadableResource

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

the class SchematronValidatorTest method testSchematron.

@Test
public void testSchematron() {
    // Check all documents
    for (final IReadableResource aRes : SchematronTestHelper.getAllValidSchematronFiles()) {
        final IMicroDocument aDoc = SchematronHelper.getWithResolvedSchematronIncludes(aRes);
        final boolean bIsValid = SchematronValidator.isValidSchematron(aDoc);
        assertTrue(aRes.getPath(), bIsValid);
    }
}
Also used : IReadableResource(com.helger.commons.io.resource.IReadableResource) IMicroDocument(com.helger.xml.microdom.IMicroDocument) Test(org.junit.Test)

Example 19 with IReadableResource

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

the class SchematronResourcePure method createBoundSchema.

@Nonnull
protected IPSBoundSchema createBoundSchema() {
    final IReadableResource aResource = getResource();
    final IPSErrorHandler aErrorHandler = getErrorHandler();
    final PSBoundSchemaCacheKey aCacheKey = new PSBoundSchemaCacheKey(aResource, getPhase(), aErrorHandler, getVariableResolver(), getFunctionResolver(), getEntityResolver());
    if (aResource instanceof AbstractMemoryReadableResource || !isUseCache()) {
        // No need to cache anything for memory resources
        try {
            return aCacheKey.createBoundSchema();
        } catch (final SchematronException ex) {
            // Convert to runtime exception
            throw new IllegalStateException("Failed to bind Schematron", ex);
        }
    }
    // happens
    return PSBoundSchemaCache.getInstance().getFromCache(aCacheKey);
}
Also used : PSBoundSchemaCacheKey(com.helger.schematron.pure.bound.PSBoundSchemaCacheKey) AbstractMemoryReadableResource(com.helger.commons.io.resource.inmemory.AbstractMemoryReadableResource) SchematronException(com.helger.schematron.SchematronException) IPSErrorHandler(com.helger.schematron.pure.errorhandler.IPSErrorHandler) IReadableResource(com.helger.commons.io.resource.IReadableResource) Nonnull(javax.annotation.Nonnull)

Example 20 with IReadableResource

use of com.helger.commons.io.resource.IReadableResource 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);
    }
}
Also used : IMicroElement(com.helger.xml.microdom.IMicroElement) IReadableResource(com.helger.commons.io.resource.IReadableResource) PSSchema(com.helger.schematron.pure.model.PSSchema) CollectingPSErrorHandler(com.helger.schematron.pure.errorhandler.CollectingPSErrorHandler) Test(org.junit.Test)

Aggregations

IReadableResource (com.helger.commons.io.resource.IReadableResource)37 Test (org.junit.Test)25 ClassPathResource (com.helger.commons.io.resource.ClassPathResource)18 CascadingStyleSheet (com.helger.css.decl.CascadingStyleSheet)12 LoggingCSSParseErrorHandler (com.helger.css.reader.errorhandler.LoggingCSSParseErrorHandler)12 SchematronOutputType (org.oclc.purl.dsdl.svrl.SchematronOutputType)11 SchematronResourcePure (com.helger.schematron.pure.SchematronResourcePure)9 FileSystemResource (com.helger.commons.io.resource.FileSystemResource)8 CSSWriter (com.helger.css.writer.CSSWriter)8 PSSchema (com.helger.schematron.pure.model.PSSchema)7 SVRLMarshaller (com.helger.schematron.svrl.SVRLMarshaller)7 CSSReaderSettings (com.helger.css.reader.CSSReaderSettings)6 AbstractSchematronResource (com.helger.schematron.AbstractSchematronResource)6 IMicroDocument (com.helger.xml.microdom.IMicroDocument)6 CollectingPSErrorHandler (com.helger.schematron.pure.errorhandler.CollectingPSErrorHandler)5 PSReader (com.helger.schematron.pure.exchange.PSReader)5 IPSErrorHandler (com.helger.schematron.pure.errorhandler.IPSErrorHandler)4 IMicroElement (com.helger.xml.microdom.IMicroElement)3 File (java.io.File)3 Nonnull (javax.annotation.Nonnull)3