예제 #1
0
  public void setCssText(final String cssText) throws DOMException {
    final CSSStyleSheetImpl parentStyleSheet = getParentStyleSheetImpl();
    if (parentStyleSheet != null && parentStyleSheet.isReadOnly()) {
      throw new DOMExceptionImpl(
          DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMExceptionImpl.READ_ONLY_STYLE_SHEET);
    }

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

      // The rule must be a media rule
      if (r.getType() == CSSRule.MEDIA_RULE) {
        media_ = ((CSSMediaRuleImpl) r).media_;
        cssRules_ = ((CSSMediaRuleImpl) r).cssRules_;
      } else {
        throw new DOMExceptionImpl(
            DOMException.INVALID_MODIFICATION_ERR, DOMExceptionImpl.EXPECTING_MEDIA_RULE);
      }
    } catch (final CSSException e) {
      throw new DOMExceptionImpl(
          DOMException.SYNTAX_ERR, DOMExceptionImpl.SYNTAX_ERROR, e.getMessage());
    } catch (final IOException e) {
      throw new DOMExceptionImpl(
          DOMException.SYNTAX_ERR, DOMExceptionImpl.SYNTAX_ERROR, e.getMessage());
    }
  }
  public void setCssText(String cssText) throws DOMException {
    if (_parentStyleSheet != null && _parentStyleSheet.isReadOnly()) {
      throw new DOMExceptionImpl(
          DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMExceptionImpl.READ_ONLY_STYLE_SHEET);
    }

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

      // The rule must be a page rule
      if (r.getType() == CSSRule.PAGE_RULE) {
        _ident = ((CSSPageRuleImpl) r)._ident;
        _pseudoPage = ((CSSPageRuleImpl) r)._pseudoPage;
        _style = ((CSSPageRuleImpl) r)._style;
      } else {
        throw new DOMExceptionImpl(
            DOMException.INVALID_MODIFICATION_ERR, DOMExceptionImpl.EXPECTING_PAGE_RULE);
      }
    } catch (CSSException e) {
      throw new DOMExceptionImpl(
          DOMException.SYNTAX_ERR, DOMExceptionImpl.SYNTAX_ERROR, e.getMessage());
    } catch (IOException e) {
      throw new DOMExceptionImpl(
          DOMException.SYNTAX_ERR, DOMExceptionImpl.SYNTAX_ERROR, e.getMessage());
    }
  }
예제 #3
0
  public int insertRule(final String rule, final int index) throws DOMException {
    final CSSStyleSheetImpl parentStyleSheet = getParentStyleSheetImpl();
    if (parentStyleSheet != null && parentStyleSheet.isReadOnly()) {
      throw new DOMExceptionImpl(
          DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMExceptionImpl.READ_ONLY_STYLE_SHEET);
    }

    try {
      final InputSource is = new InputSource(new StringReader(rule));
      final CSSOMParser parser = new CSSOMParser();
      parser.setParentStyleSheet(parentStyleSheet);
      parser.setErrorHandler(ThrowCssExceptionErrorHandler.INSTANCE);
      // parser._parentRule is never read
      // parser.setParentRule(_parentRule);
      final CSSRule r = parser.parseRule(is);

      // Insert the rule into the list of rules
      ((CSSRuleListImpl) getCssRules()).insert(r, index);

    } catch (final IndexOutOfBoundsException e) {
      throw new DOMExceptionImpl(
          DOMException.INDEX_SIZE_ERR, DOMExceptionImpl.INDEX_OUT_OF_BOUNDS, e.getMessage());
    } catch (final CSSException e) {
      throw new DOMExceptionImpl(
          DOMException.SYNTAX_ERR, DOMExceptionImpl.SYNTAX_ERROR, e.getMessage());
    } catch (final IOException e) {
      throw new DOMExceptionImpl(
          DOMException.SYNTAX_ERR, DOMExceptionImpl.SYNTAX_ERROR, e.getMessage());
    }
    return index;
  }