Package org.w3c.dom.css

Examples of org.w3c.dom.css.CSSRule


        try {
            InputSource is = new InputSource(new StringReader(rule));
            CSSOMParser parser = new CSSOMParser();
            parser.setParentStyleSheet(this);
            CSSRule r = parser.parseRule(is);

            if (getCssRules().getLength() > 0) {

                // We need to check that this type of rule can legally go into
                // the requested position.
                int msg = -1;
                if (r.getType() == CSSRule.CHARSET_RULE) {

                    // Index must be 0, and there can be only one charset rule
                    if (index != 0) {
                        msg = DOMExceptionImpl.CHARSET_NOT_FIRST;
                    } else if (getCssRules().item(0).getType()
                            == CSSRule.CHARSET_RULE) {
                        msg = DOMExceptionImpl.CHARSET_NOT_UNIQUE;
                    }
                } else if (r.getType() == CSSRule.IMPORT_RULE) {

                    // Import rules must preceed all other rules (except
                    // charset rules)
                    if (index <= getCssRules().getLength()) {
                        for (int i = 0; i < index; i++) {
View Full Code Here


    public void importImports(boolean recursive)
        throws DOMException
    {
        for (int i = 0; i < this.getCssRules().getLength(); i++)
        {
            CSSRule cssRule = this.getCssRules().item(i);
            if (cssRule.getType() == CSSRule.IMPORT_RULE)
            {
                CSSImportRule cssImportRule = (CSSImportRule) cssRule;
                try
                {
                    java.net.URI importURI = new java.net.URI(this.getBaseUri())
View Full Code Here

        }

        try {
            InputSource is = new InputSource(new StringReader(cssText));
            CSSOMParser parser = new CSSOMParser();
            CSSRule r = parser.parseRule(is);

            // The rule must be a font face rule
            if (r.getType() == CSSRule.FONT_FACE_RULE) {
                this.style = ((CSSFontFaceRuleImpl)r).style;
            } else {
                throw new DOMExceptionImpl(
                    DOMException.INVALID_MODIFICATION_ERR,
                    DOMExceptionImpl.EXPECTING_FONT_FACE_RULE);
View Full Code Here

        final CSSRuleList rules = getWrappedSheet().getCssRules();
        if (rules == null) {
            return;
        }
        for (int i = 0; i < rules.getLength(); i++) {
            final CSSRule rule = rules.item(i);
            if (rule.getType() == CSSRule.STYLE_RULE) {
                final CSSStyleRuleImpl styleRule = (CSSStyleRuleImpl) rule;
                final SelectorList selectors = styleRule.getSelectors();
                for (int j = 0; j < selectors.getLength(); j++) {
                    final Selector selector = selectors.item(j);
                    final boolean selected = selects(selector, e);
                    if (selected) {
                        final org.w3c.dom.css.CSSStyleDeclaration dec = styleRule.getStyle();
                        style.applyStyleFromSelector(dec, selector);
                    }
                }
            }
            else if (rule.getType() == CSSRule.IMPORT_RULE) {
                final CSSImportRuleImpl importRule = (CSSImportRuleImpl) rule;
                Stylesheet sheet = imports_.get(importRule);
                if (sheet == null) {
                    // TODO: surely wrong: in which case is it null and why?
                    final String uri = (uri_ != null) ? uri_
View Full Code Here

            CSSStyleSheet stylesheet = parser.parseStyleSheet(is);
            CSSRuleList rules = stylesheet.getCssRules();

            for (int i = 0; i < rules.getLength(); i++) {
                CSSRule rule = rules.item(i);
                list.add(rule);
            }


      }
View Full Code Here

            Element e,
            String pe,
            CSSOMRuleList rl) {
  int llen = l.getLength();
  for (int i = 0; i < llen; i++) {
      CSSRule rule = l.item(i);
      switch (rule.getType()) {
      case CSSRule.STYLE_RULE:
    CSSOMStyleRule sr = (CSSOMStyleRule)rule;
    SelectorList sl = sr.getSelectors();
    int slen = sl.getLength();
    for (int j = 0; j < slen; j++) {
View Full Code Here

   *
   * @return DOCUMENT ME!
   */
  public String toString() {
    CStringBuilder result = new CStringBuilder();
    CSSRule       rule  = this;
    int         level = 0;

    while (rule.getParentRule() != null) {
      level++;
      rule = rule.getParentRule();
    } // end while

    for (int i = 0; i < level; i++) {
      result.append("\t");
    } // end for
View Full Code Here

 
  private void parseSelectors(CSSStyleSheet css,List result) {
    CSSRuleList ruleList = css.getCssRules();
   
    for (int j = 0; j < ruleList.getLength(); j++) {
      CSSRule rule = ruleList.item(j);

      if (rule == null) {
        continue;
      }

      if (rule.getType() == CSSRule.STYLE_RULE) {
        CSSStyleRule      cssRule = (CSSStyleRule) rule;
        CSSStyleDeclaration decl = cssRule.getStyle();
        StringTokenizer selectorsToken = new StringTokenizer(cssRule.getSelectorText(),",", false);
        while (selectorsToken.hasMoreTokens()) {
          String   selector = selectorsToken.nextToken().trim();
          CElement element = getElements(selector);
          if (element != null) {
            result.add(new CStyle(element,decl));
          }
        }
      } // end if
      else if (rule.getType() == CSSRule.IMPORT_RULE) {
        CSSStyleSheet importCSS = ((CSSImportRule) rule).getStyleSheet();
        parseSelectors(importCSS,result);
      } // end else if
    }
  }
View Full Code Here

TOP

Related Classes of org.w3c.dom.css.CSSRule

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.