Search in sources :

Example 1 with ICSSVisitor

use of com.helger.css.decl.visit.ICSSVisitor in project ph-css by phax.

the class WikiVisitFromHtml method readFromStyleAttributeWithVisitor.

public static void readFromStyleAttributeWithVisitor() {
    final String sStyle = "color:red; background:fixed !important";
    final CSSDeclarationList aDeclList = CSSReaderDeclarationList.readFromString(sStyle, ECSSVersion.CSS30);
    if (aDeclList == null)
        throw new IllegalStateException("Failed to parse CSS: " + sStyle);
    // Create a custom visitor
    final ICSSVisitor aVisitor = new DefaultCSSVisitor() {

        @Override
        public void onDeclaration(@Nonnull final CSSDeclaration aDeclaration) {
            System.out.println(aDeclaration.getProperty() + ": " + aDeclaration.getExpression().getAsCSSString(new CSSWriterSettings(ECSSVersion.CSS30)) + (aDeclaration.isImportant() ? " (important)" : " (not important)"));
        }
    };
    CSSVisitor.visitAllDeclarations(aDeclList, aVisitor);
}
Also used : CSSWriterSettings(com.helger.css.writer.CSSWriterSettings) Nonnull(javax.annotation.Nonnull) DefaultCSSVisitor(com.helger.css.decl.visit.DefaultCSSVisitor) CSSDeclaration(com.helger.css.decl.CSSDeclaration) CSSDeclarationList(com.helger.css.decl.CSSDeclarationList) ICSSVisitor(com.helger.css.decl.visit.ICSSVisitor)

Aggregations

CSSDeclaration (com.helger.css.decl.CSSDeclaration)1 CSSDeclarationList (com.helger.css.decl.CSSDeclarationList)1 DefaultCSSVisitor (com.helger.css.decl.visit.DefaultCSSVisitor)1 ICSSVisitor (com.helger.css.decl.visit.ICSSVisitor)1 CSSWriterSettings (com.helger.css.writer.CSSWriterSettings)1 Nonnull (javax.annotation.Nonnull)1