Search in sources :

Example 31 with ClassPathResource

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

the class Issue24Test method testIssue.

@Test
public void testIssue() {
    final IReadableResource aRes = new ClassPathResource("testfiles/css30/bad_but_browsercompliant/issue24.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 32 with ClassPathResource

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

the class Issue4Test method testIssue4.

@Test
public void testIssue4() {
    final IReadableResource aRes = new ClassPathResource("testfiles/css30/good/issue4.css");
    assertTrue(aRes.exists());
    final CascadingStyleSheet aCSS = CSSReader.readFromStream(aRes, StandardCharsets.UTF_8, ECSSVersion.CSS30, 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) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) LoggingCSSParseErrorHandler(com.helger.css.reader.errorhandler.LoggingCSSParseErrorHandler) Test(org.junit.Test)

Example 33 with ClassPathResource

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

the class Issue8Test method testIssue8.

@Test
public void testIssue8() {
    final IReadableResource aRes = new ClassPathResource("testfiles/css30/good/issue8.css");
    assertTrue(aRes.exists());
    final CascadingStyleSheet aCSS = CSSReader.readFromStream(aRes, StandardCharsets.UTF_8, ECSSVersion.CSS30, new LoggingCSSParseErrorHandler());
    assertNotNull(aCSS);
    assertEquals(1, aCSS.getStyleRuleCount());
    final CSSStyleRule aStyleRule = aCSS.getStyleRuleAtIndex(0);
    assertNotNull(aStyleRule);
    assertEquals(4, aStyleRule.getDeclarationCount());
}
Also used : CascadingStyleSheet(com.helger.css.decl.CascadingStyleSheet) CSSStyleRule(com.helger.css.decl.CSSStyleRule) IReadableResource(com.helger.commons.io.resource.IReadableResource) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) LoggingCSSParseErrorHandler(com.helger.css.reader.errorhandler.LoggingCSSParseErrorHandler) Test(org.junit.Test)

Example 34 with ClassPathResource

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

the class IssueGC18Test method testIssue18.

@Test
public void testIssue18() {
    final IReadableResource aRes = new ClassPathResource("testfiles/css30/good/issue-gc-18.css");
    assertTrue(aRes.exists());
    final CascadingStyleSheet aCSS = CSSReader.readFromStream(aRes, StandardCharsets.UTF_8, ECSSVersion.CSS30, 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) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) LoggingCSSParseErrorHandler(com.helger.css.reader.errorhandler.LoggingCSSParseErrorHandler) Test(org.junit.Test)

Example 35 with ClassPathResource

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

the class CSSWriterFuncTest method testCompressCSS_Size.

@Test
public void testCompressCSS_Size() {
    final CascadingStyleSheet aCSS = CSSReader.readFromStream(new ClassPathResource("/testfiles/css21/good/phloc/test/content.css"), StandardCharsets.UTF_8, ECSSVersion.CSS30);
    assertNotNull(aCSS);
    // Only whitespace optimization
    final CSSWriterSettings aSettings = new CSSWriterSettings(ECSSVersion.CSS21, true);
    String sContent = new CSSWriter(aSettings).getCSSAsString(aCSS);
    assertEquals(2846, sContent.length());
    // Also remove empty declarations
    aSettings.setRemoveUnnecessaryCode(true);
    sContent = new CSSWriter(aSettings).getCSSAsString(aCSS);
    assertEquals(2839, sContent.length());
}
Also used : CascadingStyleSheet(com.helger.css.decl.CascadingStyleSheet) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) 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