Java 类org.w3c.dom.css.CSSRuleList 实例源码

项目:InuktitutComputing    文件:NRC_HTMLDocumentByCobra.java   
private void checkForCSSPseudoRules() {
        Collection ss = document.getStyleSheets();
        java.util.Iterator itss = ss.iterator();
        Pattern patRule = Pattern.compile("^([^:]+?):(link|active|visited|hover)\\s+(\\{.+)$");
        HashSet newRules = new HashSet();
        while (itss.hasNext()) {
            CSSStyleSheetImpl ss1 = (CSSStyleSheetImpl)itss.next();
            CSSRuleList ruleList = ss1.getCssRules();
            for (int i=0; i < ruleList.getLength(); i++) {
                CSSRule rule = ruleList.item(i);
                String ruleText = rule.getCssText();
//              System.out.println("rule : "+ruleText);
                Matcher mpatRule = patRule.matcher(ruleText);
                if (mpatRule.find()) {
                    String newRuleText = mpatRule.group(1)+" "+mpatRule.group(3);
                    if (!newRules.contains(mpatRule.group(1))) {
                        newRules.add(mpatRule.group(1));
//                      System.out.println("***new rule : "+newRuleText);
                        ss1.insertRule(newRuleText, i++);
                    }
                }
            }
        }
    }
项目:svgtoandroid    文件:StyleParser.java   
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();
            }
        }
    }
}
项目:LoboEvolution    文件:CSSStyleSheetImpl.java   
private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException {
    baseUri_ = (String) in.readObject();
    cssRules_ = (CSSRuleList) in.readObject();
    if (cssRules_ != null) {
        for (int i = 0; i < cssRules_.getLength(); i++) {
            final CSSRule cssRule = cssRules_.item(i);
            if (cssRule instanceof AbstractCSSRuleImpl) {
                ((AbstractCSSRuleImpl) cssRule).setParentStyleSheet(this);
            }
        }
    }
    disabled_ = in.readBoolean();
    href_ = (String) in.readObject();
    media_ = (MediaList) in.readObject();
    // TODO ownerNode may not be serializable!
    // ownerNode = (Node) in.readObject();
    readOnly_ = in.readBoolean();
    title_ = (String) in.readObject();
}
项目:LoboEvolution    文件:CssParserTest.java   
/**
 * Show style sheet.
 *
 * @param styleSheet
 *            the style sheet
 */
private void showStyleSheet(CSSStyleSheet styleSheet) {
    StringWriter stringWriter = new StringWriter();
    PrintWriter writer = new PrintWriter(stringWriter);
    writer.println("<DL>");
    CSSRuleList ruleList = styleSheet.getCssRules();
    int length = ruleList.getLength();
    for (int i = 0; i < length; i++) {
        CSSRule rule = ruleList.item(i);
        writer.println("<DT><strong>Rule: type=" + rule.getType() + ",class=" + rule.getClass().getName()
                + "</strong></DT>");
        writer.println("<DD>");
        this.writeRuleInfo(writer, rule);
        writer.println("</DD>");
    }
    writer.println("</DL>");
    writer.flush();
    String html = stringWriter.toString();
    HtmlRendererContext rcontext = new SimpleHtmlRendererContext(this.cssOutput, (UserAgentContext) null);
    this.cssOutput.setHtml(html, "about:css", rcontext);
}
项目:kie-wb-common    文件:SVGStyleTranslatorHelper.java   
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;
}
项目:xstreamer    文件:CSSStyleSheetAssert.java   
public CSSStyleSheetAssert hasSize(int size) {
    isNotNull();

    CSSRuleList rules = actual.getCssRules();

    if (rules == null) {
        failWithMessage("Expected to rules not to be empty or null");
    }

    if (rules.getLength() != size) {
        failWithMessage("Expected number of rules <%s> but was <%s>", size, rules.getLength());
    }

    return this;
}
项目:xstreamer    文件:XWIngCommonCssTest.java   
protected CSSStyleRule findRule(CSSRuleList rules, String ruleName) throws Exception {
    for (int i = 0; i < rules.getLength(); i++) {
        CSSStyleRuleImpl rule = (CSSStyleRuleImpl) rules.item(i);

        SelectorList selectorList = rule.getSelectors();
        for (int s = 0; s < selectorList.getLength(); s++ ) {
            Selector selector = selectorList.item(s);
            if (selector.toString().equals(ruleName)) {
                return rule;
            }
        }
    }
    return null;
}
项目:LoboEvolution    文件:CSSMediaRuleImpl.java   
@Override
public CSSRuleList getCssRules() {
    if (cssRules_ == null) {
        cssRules_ = new CSSRuleListImpl();
    }
    return cssRules_;
}
项目:LoboEvolution    文件:CSSMediaRuleImpl.java   
private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException {

        cssRules_ = (CSSRuleList) in.readObject();
        if (cssRules_ != null) {
            for (int i = 0; i < cssRules_.getLength(); i++) {
                final CSSRule cssRule = cssRules_.item(i);
                if (cssRule instanceof AbstractCSSRuleImpl) {
                    ((AbstractCSSRuleImpl) cssRule).setParentRule(this);
                    ((AbstractCSSRuleImpl) cssRule).setParentStyleSheet(getParentStyleSheetImpl());
                }
            }
        }
        media_ = (MediaList) in.readObject();
    }
