2002/css-validator/org/w3c/css/properties/css3 CssWordSpacing.java,1.1,1.2

Update of /sources/public/2002/css-validator/org/w3c/css/properties/css3
In directory hutz:/tmp/cvs-serv9523/css3

Modified Files:
	CssWordSpacing.java 
Log Message:
use CssValueList (so, a real CssValue), bumped to latest draft http://www.w3.org/TR/2012/WD-css3-text-20120814/#word-spacing0

Index: CssWordSpacing.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/properties/css3/CssWordSpacing.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- CssWordSpacing.java	9 Feb 2012 17:36:33 -0000	1.1
+++ CssWordSpacing.java	4 Sep 2012 08:33:13 -0000	1.2
@@ -4,7 +4,6 @@
 // Please first read the full copyright statement in file COPYRIGHT.html
 package org.w3c.css.properties.css3;
 
-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;
@@ -13,120 +12,87 @@
 import org.w3c.css.values.CssOperator;
 import org.w3c.css.values.CssTypes;
 import org.w3c.css.values.CssValue;
+import org.w3c.css.values.CssValueList;
+
+import java.util.ArrayList;
 
 /**
- * @spec http://www.w3.org/TR/2011/WD-css3-text-20110901/#word-spacing0
+ * @spec http://www.w3.org/TR/2012/WD-css3-text-20120814/#word-spacing0
  */
 public class CssWordSpacing extends org.w3c.css.properties.css.CssWordSpacing {
 
-    private CssValue value[] = new CssValue[3];
-    int nb_values;
-    private static CssIdent normal = CssIdent.getIdent("normal");
-
-    /**
-     * Create a new CssWordSpacing.
-     */
-    public CssWordSpacing() {
-        value[0] = normal;
-    }
-
-    /**
-     * Create a new CssWordSpacing with an expression
-     *
-     * @param expression The expression
-     * @throws org.w3c.css.util.InvalidParamException
-     *          The expression is incorrect
-     */
-    public CssWordSpacing(ApplContext ac, CssExpression expression,
-                          boolean check) throws InvalidParamException {
-        nb_values = expression.getCount();
-
-        if (check && nb_values > 3) {
-            throw new InvalidParamException("unrecognize", ac);
-        }
+	private static CssIdent normal = CssIdent.getIdent("normal");
 
-        for (int i = 0; i < nb_values; i++) {
-            CssValue val = expression.getValue();
+	/**
+	 * Create a new CssWordSpacing.
+	 */
+	public CssWordSpacing() {
+		value = initial;
+	}
 
-            setByUser();
+	/**
+	 * Create a new CssWordSpacing with an expression
+	 *
+	 * @param expression The expression
+	 * @throws org.w3c.css.util.InvalidParamException
+	 *          The expression is incorrect
+	 */
+	public CssWordSpacing(ApplContext ac, CssExpression expression,
+						  boolean check) throws InvalidParamException {
 
-            switch (val.getType()) {
-                case CssTypes.CSS_NUMBER:
-                    val = ((CssNumber) val).getLength();
-                case CssTypes.CSS_LENGTH:
-                    value[i] = val;
-                    break;
-                case CssTypes.CSS_PERCENTAGE:
-                    value[i] = val;
-                    break;
-                case CssTypes.CSS_IDENT:
-                    if (inherit.equals(val)) {
-                        // inherit can only be alone
-                        if (nb_values > 1) {
-                            throw new InvalidParamException("value", expression.getValue(),
-                                    getPropertyName(), ac);
-                        }
-                        value[i] = inherit;
-                        break;
-                    } else if (normal.equals(val)) {
-                        value[i] = normal;
-                        break;
-                    }
-                default:
-                    throw new InvalidParamException("value", expression.getValue(),
-                            getPropertyName(), ac);
-            }
-            if (i+1 < nb_values && expression.getOperator() != CssOperator.SPACE) {
-               throw new InvalidParamException("operator", CssOperator.SPACE, ac);
-            }
-            expression.next();
-        }
-    }
+		if (check && expression.getCount() > 3) {
+			throw new InvalidParamException("unrecognize", ac);
+		}
+		setByUser();
 
-    public CssWordSpacing(ApplContext ac, CssExpression expression)
-            throws InvalidParamException {
-        this(ac, expression, false);
-    }
+		ArrayList<CssValue> v = new ArrayList<CssValue>(4);
+		CssValue val;
+		char op;
 
-    /**
-     * Returns the value of this property
-     */
-    public Object get() {
-        return value;
-    }
+		while (!expression.end()) {
+			val = expression.getValue();
+			op = expression.getOperator();
 
-    /**
-     * Returns true if this property is "softly" inherited
-     * e.g. his value equals inherit
-     */
-    public boolean isSoftlyInherited() {
-        return value[0] == inherit;
-    }
+			switch (val.getType()) {
+				case CssTypes.CSS_NUMBER:
+					val = ((CssNumber) val).getLength();
+				case CssTypes.CSS_LENGTH:
+					v.add(val);
+					break;
+				case CssTypes.CSS_PERCENTAGE:
+					v.add(val);
+					break;
+				case CssTypes.CSS_IDENT:
+					if (inherit.equals(val)) {
+						// inherit can only be alone
+						if (expression.getCount() > 1) {
+							throw new InvalidParamException("value", expression.getValue(),
+									getPropertyName(), ac);
+						}
+						value = inherit;
+						break;
+					} else if (normal.equals(val)) {
+						v.add(normal);
+						break;
+					}
+				default:
+					throw new InvalidParamException("value", expression.getValue(),
+							getPropertyName(), ac);
+			}
+			if (op != CssOperator.SPACE) {
+				throw new InvalidParamException("operator",
+						((new Character(op)).toString()), ac);
+			}
+			expression.next();
+		}
+		if (value != inherit) {
+			value = (v.size() == 1) ? v.get(0) : new CssValueList(v);
+		}
+	}
 
-    /**
-     * Returns a string representation of the object.
-     */
-    public String toString() {
-        if (nb_values == 1) {
-            return value[0].toString();
-        }
-        StringBuilder sb = new StringBuilder();
-        for (int i=0; i < nb_values; i++) {
-            if (i > 0) {
-                sb.append(' ');
-            }
-            sb.append(value[i]);
-        }
-        return sb.toString();
-    }
+	public CssWordSpacing(ApplContext ac, CssExpression expression)
+			throws InvalidParamException {
+		this(ac, expression, false);
+	}
 
-    /**
-     * Compares two properties for equality.
-     *
-     * @param property The other property.
-     */
-    public boolean equals(CssProperty property) {
-        return (property instanceof CssWordSpacing &&
-                value.equals(((CssWordSpacing) property).value));
-    }
 }

Received on Tuesday, 4 September 2012 08:33:21 UTC