- From: Yves Lafon via cvs-syncmail <cvsmail@w3.org>
- Date: Fri, 21 Sep 2012 14:16:28 +0000
- To: www-validator-cvs@w3.org
Update of /sources/public/2002/css-validator/org/w3c/css/values In directory hutz:/tmp/cvs-serv24793 Modified Files: CssAngle.java CssCheckableValue.java CssFrequency.java CssLength.java CssNumber.java CssPercentage.java CssTime.java Log Message: value-based validation Index: CssCheckableValue.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/values/CssCheckableValue.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- CssCheckableValue.java 10 Sep 2012 17:04:58 -0000 1.3 +++ CssCheckableValue.java 21 Sep 2012 14:16:26 -0000 1.4 @@ -10,6 +10,8 @@ import org.w3c.css.util.ApplContext; import org.w3c.css.util.InvalidParamException; +import java.math.BigDecimal; + public abstract class CssCheckableValue extends CssValue { abstract boolean isPositive(); @@ -36,4 +38,11 @@ public void checkInteger(ApplContext ac, CssProperty property) throws InvalidParamException { } + + + /** + * set the native value + * @param v the BigDecimal + */ + public abstract void setValue(BigDecimal v); } Index: CssTime.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/values/CssTime.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- CssTime.java 7 Sep 2012 20:41:11 -0000 1.9 +++ CssTime.java 21 Sep 2012 14:16:26 -0000 1.10 @@ -6,6 +6,7 @@ // Please first read the full copyright statement in file COPYRIGHT.html package org.w3c.css.values; +import org.w3c.css.properties.css.CssProperty; import org.w3c.css.util.ApplContext; import org.w3c.css.util.InvalidParamException; @@ -27,7 +28,7 @@ * * @version $Revision$ */ -public class CssTime extends CssValue { +public class CssTime extends CssCheckableValue { public static final int type = CssTypes.CSS_TIME; @@ -138,6 +139,67 @@ return false; } + /** + * set the native value + * @param v the BigDecimal + */ + public void setValue(BigDecimal v) { + value = v; + } + + /** + * Returns true is the value is positive of null + * + * @return a boolean + */ + public boolean isPositive() { + return (value.signum() >= 0); + } + + /** + * Returns true is the value is positive of null + * + * @return a boolean + */ + public boolean isStrictlyPositive() { + return (value.signum() == 1); + } + + /** + * Returns true is the value is zero + * + * @return a boolean + */ + public boolean isZero() { + return BigDecimal.ZERO.equals(value); + } + + /** + * check if the value is positive or null + * @param ac the validation context + * @param property the property the value is defined in + * @throws InvalidParamException + */ + public void checkPositiveness(ApplContext ac, CssProperty property) + throws InvalidParamException { + if (!isPositive()) { + throw new InvalidParamException("negative-value", + toString(), property.getPropertyName(), ac); + } + } + /** + * check if the value is strictly positive + * @param ac the validation context + * @param property the property the value is defined in + * @throws InvalidParamException + */ + public void checkStrictPositiveness(ApplContext ac, CssProperty property) + throws InvalidParamException { + if (!isStrictlyPositive()) { + throw new InvalidParamException("strictly-positive", + toString(), property.getPropertyName(), ac); + } + } } Index: CssNumber.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/values/CssNumber.java,v retrieving revision 1.16 retrieving revision 1.17 diff -u -d -r1.16 -r1.17 --- CssNumber.java 10 Sep 2012 17:04:58 -0000 1.16 +++ CssNumber.java 21 Sep 2012 14:16:26 -0000 1.17 @@ -64,6 +64,18 @@ } /** + * set the native value + */ + public void setValue(BigDecimal v) { + value = v; + try { + v.toBigIntegerExact(); + isInt = true; + } catch (ArithmeticException e) { + isInt = false; + } + } + /** * Set the value explicitly */ public void setIntValue(int v) { Index: CssFrequency.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/values/CssFrequency.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- CssFrequency.java 7 Sep 2012 20:41:11 -0000 1.9 +++ CssFrequency.java 21 Sep 2012 14:16:26 -0000 1.10 @@ -6,6 +6,7 @@ // Please first read the full copyright statement in file COPYRIGHT.html package org.w3c.css.values; +import org.w3c.css.properties.css.CssProperty; import org.w3c.css.util.ApplContext; import org.w3c.css.util.InvalidParamException; @@ -27,43 +28,43 @@ * * @version $Revision$ */ -public class CssFrequency extends CssValue { +public class CssFrequency extends CssCheckableValue { - public static final int type = CssTypes.CSS_FREQUENCY; + public static final int type = CssTypes.CSS_FREQUENCY; - public final int getType() { - return type; - } + public final int getType() { + return type; + } - private BigDecimal value; + private BigDecimal value; protected String unit; protected BigDecimal factor = BigDecimal.ONE; private static BigDecimal defaultValue = BigDecimal.ZERO; - /** - * Create a new CssFrequency - */ - public CssFrequency() { - value = defaultValue; - } + /** + * Create a new CssFrequency + */ + public CssFrequency() { + value = defaultValue; + } - /** - * Create a new CssFrequency with a float number. - * - * @param value the float number. - */ - public CssFrequency(BigDecimal value) { - this.value = value; - } + /** + * Create a new CssFrequency with a float number. + * + * @param value the float number. + */ + public CssFrequency(BigDecimal value) { + this.value = value; + } - /** - * Set the value of this frequency. - * - * @param s the string representation of the frequency. - * @param ac For errors and warnings reports. - * @throws InvalidParamException The unit is incorrect - */ - public void set(String s, ApplContext ac) throws InvalidParamException { + /** + * Set the value of this frequency. + * + * @param s the string representation of the frequency. + * @param ac For errors and warnings reports. + * @throws InvalidParamException The unit is incorrect + */ + public void set(String s, ApplContext ac) throws InvalidParamException { String low_s = s.toLowerCase(); int length = low_s.length(); int unitIdx = length - 1; @@ -99,44 +100,108 @@ low_s.substring(0, unitIdx), ac); } - } + } - /** - * Returns the current value - */ - public Object get() { - // TODO FIXME should not be a Float... - return value.multiply(factor).floatValue(); - } + /** + * Returns the current value + */ + public Object get() { + // TODO FIXME should not be a Float... + return value.multiply(factor).floatValue(); + } - /** - * Returns the current value - */ - public String getUnit() { - return unit; - } + /** + * Returns the current value + */ + public String getUnit() { + return unit; + } - /** - * Returns a string representation of the object. - */ - public String toString() { - if (BigDecimal.ZERO.equals(value)) { - return value.toPlainString(); - } - return value.toPlainString() + unit; - } + /** + * Returns a string representation of the object. + */ + public String toString() { + if (BigDecimal.ZERO.equals(value)) { + return value.toPlainString(); + } + return value.toPlainString() + unit; + } - /** - * Compares two values for equality. - * - * @param value The other value. - */ - public boolean equals(Object value) { - return (value instanceof CssFrequency - && this.value.equals(((CssFrequency) value).value) - && unit.equals(((CssFrequency) value).unit)); - } + /** + * Compares two values for equality. + * + * @param value The other value. + */ + public boolean equals(Object value) { + return (value instanceof CssFrequency + && this.value.equals(((CssFrequency) value).value) + && unit.equals(((CssFrequency) value).unit)); + } + /** + * set the native value + * + * @param v the BigDecimal + */ + public void setValue(BigDecimal v) { + value = v; + } + /** + * Returns true is the value is positive of null + * + * @return a boolean + */ + public boolean isPositive() { + return (value.signum() >= 0); + } + + /** + * Returns true is the value is positive of null + * + * @return a boolean + */ + public boolean isStrictlyPositive() { + return (value.signum() == 1); + } + + /** + * Returns true is the value is zero + * + * @return a boolean + */ + public boolean isZero() { + return BigDecimal.ZERO.equals(value); + } + + /** + * check if the value is positive or null + * + * @param ac the validation context + * @param property the property the value is defined in + * @throws InvalidParamException + */ + public void checkPositiveness(ApplContext ac, CssProperty property) + throws InvalidParamException { + if (!isPositive()) { + throw new InvalidParamException("negative-value", + toString(), property.getPropertyName(), ac); + } + } + + /** + * check if the value is strictly positive + * + * @param ac the validation context + * @param property the property the value is defined in + * @throws InvalidParamException + */ + public void checkStrictPositiveness(ApplContext ac, CssProperty property) + throws InvalidParamException { + if (!isStrictlyPositive()) { + throw new InvalidParamException("strictly-positive", + toString(), property.getPropertyName(), ac); + } + } } Index: CssPercentage.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/values/CssPercentage.java,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- CssPercentage.java 10 Sep 2012 17:04:58 -0000 1.12 +++ CssPercentage.java 21 Sep 2012 14:16:26 -0000 1.13 @@ -96,6 +96,14 @@ } /** + * set the native value + * @param v the BigDecimal + */ + public void setValue(BigDecimal v) { + value = v; + } + + /** * Returns the current value */ public Object get() { @@ -187,5 +195,4 @@ toString(), property.getPropertyName(), ac); } } - } Index: CssAngle.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/values/CssAngle.java,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- CssAngle.java 7 Sep 2012 20:41:11 -0000 1.12 +++ CssAngle.java 21 Sep 2012 14:16:26 -0000 1.13 @@ -6,6 +6,7 @@ // Please first read the full copyright statement in file COPYRIGHT.html package org.w3c.css.values; +import org.w3c.css.properties.css.CssProperty; import org.w3c.css.util.ApplContext; import org.w3c.css.util.InvalidParamException; @@ -29,7 +30,7 @@ * * @version $Revision$ */ -public class CssAngle extends CssValue implements CssValueFloat { +public class CssAngle extends CssCheckableValue implements CssValueFloat { public static final int type = CssTypes.CSS_ANGLE; @@ -69,6 +70,14 @@ } /** + * set the native value + * @param v the BigDecimal + */ + public void setValue(BigDecimal v) { + value = v; + } + + /** * Set the value of this angle. * * @param s The string representation of the angle @@ -161,5 +170,59 @@ return normalize(value.multiply(factor)).floatValue(); } + /** + * Returns true is the value is positive of null + * + * @return a boolean + */ + public boolean isPositive() { + return (normalize(value).signum() >= 0); + } + + /** + * Returns true is the value is positive of null + * + * @return a boolean + */ + public boolean isStrictlyPositive() { + return (normalize(value).signum() == 1); + } + + /** + * Returns true is the value is zero + * + * @return a boolean + */ + public boolean isZero() { + return BigDecimal.ZERO.equals(normalize(value)); + } + + /** + * check if the value is positive or null + * @param ac the validation context + * @param property the property the value is defined in + * @throws InvalidParamException + */ + public void checkPositiveness(ApplContext ac, CssProperty property) + throws InvalidParamException { + if (!isPositive()) { + throw new InvalidParamException("negative-value", + toString(), property.getPropertyName(), ac); + } + } + + /** + * check if the value is strictly positive + * @param ac the validation context + * @param property the property the value is defined in + * @throws InvalidParamException + */ + public void checkStrictPositiveness(ApplContext ac, CssProperty property) + throws InvalidParamException { + if (!isStrictlyPositive()) { + throw new InvalidParamException("strictly-positive", + toString(), property.getPropertyName(), ac); + } + } } Index: CssLength.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/values/CssLength.java,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- CssLength.java 10 Sep 2012 17:04:58 -0000 1.15 +++ CssLength.java 21 Sep 2012 14:16:26 -0000 1.16 @@ -159,6 +159,15 @@ } } + + /** + * set the native value + * @param v the BigDecimal + */ + public void setValue(BigDecimal v) { + value = v; + } + // return self public CssLength getLength() throws InvalidParamException { return this;
Received on Friday, 21 September 2012 14:16:38 UTC