W3C home > Mailing lists > Public > www-validator-cvs@w3.org > September 2012

2002/css-validator/org/w3c/css/properties/css21 CssHeight.java,1.2,1.3 CssWidth.java,1.2,1.3

From: Yves Lafon via cvs-syncmail <cvsmail@w3.org>
Date: Thu, 06 Sep 2012 12:37:59 +0000
To: www-validator-cvs@w3.org
Message-Id: <E1T9bLL-00073Z-6z@lionel-hutz.w3.org>
Update of /sources/public/2002/css-validator/org/w3c/css/properties/css21
In directory hutz:/tmp/cvs-serv26889/properties/css21

Modified Files:
	CssHeight.java CssWidth.java 
Log Message:
preparation of new css3 types support, parser already modified to accept them, some alignment of coding std for old properties

Index: CssHeight.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/properties/css21/CssHeight.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- CssHeight.java	9 Feb 2012 17:36:32 -0000	1.2
+++ CssHeight.java	6 Sep 2012 12:37:56 -0000	1.3
@@ -4,7 +4,6 @@
 // Please first read the full copyright statement in file COPYRIGHT.html
 package org.w3c.css.properties.css21;
 
-import org.w3c.css.properties.css.CssProperty;
 import org.w3c.css.util.ApplContext;
 import org.w3c.css.util.InvalidParamException;
 import org.w3c.css.values.CssExpression;
@@ -21,134 +20,76 @@
  */
 public class CssHeight extends org.w3c.css.properties.css.CssHeight {
 
-    CssLength lenVal;
-    CssPercentage perVal;
-    CssIdent identVal;
-
-    /**
-     * Create a new CssHeight
-     */
-    public CssHeight() {
-    }
-
-    /**
-     * Create a new CssHeight.
-     *
-     * @param expression The expression for this property
-     * @throws org.w3c.css.util.InvalidParamException Values are incorrect
-     */
-    public CssHeight(ApplContext ac, CssExpression expression, boolean check)
-            throws InvalidParamException {
-
-        if (check && expression.getCount() > 1) {
-            throw new InvalidParamException("unrecognize", ac);
-        }
-
-        CssValue val = expression.getValue();
-
-        setByUser();
-
-        switch (val.getType()) {
-            case CssTypes.CSS_IDENT:
-                CssIdent ident = (CssIdent) val;
-                if (inherit.equals(val)) {
-                    identVal = inherit;
-                } else if (auto.equals(val)) {
-                    identVal = auto;
-                } else {
-                    throw new InvalidParamException("unrecognize", ac);
-                }
-                break;
-            case CssTypes.CSS_NUMBER:
-                val = ((CssNumber) val).getLength();
-            case CssTypes.CSS_LENGTH:
-                lenVal = (CssLength) val;
-                if (!lenVal.isPositive()) {
-                    throw new InvalidParamException("negative-value",
-                            val.toString(), ac);
-                }
-                break;
-            case CssTypes.CSS_PERCENTAGE:
-                perVal = (CssPercentage) val;
-                if (perVal.floatValue() < 0.) {
-                    throw new InvalidParamException("negative-value",
-                            val.toString(), ac);
-                }
-                break;
-            default:
-                throw new InvalidParamException("value", val, getPropertyName(), ac);
-        }
-        expression.next();
-    }
+	/**
+	 * Create a new CssHeight
+	 */
+	public CssHeight() {
+	}
 
-    public CssHeight(ApplContext ac, CssExpression expression)
-            throws InvalidParamException {
-        this(ac, expression, false);
-    }
+	/**
+	 * Create a new CssHeight.
+	 *
+	 * @param expression The expression for this property
+	 * @throws org.w3c.css.util.InvalidParamException
+	 *          Values are incorrect
+	 */
+	public CssHeight(ApplContext ac, CssExpression expression, boolean check)
+			throws InvalidParamException {
 
-    /**
-     * Returns the value of this property.
-     */
-    public Object get() {
-        if (identVal != null) {
-            return identVal;
-        }
-        if (perVal != null) {
-            return perVal;
-        }
-        return lenVal;
-    }
+		if (check && expression.getCount() > 1) {
+			throw new InvalidParamException("unrecognize", ac);
+		}
 
-    /**
-     * Returns true if this property is "softly" inherited
-     * e.g. his value equals inherit
-     */
-    public boolean isSoftlyInherited() {
-        return identVal == inherit;
-    }
+		CssValue val = expression.getValue();
 
-    /**
-     * Returns a string representation of the object.
-     */
-    public String toString() {
-        if (identVal != null) {
-            return identVal.toString();
-        }
-        if (perVal != null) {
-            return perVal.toString();
-        }
-        if (lenVal != null) {
-            return lenVal.toString();
-        }
-        // the default
-        return auto.toString();
-    }
+		setByUser();
 
-    /**
-     * Compares two properties for equality.
-     *
-     * @param property The other property.
-     */
-    public boolean equals(CssProperty property) {
-        try {
-            CssHeight h = (CssHeight) property;
-            return (identVal == h.identVal) &&
-                    ((perVal == null && h.perVal == null) ||
-                            (perVal != null && perVal.equals(h.perVal))) &&
-                    ((lenVal == null && h.lenVal == null) ||
-                            (lenVal != null && lenVal.equals(h.lenVal)));
+		switch (val.getType()) {
+			case CssTypes.CSS_IDENT:
+				CssIdent ident = (CssIdent) val;
+				if (inherit.equals(val)) {
+					value = inherit;
+				} else if (auto.equals(val)) {
+					value = auto;
+				} else {
+					throw new InvalidParamException("unrecognize", ac);
+				}
+				break;
+			case CssTypes.CSS_NUMBER:
+				val = ((CssNumber) val).getLength();
+			case CssTypes.CSS_LENGTH:
+				CssLength l = (CssLength) val;
+				if (!l.isPositive()) {
+					throw new InvalidParamException("negative-value",
+							val.toString(), ac);
+				}
+				value = l;
+				break;
+			case CssTypes.CSS_PERCENTAGE:
+				CssPercentage p = (CssPercentage) val;
+				if (!p.isPositive()) {
+					throw new InvalidParamException("negative-value",
+							val.toString(), ac);
+				}
+				value = p;
+				break;
+			default:
+				throw new InvalidParamException("value", val, getPropertyName(), ac);
+		}
+		expression.next();
+	}
 
-        } catch (ClassCastException ex) {
-            return false;
-        }
-    }
+	public CssHeight(ApplContext ac, CssExpression expression)
+			throws InvalidParamException {
+		this(ac, expression, false);
+	}
 
-    /**
-     * Is the value of this property is a default value.
-     * It is used by all macro for the function <code>print</code>
-     */
-    public boolean isDefault() {
-        return identVal == auto;
-    }
+	/**
+	 * Is the value of this property is a default value.
+	 * It is used by all macro for the function <code>print</code>
+	 */
+	public boolean isDefault() {
+		return value == auto;
+	}
 
 }

