Esempio n. 1
0
  @Nonnull
  private CSSExpressionMemberFunction _createExpressionFunction(@Nonnull final CSSNode aNode) {
    _expectNodeType(aNode, ECSSNodeType.FUNCTION);

    final int nChildCount = aNode.jjtGetNumChildren();
    if (nChildCount > 1)
      _throwUnexpectedChildrenCount(aNode, "Expected 0 or 1 children but got " + nChildCount + "!");

    final String sFunctionName = aNode.getText();
    CSSExpressionMemberFunction aFunc;
    if (nChildCount == 1) {
      // Parameters present
      final CSSNode aFirstChild = aNode.jjtGetChild(0);
      final CSSExpression aFuncExpr = _createExpression(aFirstChild);
      aFunc = new CSSExpressionMemberFunction(sFunctionName, aFuncExpr);
    } else {
      // No parameters
      aFunc = new CSSExpressionMemberFunction(sFunctionName);
    }
    aFunc.setSourceLocation(aNode.getSourceLocation());
    return aFunc;
  }
  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);
      }
    }
  }