Search in sources :

Example 6 with CSSExpressionMemberTermURI

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()));
        }
    });
}
Also used : CascadingStyleSheet(com.helger.css.decl.CascadingStyleSheet) ICSSTopLevelRule(com.helger.css.decl.ICSSTopLevelRule) CSSExpressionMemberTermURI(com.helger.css.decl.CSSExpressionMemberTermURI) CSSImportRule(com.helger.css.decl.CSSImportRule) CSSDeclaration(com.helger.css.decl.CSSDeclaration) DefaultCSSUrlVisitor(com.helger.css.decl.visit.DefaultCSSUrlVisitor)

Example 7 with CSSExpressionMemberTermURI

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"));
        }
    });
}
Also used : ICSSTopLevelRule(com.helger.css.decl.ICSSTopLevelRule) CSSExpressionMemberTermURI(com.helger.css.decl.CSSExpressionMemberTermURI) CSSImportRule(com.helger.css.decl.CSSImportRule) CSSDeclaration(com.helger.css.decl.CSSDeclaration) CSSDeclarationList(com.helger.css.decl.CSSDeclarationList) CSSWriter(com.helger.css.writer.CSSWriter) Test(org.junit.Test)

Aggregations

CSSExpressionMemberTermURI (com.helger.css.decl.CSSExpressionMemberTermURI)7 CSSDeclaration (com.helger.css.decl.CSSDeclaration)6 CascadingStyleSheet (com.helger.css.decl.CascadingStyleSheet)5 ICSSTopLevelRule (com.helger.css.decl.ICSSTopLevelRule)5 CSSImportRule (com.helger.css.decl.CSSImportRule)4 ICSSExpressionMember (com.helger.css.decl.ICSSExpressionMember)3 DefaultCSSUrlVisitor (com.helger.css.decl.visit.DefaultCSSUrlVisitor)3 CSSWriter (com.helger.css.writer.CSSWriter)3 Charset (java.nio.charset.Charset)3 Test (org.junit.Test)3 ECSSVersion (com.helger.css.ECSSVersion)2 CSSExpressionMemberFunction (com.helger.css.decl.CSSExpressionMemberFunction)2 CSSExpressionMemberMath (com.helger.css.decl.CSSExpressionMemberMath)2 CSSExpressionMemberTermSimple (com.helger.css.decl.CSSExpressionMemberTermSimple)2 CSSStyleRule (com.helger.css.decl.CSSStyleRule)2 CSSWriterSettings (com.helger.css.writer.CSSWriterSettings)2 File (java.io.File)2 CSSDeclarationList (com.helger.css.decl.CSSDeclarationList)1 CSSExpression (com.helger.css.decl.CSSExpression)1 CSSURI (com.helger.css.decl.CSSURI)1