public void insertRule ( final String rule , final int index ) throws DOMException { final CSSStyleSheetImpl parentStyleSheet = getParentStyleSheet ( ) ; try { final CSSOMParser parser = new CSSOMParser ( ) ; parser . setParentStyleSheet ( parentStyleSheet ) ; parser . setErrorHandler ( ThrowCssExceptionErrorHandler . INSTANCE ) ; final AbstractCSSRuleImpl r = parser . parseRule ( rule ) ; // Insert the rule into the list of rules 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 ( ) ) ; } }
Insert a new rule at the given index .