use of com.helger.css.reader.CSSReaderSettings in project jmeter by apache.
the class CssParserCacheLoader method load.
@Override
public URLCollection load(Triple<String, URL, Charset> triple) throws Exception {
final String cssContent = triple.getLeft();
final URL baseUrl = triple.getMiddle();
final Charset charset = triple.getRight();
final CSSReaderSettings readerSettings = new CSSReaderSettings().setBrowserCompliantMode(true).setFallbackCharset(charset).setCSSVersion(ECSSVersion.CSS30).setCustomErrorHandler(new LoggingCSSParseErrorHandler()).setCustomExceptionHandler(new CSSParseExceptionCallback(baseUrl));
if (IGNORE_ALL_CSS_ERRORS) {
readerSettings.setInterpretErrorHandler(new DoNothingCSSInterpretErrorHandler());
}
final CascadingStyleSheet aCSS = CSSReader.readFromStringReader(cssContent, readerSettings);
final URLCollection urls = new URLCollection(new ArrayList<>());
if (aCSS == null) {
LOG.warn("Failed parsing CSS: " + baseUrl + ", got null CascadingStyleSheet");
return urls;
}
CSSVisitor.visitCSSUrl(aCSS, new DefaultCSSUrlVisitor() {
@Override
public void onImport(CSSImportRule rule) {
final String location = rule.getLocationString();
if (!StringUtils.isEmpty(location)) {
urls.addURL(location, baseUrl);
}
}
// Call for URLs outside of URLs
@Override
public void onUrlDeclaration(final ICSSTopLevelRule aTopLevelRule, final CSSDeclaration aDeclaration, final CSSExpressionMemberTermURI aURITerm) {
// NOOP
// Browser fetch such urls only when CSS rule matches
// so we disable this code
}
});
return urls;
}
use of com.helger.css.reader.CSSReaderSettings in project ph-css by phax.
the class Issue17Test method testIssue.
@Test
public void testIssue() {
// Multiple errors contained
final IReadableResource aRes = new ClassPathResource("testfiles/css30/bad_but_browsercompliant/issue17.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);
}
use of com.helger.css.reader.CSSReaderSettings in project ph-css by phax.
the class Issue21Test method testIssue.
@Test
public void testIssue() {
// Multiple errors contained
final IReadableResource aRes = new ClassPathResource("testfiles/css30/good/issue21.css");
assertTrue(aRes.exists());
final CascadingStyleSheet aCSS = CSSReader.readFromStream(aRes, new CSSReaderSettings().setFallbackCharset(StandardCharsets.UTF_8).setCustomErrorHandler(new LoggingCSSParseErrorHandler()).setBrowserCompliantMode(true));
assertNotNull(aCSS);
if (false)
System.out.println(new CSSWriter(ECSSVersion.CSS30).getCSSAsString(aCSS));
assertEquals(2, aCSS.getRuleCount());
assertEquals(2, aCSS.getStyleRuleCount());
}
use of com.helger.css.reader.CSSReaderSettings in project ph-css by phax.
the class Issue33Test method testIssue.
@Test
public void testIssue() {
// No log message may be issued in this test!
final String css = "@media \\0screen\\,screen\\9 {.test {margin-left: 0px}}";
final CSSReaderSettings aSettings = new CSSReaderSettings().setCSSVersion(ECSSVersion.LATEST).setBrowserCompliantMode(true).setInterpretErrorHandler(new DoNothingCSSInterpretErrorHandler());
final CascadingStyleSheet cascadingStyleSheet = CSSReader.readFromStringStream(css, aSettings);
final CSSWriter writer = new CSSWriter(new CSSWriterSettings(ECSSVersion.LATEST, true));
assertEquals("@media \\0screen\\,screen\\9 {.test{margin-left:0}}", writer.getCSSAsString(cascadingStyleSheet));
}
use of com.helger.css.reader.CSSReaderSettings in project ph-css by phax.
the class Issue35Test method testIssue.
@Test
public void testIssue() {
final String css = StreamHelper.getAllBytesAsString(new FileSystemResource("src/test/resources/testfiles/css30/good/issue35.css"), StandardCharsets.UTF_8);
final CSSReaderSettings aSettings = new CSSReaderSettings().setCSSVersion(ECSSVersion.LATEST).setBrowserCompliantMode(false);
final CascadingStyleSheet cascadingStyleSheet = CSSReader.readFromStringStream(css, aSettings);
assertNotNull(cascadingStyleSheet);
final CSSWriter writer = new CSSWriter(new CSSWriterSettings(ECSSVersion.LATEST, true));
assertNotNull(writer.getCSSAsString(cascadingStyleSheet));
}
Aggregations