Search in sources :

Example 21 with CSSWriterSettings

use of com.helger.css.writer.CSSWriterSettings 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

CSSWriterSettings (com.helger.css.writer.CSSWriterSettings)21 Test (org.junit.Test)14 CascadingStyleSheet (com.helger.css.decl.CascadingStyleSheet)10 CSSWriter (com.helger.css.writer.CSSWriter)10 CSSDeclaration (com.helger.css.decl.CSSDeclaration)6 CSSReaderSettings (com.helger.css.reader.CSSReaderSettings)6 CSSDeclarationList (com.helger.css.decl.CSSDeclarationList)3 CSSExpressionMemberTermSimple (com.helger.css.decl.CSSExpressionMemberTermSimple)3 ICSSExpressionMember (com.helger.css.decl.ICSSExpressionMember)3 File (java.io.File)3 Charset (java.nio.charset.Charset)3 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)2 FileSystemResource (com.helger.commons.io.resource.FileSystemResource)2 ECSSVersion (com.helger.css.ECSSVersion)2 CSSExpressionMemberFunction (com.helger.css.decl.CSSExpressionMemberFunction)2 CSSExpressionMemberMath (com.helger.css.decl.CSSExpressionMemberMath)2 CSSExpressionMemberTermURI (com.helger.css.decl.CSSExpressionMemberTermURI)2 CSSStyleRule (com.helger.css.decl.CSSStyleRule)2 DefaultCSSVisitor (com.helger.css.decl.visit.DefaultCSSVisitor)2 LoggingCSSParseErrorHandler (com.helger.css.reader.errorhandler.LoggingCSSParseErrorHandler)2