Search in sources :

Example 1 with CSSStyleSheetImpl

use of com.steadystate.css.dom.CSSStyleSheetImpl in project kie-wb-common by kiegroup.

the class SVGStyleTranslator method parseStyleSheetDefinition.

public static StyleSheetDefinition parseStyleSheetDefinition(final String cssPath, final InputStream cssStream) throws TranslatorException {
    final CSSStyleSheetImpl sheet = parseStyleSheet(new InputSource(new InputStreamReader(cssStream)));
    final CSSRuleList cssRules = sheet.getCssRules();
    final StyleSheetDefinition result = new StyleSheetDefinition(cssPath);
    for (int i = 0; i < cssRules.getLength(); i++) {
        final CSSRule item = cssRules.item(i);
        if (CSSRule.STYLE_RULE == item.getType()) {
            final CSSStyleRuleImpl rule = (CSSStyleRuleImpl) item;
            final String selectorText = rule.getSelectorText();
            final CSSStyleDeclaration declaration = rule.getStyle();
            final StyleDefinition styleDefinition = parseStyleDefinition(declaration);
            result.addStyle(selectorText, styleDefinition);
        }
    }
    return result;
}
Also used : InputSource(org.w3c.css.sac.InputSource) CSSRule(org.w3c.dom.css.CSSRule) CSSStyleSheetImpl(com.steadystate.css.dom.CSSStyleSheetImpl) InputStreamReader(java.io.InputStreamReader) CSSStyleRuleImpl(com.steadystate.css.dom.CSSStyleRuleImpl) StyleSheetDefinition(org.kie.workbench.common.stunner.svg.gen.model.StyleSheetDefinition) CSSStyleDeclaration(org.w3c.dom.css.CSSStyleDeclaration) StyleDefinition(org.kie.workbench.common.stunner.svg.gen.model.StyleDefinition) CSSRuleList(org.w3c.dom.css.CSSRuleList)

Example 2 with CSSStyleSheetImpl

use of com.steadystate.css.dom.CSSStyleSheetImpl in project kie-wb-common by kiegroup.

the class SVGStyleTranslator method parseElementStyleDefinition.

private static StyleDefinition parseElementStyleDefinition(final String styleRaw) throws TranslatorException {
    final CSSStyleSheetImpl sheet = parseElementStyleSheet(styleRaw);
    final CSSRuleList cssRules = sheet.getCssRules();
    for (int i = 0; i < cssRules.getLength(); i++) {
        final CSSRule item = cssRules.item(i);
        if (CSSRule.STYLE_RULE == item.getType()) {
            final CSSStyleRuleImpl rule = (CSSStyleRuleImpl) item;
            final CSSStyleDeclaration declaration = rule.getStyle();
            return parseStyleDefinition(declaration);
        }
    }
    return null;
}
Also used : CSSRule(org.w3c.dom.css.CSSRule) CSSStyleSheetImpl(com.steadystate.css.dom.CSSStyleSheetImpl) CSSStyleRuleImpl(com.steadystate.css.dom.CSSStyleRuleImpl) CSSStyleDeclaration(org.w3c.dom.css.CSSStyleDeclaration) CSSRuleList(org.w3c.dom.css.CSSRuleList)

Aggregations

CSSStyleRuleImpl (com.steadystate.css.dom.CSSStyleRuleImpl)2 CSSStyleSheetImpl (com.steadystate.css.dom.CSSStyleSheetImpl)2 CSSRule (org.w3c.dom.css.CSSRule)2 CSSRuleList (org.w3c.dom.css.CSSRuleList)2 CSSStyleDeclaration (org.w3c.dom.css.CSSStyleDeclaration)2 InputStreamReader (java.io.InputStreamReader)1 StyleDefinition (org.kie.workbench.common.stunner.svg.gen.model.StyleDefinition)1 StyleSheetDefinition (org.kie.workbench.common.stunner.svg.gen.model.StyleSheetDefinition)1 InputSource (org.w3c.css.sac.InputSource)1