Пример #1
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;
  }
Пример #2
0
 public void setMediaText(final String mediaText) throws DOMException {
   final InputSource source = new InputSource(new StringReader(mediaText));
   try {
     final CSSOMParser parser = new CSSOMParser();
     parser.setErrorHandler(ThrowCssExceptionErrorHandler.INSTANCE);
     final SACMediaList sml = parser.parseMedia(source);
     setMediaList(sml);
   } catch (final CSSParseException e) {
     throw new DOMException(DOMException.SYNTAX_ERR, e.getLocalizedMessage());
   } catch (final IOException e) {
     throw new DOMException(DOMException.NOT_FOUND_ERR, e.getLocalizedMessage());
   }
 }