protected void convertShorthandRadiusProperties(CSSDeclaration cssDeclaration) {

    CSSExpression cssExpression = cssDeclaration.getExpression();

    List<CSSExpressionMemberTermSimple> cssExpressionMemberTermSimples =
        cssExpression.getAllSimpleMembers();

    if (cssExpressionMemberTermSimples.size() == 4) {
      CSSExpressionMemberTermSimple cssExpressionMemberTermSimple1 =
          cssExpressionMemberTermSimples.get(0);

      String value = cssExpressionMemberTermSimple1.getValue();

      CSSExpressionMemberTermSimple cssExpressionMemberTermSimple2 =
          cssExpressionMemberTermSimples.get(1);

      cssExpressionMemberTermSimple1.setValue(cssExpressionMemberTermSimple2.getValue());

      cssExpressionMemberTermSimple2.setValue(value);

      CSSExpressionMemberTermSimple cssExpressionMemberTermSimple3 =
          cssExpressionMemberTermSimples.get(2);

      value = cssExpressionMemberTermSimple3.getValue();

      CSSExpressionMemberTermSimple cssExpressionMemberTermSimple4 =
          cssExpressionMemberTermSimples.get(3);

      cssExpressionMemberTermSimple3.setValue(cssExpressionMemberTermSimple4.getValue());

      cssExpressionMemberTermSimple4.setValue(value);
    } else if (cssExpressionMemberTermSimples.size() == 3) {
      CSSExpressionMemberTermSimple cssExpressionMemberTermSimple1 =
          cssExpressionMemberTermSimples.get(0);

      String value = cssExpressionMemberTermSimple1.getValue();

      CSSExpressionMemberTermSimple cssExpressionMemberTermSimple2 =
          cssExpressionMemberTermSimples.get(1);

      cssExpressionMemberTermSimple1.setValue(cssExpressionMemberTermSimple2.getValue());

      cssExpressionMemberTermSimple2.setValue(value);

      CSSExpressionMemberTermSimple cssExpressionMemberTermSimple3 =
          cssExpressionMemberTermSimples.get(2);

      value = cssExpressionMemberTermSimple3.getValue();

      cssExpressionMemberTermSimple3.setValue(cssExpressionMemberTermSimple1.getValue());

      cssExpression.addTermSimple(value);
    }
  }
  protected void resizeYui3BackgroundPosition(
      CSSStyleRule cssStyleRule, CSSDeclaration cssDeclaration) {

    String selector = cssStyleRule.getSelectorsAsCSSString(_cssWriterSettings, 0);

    String property = cssDeclaration.getProperty();

    Matcher matcher = _yui3ResizeHandleInnerPattern.matcher(selector);

    if (!property.equals("background-position")) {
      return;
    }

    if (!matcher.find()) {
      return;
    }

    CSSExpression cssExpression = cssDeclaration.getExpression();

    List<CSSExpressionMemberTermSimple> cssExpressionMemberTermSimples =
        cssExpression.getAllSimpleMembers();

    if (selector.endsWith("bl")) {
      CSSExpressionMemberTermSimple cssExpressionMemberTermSimple1 =
          cssExpressionMemberTermSimples.get(0);

      cssExpressionMemberTermSimple1.setValue("-30px");
    } else if (selector.endsWith("br")) {
      CSSExpressionMemberTermSimple cssExpressionMemberTermSimple1 =
          cssExpressionMemberTermSimples.get(0);

      cssExpressionMemberTermSimple1.setValue("-75px");
    } else if (selector.endsWith("tl")) {
      CSSExpressionMemberTermSimple cssExpressionMemberTermSimple1 =
          cssExpressionMemberTermSimples.get(0);

      cssExpressionMemberTermSimple1.setValue("-58px");
    } else if (selector.endsWith("tr")) {
      CSSExpressionMemberTermSimple cssExpressionMemberTermSimple1 =
          cssExpressionMemberTermSimples.get(0);

      cssExpressionMemberTermSimple1.setValue("-47px");
    }

    CSSExpressionMemberTermSimple cssExpressionMemberTermSimple2 =
        cssExpressionMemberTermSimples.get(1);

    cssExpressionMemberTermSimple2.setValue("0");
  }
  protected void replace(CSSDeclaration cssDeclaration, Map<String, String> replacementValues) {

    CSSExpression cssExpression = cssDeclaration.getExpression();

    List<CSSExpressionMemberTermSimple> cssExpressionMemberTermSimples =
        cssExpression.getAllSimpleMembers();

    for (CSSExpressionMemberTermSimple cssExpressionMemberTermSimple :
        cssExpressionMemberTermSimples) {

      String replacementValue = replacementValues.get(cssExpressionMemberTermSimple.getValue());

      if (replacementValue != null) {
        cssExpressionMemberTermSimple.setValue(replacementValue);
      }
    }
  }
  protected void reverseValue(CSSExpression cssExpression) {
    List<CSSExpressionMemberTermSimple> cssExpressionMemberTermSimples =
        cssExpression.getAllSimpleMembers();

    for (CSSExpressionMemberTermSimple cssExpressionMemberTermSimple :
        cssExpressionMemberTermSimples) {

      String value = cssExpressionMemberTermSimple.getValue();

      value = reverse(value);

      if (value.contains("rtl")) {
        value = value.replace("rtl", "ltr");
      } else if (value.contains("ltr")) {
        value = value.replace("ltr", "rtl");
      }

      cssExpressionMemberTermSimple.setValue(value);
    }
  }
  protected void resizeYui3Offset(CSSStyleRule cssStyleRule, CSSDeclaration cssDeclaration) {

    String selector = cssStyleRule.getSelectorsAsCSSString(_cssWriterSettings, 0);

    Matcher matcher = _yui3ResizeHandleInnerPattern.matcher(selector);

    if (!matcher.find()) {
      return;
    }

    CSSExpression cssExpression = cssDeclaration.getExpression();

    List<CSSExpressionMemberTermSimple> cssExpressionMemberTermSimples =
        cssExpression.getAllSimpleMembers();

    for (CSSExpressionMemberTermSimple cssExpressionMemberTermSimple :
        cssExpressionMemberTermSimples) {

      cssExpressionMemberTermSimple.setValue("2px");
    }
  }
  protected void convertBackgroundProperties(CSSDeclaration cssDeclaration) {
    CSSExpression cssExpression = cssDeclaration.getExpression();

    List<ICSSExpressionMember> icssExpressionMembers = cssExpression.getAllMembers();

    for (ICSSExpressionMember icssExpressionMember : icssExpressionMembers) {

      if (icssExpressionMember instanceof CSSExpressionMemberFunction) {
        CSSExpressionMemberFunction cssExpressionMemberFunction =
            (CSSExpressionMemberFunction) icssExpressionMember;

        reverseValue(cssExpressionMemberFunction.getExpression());
      } else if (icssExpressionMember instanceof CSSExpressionMemberTermSimple) {

        CSSExpressionMemberTermSimple cssExpressionMemberTermSimple =
            (CSSExpressionMemberTermSimple) icssExpressionMember;

        cssExpressionMemberTermSimple.setValue(reverse(cssExpressionMemberTermSimple.getValue()));
      } else if (icssExpressionMember instanceof CSSExpressionMemberTermURI) {

        CSSExpressionMemberTermURI cssExpressionMemberTermURI =
            (CSSExpressionMemberTermURI) icssExpressionMember;

        String uri = cssExpressionMemberTermURI.getURIString();

        int index = uri.lastIndexOf("/") + 1;

        String fileName = reverse(uri.substring(index));

        cssExpressionMemberTermURI.setURIString(uri.substring(0, index) + fileName);
      }
    }

    List<CSSExpressionMemberTermSimple> cssExpressionMemberTermSimples =
        cssExpression.getAllSimpleMembers();

    if (cssExpressionMemberTermSimples.size() == 1) {
      CSSExpressionMemberTermSimple cssExpressionMemberTermSimple =
          cssExpressionMemberTermSimples.get(0);

      String value = cssExpressionMemberTermSimple.getValue();

      Matcher matcher = _percentOrLengthPattern.matcher(value);

      if (matcher.matches()) {
        cssExpression.addTermSimple(value);

        cssExpressionMemberTermSimple.setValue("right");
      }
    } else if (cssExpressionMemberTermSimples.size() == 2) {
      CSSExpressionMemberTermSimple cssExpressionMemberTermSimple =
          cssExpressionMemberTermSimples.get(0);

      String value = cssExpressionMemberTermSimple.getValue();

      Matcher matcher = _percentPattern.matcher(value);

      if (matcher.matches()) {
        int delta = Integer.valueOf(value.replaceAll("[^\\d]", ""), 10);

        value = (100 - delta) + "%";

        cssExpressionMemberTermSimple.setValue(value);
      }
    }
  }