use of com.helger.css.utils.CSSDataURL in project ph-css by phax.
the class WikiVisitDataUrls method readFromStyleAttributeWithAPI.
public void readFromStyleAttributeWithAPI() {
final String sStyle = "@import '/folder/foobar.css';\n" + "div{background:fixed url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAIAAAACUFjqAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAALEgAACxIB0t1+/AAAAAd0SU1FB9EFBAoYMhVvMQIAAAAtSURBVHicY/z//z8DHoBH+v///yy4FDEyMjIwMDDhM3lgpaEuh7gTEzDiDxYA9HEPDF90e5YAAAAASUVORK5CYII=) !important;}\n" + "span { background-image:url('/my/folder/b.gif');}";
final CascadingStyleSheet aCSS = CSSReader.readFromString(sStyle, ECSSVersion.CSS30);
CSSVisitor.visitCSSUrl(aCSS, new DefaultCSSUrlVisitor() {
// Called for each import
@Override
public void onImport(@Nonnull final CSSImportRule aImportRule) {
System.out.println("Import: " + aImportRule.getLocationString());
}
// Call for URLs outside of URLs
@Override
public void onUrlDeclaration(@Nullable final ICSSTopLevelRule aTopLevelRule, @Nonnull final CSSDeclaration aDeclaration, @Nonnull final CSSExpressionMemberTermURI aURITerm) {
final CSSURI aURI = aURITerm.getURI();
if (aURI.isDataURL()) {
final CSSDataURL aDataURL = aURI.getAsDataURL();
System.out.println(aDeclaration.getProperty() + " - references data URL with " + aDataURL.getContentLength() + " bytes of content");
} else
System.out.println(aDeclaration.getProperty() + " - references regular URL: " + aURI.getURI());
}
});
}
use of com.helger.css.utils.CSSDataURL in project ph-css by phax.
the class CSSURITest method testDataURL.
@Test
public void testDataURL() {
final CSSURI aURI = new CSSURI("data:text/plain,foobar");
assertEquals("data:text/plain,foobar", aURI.getURI());
assertTrue(aURI.isDataURL());
final CSSDataURL aDataURL = aURI.getAsDataURL();
assertNotNull(aDataURL);
assertEquals("foobar", aDataURL.getContentAsString());
}
Aggregations