Index: CssWidth.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/properties/css21/CssWidth.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- CssWidth.java	9 Feb 2012 17:36:32 -0000	1.2
+++ CssWidth.java	6 Sep 2012 12:37:56 -0000	1.3
@@ -4,7 +4,6 @@
 // Please first read the full copyright statement in file COPYRIGHT.html
 package org.w3c.css.properties.css21;
 
-import org.w3c.css.properties.css.CssProperty;
 import org.w3c.css.util.ApplContext;
 import org.w3c.css.util.InvalidParamException;
 import org.w3c.css.values.CssExpression;
@@ -21,10 +20,6 @@
  */
 public class CssWidth extends org.w3c.css.properties.css.CssWidth {
 
-    CssLength lenVal;
-    CssPercentage perVal;
-    CssIdent identVal;
-
     /**
      * Create a new CssWidth
      */
@@ -52,9 +47,9 @@
             case CssTypes.CSS_IDENT:
                 CssIdent ident = (CssIdent) val;
                 if (inherit.equals(val)) {
-                    identVal = inherit;
+                    value = inherit;
                 } else if (auto.equals(val)) {
-                    identVal = auto;
+                    value = auto;
                 } else {
                     throw new InvalidParamException("unrecognize", ac);
                 }
@@ -62,18 +57,20 @@
             case CssTypes.CSS_NUMBER:
                 val = ((CssNumber) val).getLength();
             case CssTypes.CSS_LENGTH:
-                lenVal = (CssLength) val;
+                CssLength lenVal = (CssLength) val;
                 if (!lenVal.isPositive()) {
                     throw new InvalidParamException("negative-value",
                             val.toString(), ac);
                 }
+				value = lenVal;
                 break;
             case CssTypes.CSS_PERCENTAGE:
-                perVal = (CssPercentage) val;
-                if (perVal.floatValue() < 0.) {
+                CssPercentage perVal = (CssPercentage) val;
+                if (!perVal.isPositive()) {
                     throw new InvalidParamException("negative-value",
                             val.toString(), ac);
                 }
+				value = perVal;
                 break;
             default:
                 throw new InvalidParamException("value", val, getPropertyName(), ac);
@@ -87,68 +84,11 @@
     }
 
     /**
-     * Returns the value of this property.
-     */
-    public Object get() {
-        if (identVal != null) {
-            return identVal;
-        }
-        if (perVal != null) {
-            return perVal;
-        }
-        return lenVal;
-    }
-
-    /**
-     * Returns true if this property is "softly" inherited
-     * e.g. his value equals inherit
-     */
-    public boolean isSoftlyInherited() {
-        return identVal == inherit;
-    }
-
-    /**
-     * Returns a string representation of the object.
-     */
-    public String toString() {
-        if (identVal != null) {
-            return identVal.toString();
-        }
-        if (perVal != null) {
-            return perVal.toString();
-        }
-        if (lenVal != null) {
-            return lenVal.toString();
-        }
-        // the default
-        return auto.toString();
-    }
-
-    /**
-     * Compares two properties for equality.
-     *
-     * @param property The other property.
-     */
-    public boolean equals(CssProperty property) {
-        try {
-            CssWidth w = (CssWidth) property;
-            return (identVal == w.identVal) &&
-                    ((perVal == null && w.perVal == null) ||
-                            (perVal != null && perVal.equals(w.perVal))) &&
-                    ((lenVal == null && w.lenVal == null) ||
-                            (lenVal != null && lenVal.equals(w.lenVal)));
-
-        } catch (ClassCastException ex) {
-            return false;
-        }
-    }
-
-    /**
      * Is the value of this property is a default value.
      * It is used by all macro for the function <code>print</code>
      */
     public boolean isDefault() {
-        return identVal == auto;
+        return value == auto;
     }
 
 }
Received on Thursday, 6 September 2012 12:38:06 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 15:17:51 UTC