2002/css-validator/org/w3c/css/properties/css1 CssBackground.java,1.9,1.10 CssBackgroundAttachment.java,1.6,1.7 CssBackgroundImage.java,1.6,1.7 CssBackgroundRepeat.java,1.5,1.6

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

Modified Files:
	CssBackground.java CssBackgroundAttachment.java 
	CssBackgroundImage.java CssBackgroundRepeat.java 
Log Message:
css1 background fixes

Index: CssBackgroundImage.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/properties/css1/CssBackgroundImage.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- CssBackgroundImage.java	9 Feb 2012 17:36:28 -0000	1.6
+++ CssBackgroundImage.java	4 May 2012 12:57:40 -0000	1.7
@@ -12,6 +12,7 @@
 import org.w3c.css.util.ApplContext;
 import org.w3c.css.util.InvalidParamException;
 import org.w3c.css.values.CssExpression;
+import org.w3c.css.values.CssIdent;
 import org.w3c.css.values.CssTypes;
 import org.w3c.css.values.CssValue;
 
@@ -40,6 +41,9 @@
 
     CssValue url = null;
 
+	protected static boolean checkMatchingIdent(CssIdent ident){
+		return none.equals(ident);
+	}
     /**
      * Create a new CssBackgroundImage
      */

Index: CssBackgroundRepeat.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/properties/css1/CssBackgroundRepeat.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- CssBackgroundRepeat.java	9 Feb 2012 17:36:29 -0000	1.5
+++ CssBackgroundRepeat.java	4 May 2012 12:57:40 -0000	1.6
@@ -59,6 +59,15 @@
         }
     }
 
+	protected static boolean checkMatchingIdent(CssIdent ident) {
+		for (CssIdent id : allowed_values.values()) {
+			if (id.equals(ident)) {
+				return true;
+			}
+		}
+		return false;
+	}
+
     public CssValue value;
 
 

Index: CssBackgroundAttachment.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/properties/css1/CssBackgroundAttachment.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- CssBackgroundAttachment.java	9 Feb 2012 17:36:28 -0000	1.6
+++ CssBackgroundAttachment.java	4 May 2012 12:57:40 -0000	1.7
@@ -15,7 +15,7 @@
 import org.w3c.css.values.CssTypes;
 import org.w3c.css.values.CssValue;
 
