use of com.helger.css.decl.CSSExpressionMemberTermURI in project ph-css by phax.
the class WikiVisitUrls method readFromStyleAttributeWithAPI.
public void readFromStyleAttributeWithAPI() {
final String sStyle = "@import 'foobar.css';\n" + "div{background:fixed url(a.gif) !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() + " - " + getSourceLocationString(aImportRule.getSourceLocation()));
}
// Call for URLs outside of URLs
@Override
public void onUrlDeclaration(@Nullable final ICSSTopLevelRule aTopLevelRule, @Nonnull final CSSDeclaration aDeclaration, @Nonnull final CSSExpressionMemberTermURI aURITerm) {
System.out.println(aDeclaration.getProperty() + " - references: " + aURITerm.getURIString() + " - " + getSourceLocationString(aURITerm.getSourceLocation()));
}
});
}
use of com.helger.css.decl.CSSExpressionMemberTermURI in project ph-css by phax.
the class CSSVisitorDeclarationListFuncTest method testModifyingCSSUrlVisitor.
@Test
public void testModifyingCSSUrlVisitor() {
final CSSDeclarationList aCSS = CSSReaderDeclarationList.readFromString("background:url(a.gif);background:url(b.gif);", ECSSVersion.CSS30);
assertNotNull(aCSS);
// Append ".modified" to all URLs
final MockModifyingCSSUrlVisitor aVisitor2 = new MockModifyingCSSUrlVisitor();
CSSVisitor.visitAllDeclarationUrls(aCSS, aVisitor2);
// Check the result
assertEquals("background:url(a.gif.modified);background:url(b.gif.modified)", new CSSWriter(ECSSVersion.CSS30, true).getCSSAsString(aCSS));
// Re-iterate to check twice
CSSVisitor.visitAllDeclarationUrls(aCSS, new DefaultCSSUrlVisitor() {
@Override
public void onImport(@Nonnull final CSSImportRule aImportRule) {
assertTrue(aImportRule.getLocationString().endsWith(".modified"));
}
@Override
public void onUrlDeclaration(@Nullable final ICSSTopLevelRule aTopLevelRule, @Nonnull final CSSDeclaration aDeclaration, @Nonnull final CSSExpressionMemberTermURI aURITerm) {
assertTrue(aURITerm.getURIString().endsWith(".modified"));
}
});
}
Aggregations