Search in sources :

Example 1 with DoNothingCSSParseErrorHandler

use of com.helger.css.reader.errorhandler.DoNothingCSSParseErrorHandler in project ph-css by phax.

the class CSSReader30SpecialFuncTest method testReadWithBOM.

@Test
public void testReadWithBOM() {
    final String sCSSBase = "/* comment */.class{color:red}.class{color:blue}";
    for (final EUnicodeBOM eBOM : EUnicodeBOM.values()) {
        final Charset aDeterminedCharset = eBOM.getCharset();
        if (aDeterminedCharset != null) {
            final CascadingStyleSheet aCSS = CSSReader.readFromStream(new ByteArrayInputStreamProvider(ArrayHelper.getConcatenated(eBOM.getAllBytes(), sCSSBase.getBytes(aDeterminedCharset))), aDeterminedCharset, ECSSVersion.CSS30, new DoNothingCSSParseErrorHandler());
            assertNotNull("Failed to read with BOM " + eBOM, aCSS);
            assertEquals(".class{color:red}.class{color:blue}", new CSSWriter(ECSSVersion.CSS30, true).getCSSAsString(aCSS));
        }
    }
}
Also used : CascadingStyleSheet(com.helger.css.decl.CascadingStyleSheet) ByteArrayInputStreamProvider(com.helger.commons.io.streamprovider.ByteArrayInputStreamProvider) EUnicodeBOM(com.helger.commons.charset.EUnicodeBOM) DoNothingCSSParseErrorHandler(com.helger.css.reader.errorhandler.DoNothingCSSParseErrorHandler) Charset(java.nio.charset.Charset) CSSWriter(com.helger.css.writer.CSSWriter) Test(org.junit.Test)

Example 2 with DoNothingCSSParseErrorHandler

use of com.helger.css.reader.errorhandler.DoNothingCSSParseErrorHandler in project ph-css by phax.

the class Issue36Test method testIssue.

@Test
public void testIssue() {
    final String css = "@media screen and (min-width: 768px) {.section {.\r\n" + "    padding: 40px\r\n" + "}\r\n" + "\r\n" + "}";
    final CSSReaderSettings aSettings = new CSSReaderSettings().setCSSVersion(ECSSVersion.LATEST).setBrowserCompliantMode(true).setCustomErrorHandler(new DoNothingCSSParseErrorHandler());
    final CascadingStyleSheet cascadingStyleSheet = CSSReader.readFromStringStream(css, aSettings);
    final CSSWriter writer = new CSSWriter(new CSSWriterSettings(ECSSVersion.LATEST, true));
    assertEquals("@media screen and (min-width:768px){.section{}}", writer.getCSSAsString(cascadingStyleSheet));
}
Also used : CascadingStyleSheet(com.helger.css.decl.CascadingStyleSheet) CSSWriterSettings(com.helger.css.writer.CSSWriterSettings) DoNothingCSSParseErrorHandler(com.helger.css.reader.errorhandler.DoNothingCSSParseErrorHandler) CSSWriter(com.helger.css.writer.CSSWriter) CSSReaderSettings(com.helger.css.reader.CSSReaderSettings) Test(org.junit.Test)

Aggregations

CascadingStyleSheet (com.helger.css.decl.CascadingStyleSheet)2 DoNothingCSSParseErrorHandler (com.helger.css.reader.errorhandler.DoNothingCSSParseErrorHandler)2 CSSWriter (com.helger.css.writer.CSSWriter)2 Test (org.junit.Test)2 EUnicodeBOM (com.helger.commons.charset.EUnicodeBOM)1 ByteArrayInputStreamProvider (com.helger.commons.io.streamprovider.ByteArrayInputStreamProvider)1 CSSReaderSettings (com.helger.css.reader.CSSReaderSettings)1 CSSWriterSettings (com.helger.css.writer.CSSWriterSettings)1 Charset (java.nio.charset.Charset)1