-import java.util.HashMap;
+import java.util.ArrayList;
 
 /**
  * <H4>
@@ -43,122 +43,135 @@
  */
 public class CssBackgroundAttachment extends org.w3c.css.properties.css.CssBackgroundAttachment {
 
-    private static HashMap<String, CssIdent> allowed_values;
-    private static CssIdent scroll;
+	private static ArrayList<CssIdent> allowed_values;
+	private static CssIdent scroll;
 
-    static {
-        allowed_values = new HashMap<String, CssIdent>();
-        scroll = CssIdent.getIdent("scroll");
-        allowed_values.put("scroll", scroll);
-        allowed_values.put("fixed", CssIdent.getIdent("fixed"));
-    }
+	static {
+		allowed_values = new ArrayList<CssIdent>();
+		scroll = CssIdent.getIdent("scroll");
+		allowed_values.add(scroll);
+		allowed_values.add(CssIdent.getIdent("fixed"));
+	}
 
-    CssIdent value;
+	protected static boolean checkMatchingIdent(CssIdent ident) {
+		return (null != getMatchingIdent(ident));
+	}
 
-    /**
-     * Create a new CssBackgroundAttachment
-     */
-    public CssBackgroundAttachment() {
-        value = scroll;
-    }
+	protected static CssIdent getMatchingIdent(CssIdent ident) {
+		for (CssIdent id : allowed_values) {
+			if (id.equals(ident)) {
+				return id;
+			}
+		}
+		return null;
+	}
 
-    /**
-     * Creates a new CssBackgroundAttachment
-     *
-     * @param expression The expression for this property
-     * @throws InvalidParamException Values are incorrect
-     */
-    public CssBackgroundAttachment(ApplContext ac, CssExpression expression,
-                                   boolean check) throws InvalidParamException {
+	CssIdent value;
 
-        if (check && expression.getCount() > 1) {
-            throw new InvalidParamException("unrecognize", ac);
-        }
+	/**
+	 * Create a new CssBackgroundAttachment
+	 */
+	public CssBackgroundAttachment() {
+		value = scroll;
+	}
 
-        setByUser();
+	/**
+	 * Creates a new CssBackgroundAttachment
+	 *
+	 * @param expression The expression for this property
+	 * @throws InvalidParamException Values are incorrect
+	 */
+	public CssBackgroundAttachment(ApplContext ac, CssExpression expression,
+								   boolean check) throws InvalidParamException {
 
-        CssValue val = expression.getValue();
+		if (check && expression.getCount() > 1) {
+			throw new InvalidParamException("unrecognize", ac);
+		}
 
-        if (val.getType() == CssTypes.CSS_IDENT) {
-            CssIdent new_val = allowed_values.get(val.toString());
-            if (new_val != null) {
-                value = new_val;
-                expression.next();
-                return;
-            }
-        }
-        throw new InvalidParamException("value", expression.getValue(),
-                getPropertyName(), ac);
-    }
+		setByUser();
 
-    public CssBackgroundAttachment(ApplContext ac, CssExpression expression)
-            throws InvalidParamException {
-        this(ac, expression, false);
-    }
+		CssValue val = expression.getValue();
 
-    /**
-     * Returns the value of this property
-     */
-    public Object get() {
-        return value;
-    }
+		if (val.getType() == CssTypes.CSS_IDENT) {
+			CssIdent new_val = getMatchingIdent((CssIdent)val);
+			if (new_val != null) {
+				value = new_val;
+				expression.next();
+				return;
+			}
+		}
+		throw new InvalidParamException("value", expression.getValue(),
+				getPropertyName(), ac);
+	}
 
-    /**
-     * Returns true if this property is "softly" inherited
-     * e.g. his value equals inherit
-     */
-    public boolean isSoftlyInherited() {
-        return false;
-    }
+	public CssBackgroundAttachment(ApplContext ac, CssExpression expression)
+			throws InvalidParamException {
+		this(ac, expression, false);
+	}
 
-    /**
-     * Returns a string representation of the object.
-     */
-    public String toString() {
-        return value.toString();
-    }
+	/**
+	 * Returns the value of this property
+	 */
+	public Object get() {
+		return value;
+	}
 
-    /**
-     * Add this property to the CssStyle.
-     *
-     * @param style The CssStyle
-     */
-    public void addToStyle(ApplContext ac, CssStyle style) {
-        org.w3c.css.properties.css.CssBackground cssBackground = ((Css1Style) style).cssBackground;
-        if (cssBackground.attachment != null)
-            style.addRedefinitionWarning(ac, this);
-        cssBackground.attachment = this;
-    }
+	/**
+	 * Returns true if this property is "softly" inherited
+	 * e.g. his value equals inherit
+	 */
+	public boolean isSoftlyInherited() {
+		return false;
+	}
 
-    /**
-     * Get this property in the style.
-     *
-     * @param style   The style where the property is
-     * @param resolve if true, resolve the style to find this property
-     */
-    public CssProperty getPropertyInStyle(CssStyle style, boolean resolve) {
-        if (resolve) {
-            return ((Css1Style) style).getBackgroundAttachment();
-        } else {
-            return ((Css1Style) style).cssBackground.attachment;
-        }
-    }
+	/**
+	 * Returns a string representation of the object.
+	 */
+	public String toString() {
+		return value.toString();
+	}
 
-    /**
-     * Compares two properties for equality.
-     *
-     * @param property The other property.
-     */
-    public boolean equals(CssProperty property) {
-        return (property instanceof CssBackgroundAttachment &&
-                value == ((CssBackgroundAttachment) property).value);
-    }
+	/**
+	 * Add this property to the CssStyle.
+	 *
+	 * @param style The CssStyle
+	 */
+	public void addToStyle(ApplContext ac, CssStyle style) {
+		org.w3c.css.properties.css.CssBackground cssBackground = ((Css1Style) style).cssBackground;
+		if (cssBackground.attachment != null)
+			style.addRedefinitionWarning(ac, this);
+		cssBackground.attachment = this;
+	}
 
-    /**
-     * 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 (scroll == value);
-    }
+	/**
+	 * Get this property in the style.
+	 *
+	 * @param style   The style where the property is
+	 * @param resolve if true, resolve the style to find this property
+	 */
+	public CssProperty getPropertyInStyle(CssStyle style, boolean resolve) {
+		if (resolve) {
+			return ((Css1Style) style).getBackgroundAttachment();
+		} else {
+			return ((Css1Style) style).cssBackground.attachment;
+		}
+	}
+
+	/**
+	 * Compares two properties for equality.
+	 *
+	 * @param property The other property.
+	 */
+	public boolean equals(CssProperty property) {
+		return (property instanceof CssBackgroundAttachment &&
+				value == ((CssBackgroundAttachment) property).value);
+	}
+
+	/**
+	 * 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 (scroll == value);
+	}
 }

Index: CssBackground.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/properties/css1/CssBackground.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- CssBackground.java	25 Apr 2012 20:21:55 -0000	1.9
+++ CssBackground.java	4 May 2012 12:57:39 -0000	1.10
@@ -12,6 +12,8 @@
 import org.w3c.css.util.ApplContext;
 import org.w3c.css.util.InvalidParamException;
 import org.w3c.css.values.CssExpression;
+import org.w3c.css.values.CssIdent;
+import org.w3c.css.values.CssTypes;
 import org.w3c.css.values.CssValue;
 
 import static org.w3c.css.values.CssOperator.SPACE;
@@ -78,74 +80,138 @@
     public CssBackground(ApplContext ac, CssExpression expression,
                          boolean check) throws InvalidParamException {
 
-        CssValue val;
-        char op;
-        boolean find = true;
+		CssValue val;
+		char op = SPACE;
+		boolean find = true;
+		CssExpression background_position_expression = null;
 
-        // too many values
-        if (check && expression.getCount() > 6) {
-            throw new InvalidParamException("unrecognize", ac);
-        }
+		// too many values
+		if (check && expression.getCount() > 6) {
+			throw new InvalidParamException("unrecognize", ac);
+		}
 
-        setByUser();
+		setByUser();
 
-        while (find) {
-            find = false;
-            val = expression.getValue();
-            op = expression.getOperator();
+		boolean manyValues = (expression.getCount() > 1);
 
-            if (val == null) {
-                break;
-            }
+		while (find) {
+			val = expression.getValue();
+			if (val == null) {
+				break;
+			}
+			op = expression.getOperator();
 
-            if (color == null) {
-                try {
-                    color = new CssBackgroundColor(ac, expression);
-                    find = true;
-                } catch (InvalidParamException e) {
-                }
-            }
-            if (!find && image == null) {
-                try {
-                    image = new CssBackgroundImage(ac, expression);
-                    find = true;
-                } catch (InvalidParamException e) {
-                    // nothing to do, repeat will test this value
-                }
-            }
-            if (!find && repeat == null) {
-                try {
-                    repeat = new CssBackgroundRepeat(ac, expression);
-                    find = true;
-                } catch (InvalidParamException e) {
-                    // nothing to do, attachment will test this value
-                }
-            }
-            if (!find && attachment == null) {
-                try {
-                    attachment = new CssBackgroundAttachment(ac, expression);
-                    find = true;
-                } catch (InvalidParamException e) {
-                    // nothing to do, position will test this value
-                }
-            }
-            if (!find && position == null) {
-                try {
-                    position = new CssBackgroundPosition(ac, expression);
-                    find = true;
-                } catch (InvalidParamException e) {
-                    // nothing to do
-                }
-            }
-            if (op != SPACE) {
-                throw new InvalidParamException("operator",
-                        ((new Character(op)).toString()),
-                        ac);
-            }
-            if (check && !find && val != null) {
-                throw new InvalidParamException("unrecognize", ac);
-            }
-        }
+			// if there are many values, we can't have inherit as one of them
+			if (manyValues && val.equals(inherit)) {
+				throw new InvalidParamException("unrecognize", null, null, ac);
+			}
+
+			switch (val.getType()) {
+				case CssTypes.CSS_STRING:
+					if (check) {
+						throw new InvalidParamException("unrecognize", ac);
+					}
+					find = false;
+					break;
+				case CssTypes.CSS_URL:
+					if (image == null) {
+						image = new CssBackgroundImage(ac, expression);
+						continue;
+					}
+					find = false;
+					break;
+				case CssTypes.CSS_COLOR:
+					if (color == null) {
+						color = new CssBackgroundColor(ac, expression);
+						continue;
+					}
+					find = false;
+					break;
+				case CssTypes.CSS_NUMBER:
+				case CssTypes.CSS_PERCENTAGE:
+				case CssTypes.CSS_LENGTH:
+					if (background_position_expression == null) {
+						background_position_expression = new CssExpression();
+					}
+					background_position_expression.addValue(val);
+					expression.next();
+					find = true;
+					break;
+				case CssTypes.CSS_IDENT:
+					// the hard part, as ident can be from different subproperties
+					find = false;
+					CssIdent identval = (CssIdent) val;
+					if (inherit.equals(identval) && !manyValues) {
+						find = true;
+						same = true;
+						expression.next();
+						break;
+					}
+					// check background-image ident
+					if (CssBackgroundImage.checkMatchingIdent(identval)) {
+						if (image == null) {
+							image = new CssBackgroundImage(ac, expression);
+							find = true;
+						}
+						break;
+					}
+					// check background-repeat ident
+					if (CssBackgroundRepeat.checkMatchingIdent(identval)) {
+						if (repeat == null) {
+							repeat = new CssBackgroundRepeat(ac, expression);
+							find = true;
+						}
+						break;
+					}
+					// check background-attachment ident
+					if (CssBackgroundAttachment.checkMatchingIdent(identval)) {
+						if (attachment == null) {
+							attachment = new CssBackgroundAttachment(ac, expression);
+							find = true;
+						}
+						break;
+					}
+					// check background-position ident
+					if (CssBackgroundPosition.checkMatchingIdent(identval)) {
+						if (background_position_expression == null) {
+							background_position_expression = new CssExpression();
+						}
+						background_position_expression.addValue(val);
+						expression.next();
+						find = true;
+						break;
+					}
+
+					if (color == null) {
+						try {
+							color = new CssBackgroundColor(ac, expression);
+							find = true;
+							break;
+						} catch (InvalidParamException e) {
+							// nothing to do, image will test this value
+						}
+					}
+
+				default:
+					if (check) {
+						throw new InvalidParamException("unrecognize", ac);
+					}
+					find = false;
+			}
+			if (check && !find) {
+				throw new InvalidParamException("unrecognize", ac);
+			}
+			if (op != SPACE) {
+				throw new InvalidParamException("operator",
+						Character.toString(op),
+						ac);
+			}
+		}
+		if (background_position_expression != null) {
+			position = new CssBackgroundPosition(ac,
+					background_position_expression,
+					check);
+		}
     }
 
     public CssBackground(ApplContext ac, CssExpression expression)

Received on Friday, 4 May 2012 12:57:49 UTC