Beispiel #1
0
  /**
   * Creates a new CssCueAfter
   *
   * @param expression The expression for this property
   * @throws org.w3c.css.util.InvalidParamException Expressions are incorrect
   */
  public CssCueAfter(ApplContext ac, CssExpression expression, boolean check)
      throws InvalidParamException {
    if (check && expression.getCount() > 2) {
      throw new InvalidParamException("unrecognize", ac);
    }
    setByUser();

    CssValue val;
    char op;

    val = expression.getValue();
    op = expression.getOperator();

    switch (val.getType()) {
      case CssTypes.CSS_URL:
        value = val;
        // now let's check for a volume...
        if (expression.getRemainingCount() > 1) {
          CssValue vnext = expression.getNextValue();
          if (vnext.getType() == CssTypes.CSS_VOLUME) {
            // we got a volume, so let's do extra checks, then
            // construct the value...
            if (op != SPACE) {
              throw new InvalidParamException("operator", ((new Character(op)).toString()), ac);
            }
            expression.next();
            ArrayList<CssValue> values = new ArrayList<CssValue>(2);
            values.add(val);
            values.add(vnext);
            value = new CssValueList(values);
          } else if (check) {
            throw new InvalidParamException("value", vnext, getPropertyName(), ac);
          }
        }
        break;
      case CssTypes.CSS_IDENT:
        if (inherit.equals(val)) {
          if (expression.getCount() > 1) {
            throw new InvalidParamException("value", inherit, getPropertyName(), ac);
          }
          value = inherit;
          break;
        }
        if (none.equals(val)) {
          if (check && expression.getCount() > 1) {
            throw new InvalidParamException("value", inherit, getPropertyName(), ac);
          }
          value = none;
          break;
        }
      default:
        throw new InvalidParamException("value", val.toString(), getPropertyName(), ac);
    }
    expression.next();
  }
  /**
   * Creates a new CssFontFamily
   *
   * @param expression The expression for this property
   * @throws org.w3c.css.util.InvalidParamException Expressions are incorrect
   */
  public CssFontFamily(ApplContext ac, CssExpression expression, boolean check)
      throws InvalidParamException {

    ArrayList<CssValue> values = new ArrayList<CssValue>();

    while (!expression.end()) {
      char op = expression.getOperator();
      CssValue val = expression.getValue();
      switch (val.getType()) {
        case CssTypes.CSS_STRING:
          // check it's not a quoted reserved keyword
          String s = val.toString();
          if (s.length() > 2) {
            // we remove quotes and check it's not reserved.
            CssIdent id = new CssIdent(s.substring(1, s.length() - 1));
            if (getGenericFontName(id) != null) {
              ac.getFrame().addWarning("generic-family.quote", 2);
            }
          }
          values.add(val);
          break;
        case CssTypes.CSS_IDENT:
          ArrayList<CssIdent> idval = new ArrayList<CssIdent>();
          idval.add((CssIdent) val);
          // we add idents if separated by spaces...
          while (op == SPACE && expression.getRemainingCount() > 1) {
            expression.next();
            op = expression.getOperator();
            val = expression.getValue();
            if (val.getType() == CssTypes.CSS_IDENT) {
              idval.add((CssIdent) val);
            } else {
              throw new InvalidParamException("value", val, getPropertyName(), ac);
            }
          }
          checkExpression(ac, values, idval, check);
          break;
        default:
          throw new InvalidParamException("value", val, getPropertyName(), ac);
      }
      expression.next();
      if (!expression.end() && (op != COMMA)) {
        throw new InvalidParamException("operator", ((new Character(op)).toString()), ac);
      }
    }
    checkValues(ac, values);
    value = (values.size() > 1) ? new CssLayerList(values) : values.get(0);
  }
  /**
   * Creates a new CssTextDecoration
   *
   * @param expression The expression for this property
   * @throws org.w3c.css.util.InvalidParamException Expressions are incorrect
   */
  public CssTextDecoration(ApplContext ac, CssExpression expression, boolean check)
      throws InvalidParamException {
    if (check && expression.getCount() > 4) {
      throw new InvalidParamException("unrecognize", ac);
    }
    setByUser();

    CssValue val;
    char op;

    CssIdent undValue = null;
    CssIdent oveValue = null;
    CssIdent linValue = null;
    CssIdent bliValue = null;

    val = expression.getValue();
    op = expression.getOperator();

    if (val.getType() != CssTypes.CSS_IDENT) {
      throw new InvalidParamException("value", val.toString(), getPropertyName(), ac);
    }

    CssIdent ident = (CssIdent) val;
    if (none.equals(ident)) {
      value = none;
      if (check && expression.getCount() != 1) {
        throw new InvalidParamException("value", val.toString(), getPropertyName(), ac);
      }
    } else {
      int nbgot = 0;
      do {
        if (undValue == null && underline.equals(ident)) {
          undValue = underline;
        } else if (oveValue == null && overline.equals(ident)) {
          oveValue = overline;
        } else if (linValue == null && line_through.equals(ident)) {
          linValue = line_through;
        } else if (bliValue == null && blink.equals(ident)) {
          bliValue = blink;
        } else {
          throw new InvalidParamException("value", val.toString(), getPropertyName(), ac);
        }
        nbgot++;
        if (expression.getRemainingCount() == 1 || (!check && nbgot == 4)) {
          // if we have both, exit
          // (needed only if check == false...
          break;
        }
        if (op != CssOperator.SPACE) {
          throw new InvalidParamException("operator", ((new Character(op)).toString()), ac);
        }
        expression.next();
        val = expression.getValue();
        op = expression.getOperator();
        if (val.getType() != CssTypes.CSS_IDENT) {
          throw new InvalidParamException("value", val.toString(), getPropertyName(), ac);
        }
        ident = (CssIdent) val;
      } while (!expression.end());
      // now construct the value
      ArrayList<CssValue> v = new ArrayList<CssValue>(nbgot);
      if (undValue != null) {
        v.add(undValue);
      }
      if (oveValue != null) {
        v.add(oveValue);
      }
      if (linValue != null) {
        v.add(linValue);
      }
      if (bliValue != null) {
        v.add(bliValue);
      }
      value = (nbgot > 1) ? new CssValueList(v) : v.get(0);
    }
    expression.next();
  }