项目:LoboEvolution    文件:CSSStyleSheetImpl.java   
@Override
public CSSRuleList getCssRules() {
    if (cssRules_ == null) {
        cssRules_ = new CSSRuleListImpl();
    }
    return cssRules_;
}
项目:LoboEvolution    文件:CSSStyleSheetImpl.java   
/**
 * {@inheritDoc}
 */
@Override
public String getCssText(final CSSFormat format) {
    final CSSRuleList rules = getCssRules();
    if (rules instanceof CSSFormatable) {
        return ((CSSRuleListImpl) rules).getCssText(format);
    }
    return getCssRules().toString();
}
项目:LoboEvolution    文件:CSSRuleListImpl.java   
@Override
public boolean equals(final Object obj) {
    if (this == obj) {
        return true;
    }
    if (!(obj instanceof CSSRuleList)) {
        return false;
    }
    final CSSRuleList crl = (CSSRuleList) obj;
    return equalsRules(crl);
}
项目:LoboEvolution    文件:CSSRuleListImpl.java   
private boolean equalsRules(final CSSRuleList crl) {
    if ((crl == null) || (getLength() != crl.getLength())) {
        return false;
    }
    for (int i = 0; i < getLength(); i++) {
        final CSSRule cssRule1 = item(i);
        final CSSRule cssRule2 = crl.item(i);
        if (!LangUtils.equals(cssRule1, cssRule2)) {
            return false;
        }
    }
    return true;
}
项目:LoboEvolution    文件:StyleSheetAggregator.java   
/**
 * Adds the style sheet.
 *
 * @param styleSheet
 *            the style sheet
 * @throws MalformedURLException
 *             the malformed url exception
 * @throws UnsupportedEncodingException
 */
private final void addStyleSheet(CSSStyleSheet styleSheet)
        throws MalformedURLException, UnsupportedEncodingException {
    CSSRuleList ruleList = styleSheet.getCssRules();
    int length = ruleList.getLength();
    for (int i = 0; i < length; i++) {
        CSSRule rule = ruleList.item(i);
        this.addRule(styleSheet, rule);
    }
}
项目:jStyleDomBridge    文件:JStyleSheetWrapper.java   
/**
 * @return A list of rules contained in this style sheet.
 */
public CSSRuleList getCssRules() {
  if (this.jStyleSheet != null) {
    return new CSSRuleListImpl(jStyleSheet, this);
  }
  throw new DOMException(DOMException.INVALID_ACCESS_ERR, "A parameter or an operation is not supported by the underlying object");
}
项目:SimpleFunctionalTest    文件:CssParser.java   
public HashMap<String, CSSStyleRule> extractCssStyleRules(String cssFile) throws IOException {
    TEST_FILE_SYSTEM.filesExists(cssFile);
    CSSOMParser cssParser = new CSSOMParser();
    CSSStyleSheet css = cssParser.parseStyleSheet(new InputSource(new FileReader(TEST_FILE_SYSTEM.file(cssFile))), null, null);
    CSSRuleList cssRules = css.getCssRules();
    HashMap<String, CSSStyleRule> rules = new HashMap<String, CSSStyleRule>();
    for (int i = 0; i < cssRules.getLength(); i++) {
        CSSRule rule = cssRules.item(i);
        if (rule instanceof CSSStyleRule) {
            rules.put(((CSSStyleRule) rule).getSelectorText(), (CSSStyleRule) rule);
        }
    }
    return rules;
}
项目:thymesheet    文件:AttributeRuleList.java   
public AttributeRuleList(CSSRuleList ruleList) {
    super(ruleList.getLength());

    for (int i = 0; i < ruleList.getLength(); i++) {
        CSSRule rule = ruleList.item(i);
        if(rule instanceof CSSStyleRule) {
            this.add((CSSStyleRule)rule);
        }
    }

}
项目:thymesheet    文件:ThymesheetPreprocessor.java   
AttributeRuleList getRuleList(InputStream stream) throws IOException {
    InputSource source = new InputSource(new InputStreamReader(stream));
       CSSOMParser parser = new CSSOMParser(new SACParserCSS3());
       parser.setErrorHandler(ThrowCssExceptionErrorHandler.INSTANCE);
       CSSStyleSheet stylesheet = parser.parseStyleSheet(source, null, null);
       CSSRuleList ruleList = stylesheet.getCssRules();

       return new AttributeRuleList(ruleList);
}
项目:kie-wb-common    文件:SVGStyleTranslatorHelper.java   
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;
            String selectorText = rule.getSelectorText();
            final CSSStyleDeclaration declaration = rule.getStyle();
            return parseStyleDefinition(declaration);
        }
    }
    return null;
}
项目:LoboEvolution    文件:CSSMediaRuleImpl.java   
public void setCssRules(final CSSRuleList cssRules) {
    cssRules_ = cssRules;
}
项目:LoboEvolution    文件:CSSStyleSheetImpl.java   
public void setCssRules(final CSSRuleList rules) {
    cssRules_ = rules;
}
项目:birt    文件:StyleSheet.java   
public CSSRuleList getCssRules( )
{
    return null;
}
项目:jStyleDomBridge    文件:CSSMediaRuleImpl.java   
public CSSRuleList getCssRules() {
  return new CSSMediaRuleList();
}