org.w3c.dom.css.CSSRule Java Examples

The following examples show how to use org.w3c.dom.css.CSSRule. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StyleParser.java    From svgtoandroid with MIT License 6 votes vote down vote up
private void init() {
    if (style != null) {
        String styleContent = style.getValue().getText();
        if (styleContent != null && !styleContent.isEmpty()) {
            InputSource source = new InputSource(new StringReader(styleContent));
            CSSOMParser parser = new CSSOMParser(new SACParserCSS3());
            parser.setErrorHandler(new ParserErrorHandler());
            try {
                styleSheet = parser.parseStyleSheet(source, null, null);
                cssFormat = new CSSFormat().setRgbAsHex(true);

                CSSRuleList rules = styleSheet.getCssRules();
                for (int i = 0; i < rules.getLength(); i++) {
                    final CSSRule rule = rules.item(i);
                    if (rule instanceof CSSStyleRuleImpl) {
                        styleRuleMap.put(((CSSStyleRuleImpl) rule).getSelectorText(), (CSSStyleRuleImpl) rule);
                    }
                }

            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
 
Example #2
Source File: HtmlHelper.java    From FairEmail with GNU General Public License v3.0 5 votes vote down vote up
private static String processStyles(String tag, String clazz, String style, CSSRuleList rules, int stype) {
    for (int i = 0; rules != null && i < rules.getLength(); i++) {
        CSSRule rule = rules.item(i);
        switch (rule.getType()) {
            case CSSRule.STYLE_RULE:
                CSSStyleRuleImpl srule = (CSSStyleRuleImpl) rule;
                for (int j = 0; j < srule.getSelectors().getLength(); j++) {
                    Selector selector = srule.getSelectors().item(j);
                    if (selector.getSelectorType() != stype)
                        continue;
                    switch (selector.getSelectorType()) {
                        case Selector.SAC_ELEMENT_NODE_SELECTOR:
                            ElementSelectorImpl eselector = (ElementSelectorImpl) selector;
                            if (tag == null
                                    ? eselector.getLocalName() == null
                                    : tag.equals(eselector.getLocalName()))
                                style = mergeStyles(style, srule.getStyle().getCssText());
                            break;
                        case Selector.SAC_CONDITIONAL_SELECTOR:
                            ConditionalSelectorImpl cselector = (ConditionalSelectorImpl) selector;
                            if (cselector.getCondition().getConditionType() == SAC_CLASS_CONDITION) {
                                ClassConditionImpl ccondition = (ClassConditionImpl) cselector.getCondition();
                                if (clazz.equals(ccondition.getValue()))
                                    style = mergeStyles(style, srule.getStyle().getCssText());
                            }
                            break;
                    }
                }
                break;

            case CSSRule.MEDIA_RULE:
                CSSMediaRuleImpl mrule = (CSSMediaRuleImpl) rule;
                if (isScreenMedia(mrule.getMedia()))
                    style = processStyles(tag, clazz, style, mrule.getCssRules(), stype);
                break;
        }
    }
    return style;
}
 
Example #3
Source File: CSSStyleSheet.java    From HtmlUnit-Android with Apache License 2.0 5 votes vote down vote up
private void refreshCssRules() {
    if (cssRules_ == null) {
        return;
    }

    cssRules_.clearRules();
    cssRulesIndexFix_.clear();

    final CSSRuleListImpl ruleList = (CSSRuleListImpl) getWrappedSheet().getCssRules();
    final List<CSSRule> rules = ruleList.getRules();
    int pos = 0;
    for (CSSRule rule : rules) {
        if (rule instanceof org.w3c.dom.css.CSSCharsetRule) {
            cssRulesIndexFix_.add(pos);
            continue;
        }

        final com.gargoylesoftware.htmlunit.javascript.host.css.CSSRule cssRule
                    = com.gargoylesoftware.htmlunit.javascript.host.css.CSSRule.create(this, rule);
        if (null == cssRule) {
            cssRulesIndexFix_.add(pos);
        }
        else {
            cssRules_.addRule(cssRule);
        }
        pos++;
    }

    // reset our index also
    ((CSSStyleSheetImpl) getWrappedSheet()).resetRuleIndex();
}
 
Example #4
Source File: PackageInfoTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name = "jdkClasses")
public Object[][] jdkClasses() {
    return new Object[][] {
        { java.awt.Button.class,             null },
        { java.lang.Object.class,            null },
        { org.w3c.dom.css.CSSRule.class,     null },
        { loadClass("org.w3c.dom.css.Fake"), loadClass("org.w3c.dom.css.FakePackage") },
    };
}
 
Example #5
Source File: PackageInfoTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private Class<?> loadClass(String name) {
    return Class.forName(CSSRule.class.getModule(), name);
}
 
Example #6
Source File: AbstractStyle.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public CSSRule getParentRule( )
{
	throw new DOMException( DOMException.NOT_SUPPORTED_ERR, "getParentRule" );
}
 
Example #7
Source File: StyleSheet.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Gets the rule list of the style sheet.
 * 
 * @return the rule list
 */

public List<CSSRule> getRules( )
{
	return rules;
}
 
Example #8
Source File: StyleSheet.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public CSSRule getOwnerRule( )
{
	return null;
}
 
Example #9
Source File: StyleRule.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public CSSRule getParentRule( )
{
	return null;
}
 
Example #10
Source File: StyleDeclaration.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public CSSRule getParentRule( )
{
	return null;
}
 
Example #11
Source File: UnSupportedRule.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public CSSRule getParentRule( )
{
	return null;
}
 
Example #12
Source File: StyleSheet.java    From birt with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Adds a rule into the tail of the style sheet.
 * 
 * @param rule
 *            the rule to add
 */

public void add( CSSRule rule )
{
	rules.add( rule );
}
 
Example #13
Source File: StyleSheet.java    From birt with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Inserts a rule to the given position of the style sheet.
 * 
 * @param rule
 *            the rule to insert
 * @param index
 *            the position to insert
 */

public void insert( CSSRule rule, int index )
{
	rules.add( index, rule );
}