Ejemplo n.º 1
0
  /**
   * Create a new CssMaxWidthATSC
   *
   * @param expression The expression for this property
   * @exception InvalidParamException Values are incorrect
   */
  public CssMaxWidthATSC(ApplContext ac, CssExpression expression, boolean check)
      throws InvalidParamException {

    if (check && expression.getCount() > 1) {
      throw new InvalidParamException("unrecognize", ac);
    }

    CssValue val = expression.getValue();

    setByUser();

    ac.getFrame().addWarning("atsc", val.toString());

    if (val.equals(inherit)) {
      value = inherit;
    } else if (val instanceof CssLength || val instanceof CssPercentage) {
      float f = ((Float) val.get()).floatValue();
      if (f < 0) {
        throw new InvalidParamException("negative-value", val.toString(), ac);
      }
      value = val;
    } else if (val.equals(none)) {
      value = none;
    } else if (val instanceof CssNumber) {
      value = ((CssNumber) val).getLength();
    } else {
      throw new InvalidParamException("value", expression.getValue(), getPropertyName(), ac);
    }

    expression.next();
  }
Ejemplo n.º 2
0
 private void checkExpression(
     ApplContext ac, ArrayList<CssValue> curval, ArrayList<CssIdent> values, boolean check) {
   CssIdent val;
   if (values.size() > 1) {
     // create a value out of that. We could even create
     // a CssString for the output (TODO ?)
     StringBuilder sb = new StringBuilder();
     boolean addSpace = false;
     for (CssIdent id : values) {
       if (addSpace) {
         sb.append(' ');
       } else {
         addSpace = true;
       }
       sb.append(id);
     }
     ac.getFrame().addWarning("with-space", 1);
     val = new CssIdent(sb.toString());
   } else {
     val = values.get(0);
     // could be done in the consistency check, but...
     if (null != getGenericFontName(val)) {
       hasGenericFontFamily = true;
     }
     if (inherit.equals(val)) {
       val = inherit;
     }
   }
   curval.add(val);
 }
Ejemplo n.º 3
0
 /**
  * check if the value is lower or equal than...
  *
  * @param ac the validation context
  * @param property the property the value is defined in
  * @throws InvalidParamException
  */
 public void warnLowerEqualThan(ApplContext ac, double d, CssProperty property) {
   BigDecimal other = BigDecimal.valueOf(d);
   if (value.compareTo(other) > 0) {
     String[] s = new String[2];
     s[0] = toString();
     s[1] = other.toPlainString() + '%';
     ac.getFrame().addWarning("lowerequal", s);
   }
 }
 public static CssIdent getAllowedIdent(ApplContext ac, CssIdent ident) {
   if (none.equals(ident)) {
     return none;
   }
   if (all.equals(ident)) {
     return all;
   }
   if (PropertiesLoader.getProfile(ac.getPropertyKey()).getProperty(ident.toString()) == null) {
     ac.getFrame().addWarning("noexproperty", ident.toString());
   }
   return ident;
 }
Ejemplo n.º 5
0
  /**
   * 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);
  }
Ejemplo n.º 6
0
 /**
  * warn if the value is not positive or null
  *
  * @param ac the validation context
  * @param property the property the value is defined in
  */
 public void warnPositiveness(ApplContext ac, CssProperty property) {
   if (!isPositive()) {
     ac.getFrame().addWarning("negative", toString());
   }
 }
Ejemplo n.º 7
0
  /**
   * Create a new OutlineATSC
   *
   * @param expression The expression for this property
   * @exception InvalidParamException Values are incorrect
   */
  public OutlineATSC(ApplContext ac, CssExpression expression, boolean check)
      throws InvalidParamException {

    if (check && expression.getCount() > 3) {
      throw new InvalidParamException("unrecognize", ac);
    }

    CssValue val = expression.getValue();
    char op = SPACE;
    boolean find = true;
    int max_values = 3;

    ac.getFrame().addWarning("atsc", val.toString());

    if (val.equals(inherit)) {
      if (expression.getCount() > 1) {
        throw new InvalidParamException("unrecognize", ac);
      }
      this.same = true;
      color = new OutlineColorATSC(ac, expression);
      width = new OutlineWidthATSC();
      width.value = inherit;
      style = new OutlineStyleATSC();
      style.value = OutlineStyleATSC.BORDERSTYLE.length - 1;
      return;
    }

    while (find && max_values-- > 0) {
      find = false;
      val = expression.getValue();
      op = expression.getOperator();

      if (val != null && val.equals(inherit)) {
        throw new InvalidParamException("unrecognize", ac);
      }

      if (val == null) {
        break;
      }

      if (op != SPACE) {
        throw new InvalidParamException("operator", ((new Character(op)).toString()), ac);
      }

      if (style == null) {
        try {
          style = new OutlineStyleATSC(ac, expression);
          find = true;
        } catch (InvalidParamException e) {
        }
      }
      if (!find && color == null) {
        try {
          color = new OutlineColorATSC(ac, expression);
          find = true;
        } catch (InvalidParamException e) {
        }
      }
      if (!find && width == null) {
        width = new OutlineWidthATSC(ac, expression);
        find = true;
      }
      if (val != null && !find) {
        throw new InvalidParamException("unrecognize", ac);
      }
    }

    if (max_values >= 2) {
      throw new InvalidParamException("few-value", getPropertyName(), ac);
    }
    /*
    if (color == null) {
        color = new OutlineColorATSC();
    }
    if (width == null) {
        width = new OutlineWidthATSC();
    }
    if (style == null) {
        style = new OutlineStyleATSC();
    }
    */
  }