2002/css-validator/org/w3c/css/properties/mobile CssBackground.java,NONE,1.1 CssBackgroundAttachment.java,NONE,1.1 CssBackgroundColor.java,NONE,1.1 CssBackgroundImage.java,NONE,1.1 CssBackgroundPosition.java,NONE,1.1 CssBackgroundRepeat.java,NONE,1.1

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

Added Files:
	CssBackground.java CssBackgroundAttachment.java 
	CssBackgroundColor.java CssBackgroundImage.java 
	CssBackgroundPosition.java CssBackgroundRepeat.java 
Log Message:
more mobile/tv cleanup

--- NEW FILE: CssBackgroundRepeat.java ---
//
// $Id: CssBackgroundRepeat.java,v 1.1 2012/11/02 14:14:13 ylafon Exp $
// From Philippe Le Hegaret (Philippe.Le_Hegaret@sophia.inria.fr)
//
// (c) COPYRIGHT MIT and INRIA, 1997.
// Please first read the full copyright statement in file COPYRIGHT.html
package org.w3c.css.properties.mobile;

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;

/**
 * @spec http://www.w3.org/TR/2011/REC-CSS2-20110607/colors.html#propdef-background-repeat
 * @spec http://www.w3.org/TR/2008/CR-css-mobile-20081210/#properties
 */
public class CssBackgroundRepeat extends org.w3c.css.properties.css.CssBackgroundRepeat {

	private static CssIdent[] allowed_values;

	static {
		String[] REPEAT = {"repeat", "repeat-x", "repeat-y", "no-repeat"};

		allowed_values = new CssIdent[REPEAT.length];
		int i = 0;
		for (String aREPEAT : REPEAT) {
			allowed_values[i++] = CssIdent.getIdent(aREPEAT);
		}
	}

	protected static boolean checkMatchingIdent(CssIdent ident) {
		return (getMatchingIdent(ident) != null);
	}

	protected static CssIdent getMatchingIdent(CssIdent ident) {
		for (CssIdent id : allowed_values) {
			if (id.equals(ident)) {
				return id;
			}
		}
		return null;
	}

	/**
	 * Create a new CssBackgroundRepeat
	 */
	public CssBackgroundRepeat() {
		value = repeat;
	}

	/**
	 * Set the value of the property
	 *
	 * @param expression The expression for this property
	 * @throws org.w3c.css.util.InvalidParamException
	 *          The expression is incorrect
	 */
	public CssBackgroundRepeat(ApplContext ac, CssExpression expression,
							   boolean check) throws InvalidParamException {

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

		CssValue val = expression.getValue();
		setByUser();

		if (val.getType() != CssTypes.CSS_IDENT) {
			throw new InvalidParamException("value", expression.getValue(),
					getPropertyName(), ac);
		}
		if (inherit.equals(val)) {
			value = inherit;
		} else {
			value = getMatchingIdent((CssIdent) val);
			if (value == null) {
				throw new InvalidParamException("value", expression.getValue(),
						getPropertyName(), ac);
			}
		}
		expression.next();
	}

	public CssBackgroundRepeat(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 (repeat == value);
	}
}




--- NEW FILE: CssBackgroundAttachment.java ---
//
// $Id: CssBackgroundAttachment.java,v 1.1 2012/11/02 14:14:13 ylafon Exp $
// From Philippe Le Hegaret (Philippe.Le_Hegaret@sophia.inria.fr)
//
// (c) COPYRIGHT MIT and INRIA, 1997.
// Please first read the full copyright statement in file COPYRIGHT.html
package org.w3c.css.properties.mobile;

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;

/**
 * @spec http://www.w3.org/TR/2011/REC-CSS2-20110607/colors.html#propdef-background-attachment
 * @spec http://www.w3.org/TR/2008/CR-css-mobile-20081210/#properties
 */
public class CssBackgroundAttachment extends org.w3c.css.properties.css.CssBackgroundAttachment {

	public static boolean checkMatchingIdent(CssIdent ident) {
		for (CssIdent id : allowed_values) {
			if (id.equals(ident)) {
				return true;
			}
		}
		return false;
	}

	private static CssIdent[] allowed_values;

	static {
		allowed_values = new CssIdent[2];
		allowed_values[0] = CssIdent.getIdent("scroll");
		allowed_values[1] = CssIdent.getIdent("fixed");
	}

	public static CssIdent getMatchingIdent(CssIdent ident) {
		for (CssIdent id : allowed_values) {
			if (id.equals(ident)) {
				return id;
			}
		}
		return null;
	}

	/**
	 * Create a new CssBackgroundAttachment
	 */
	public CssBackgroundAttachment() {
	}

	/**
	 * Creates a new CssBackgroundAttachment
	 *
	 * @param expression The expression for this property
	 * @throws org.w3c.css.util.InvalidParamException
	 *          Values are incorrect
	 */
	public CssBackgroundAttachment(ApplContext ac, CssExpression expression,
								   boolean check) throws InvalidParamException {

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

		setByUser();

		CssValue val = expression.getValue();

		if (val.getType() == CssTypes.CSS_IDENT) {
			if (inherit.equals(val)) {
				value = inherit;
				expression.next();
				return;
			}
			CssIdent new_val = getMatchingIdent((CssIdent) val);
			if (new_val != null) {
				value = new_val;
				expression.next();
				return;
			}
		}


		throw new InvalidParamException("value", expression.getValue(),
				getPropertyName(), ac);
	}

	public CssBackgroundAttachment(ApplContext ac, CssExpression expression)
			throws InvalidParamException {
		this(ac, expression, false);
	}
}

--- NEW FILE: CssBackground.java ---
// $Id: CssBackground.java,v 1.1 2012/11/02 14:14:13 ylafon Exp $
// Author: Jean-Guilhem Rouel
// Revised by: Yves Lafon
// (c) COPYRIGHT MIT, ERCIM and Keio, 2005-2008.
// Please first read the full copyright statement in file COPYRIGHT.html
package org.w3c.css.properties.mobile;

import org.w3c.css.parser.CssSelectors;
import org.w3c.css.parser.CssStyle;
import org.w3c.css.properties.css.CssProperty;
import org.w3c.css.properties.css1.Css1Style;
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;

/**
 * @spec http://www.w3.org/TR/2008/CR-css-mobile-20081210/#properties
 * @spec http://www.w3.org/TR/2011/REC-CSS2-20110607/colors.html#propdef-background
 */
public class CssBackground extends org.w3c.css.properties.css.CssBackground {

	public CssBackgroundColor color;
	public CssBackgroundImage image;
	public CssBackgroundRepeat repeat;
	public CssBackgroundAttachment attachment;
	public CssBackgroundPosition position;

	public boolean same;

	/**
	 * Create a new CssBackground
	 */
	public CssBackground() {
		super();
	}

	/**
	 * Set the value of the property
	 *
	 * @param expression The expression for this property
	 * @throws org.w3c.css.util.InvalidParamException The expression is incorrect
	 */
	public CssBackground(ApplContext ac, CssExpression expression,
						 boolean check) throws InvalidParamException {
		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);
		}

		setByUser();

		boolean manyValues = (expression.getCount() > 1);

		while (find) {
			val = expression.getValue();
			if (val == null) {
				break;
			}
			op = expression.getOperator();

			// 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_HASH_IDENT:
				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)
			throws InvalidParamException {
		this(ac, expression, false);
	}

	/**
	 * Returns the value of this property
	 */
	public Object get() {
		return color;
	}

	/**
	 * Returns the color
	 */
	public final CssValue getColor() {
		if (color == null) {
			return null;
		} else {
			return color.getColor();
		}
	}

	/**
	 * Returns a string representation of the object.
	 */
	public String toString() {

		if (same) {
			return inherit.toString();
		} else {
			StringBuilder sb = new StringBuilder();
			boolean addspace = false;

			if (color != null) {
				sb.append(color);
				addspace = true;
			}
			if (image != null) {
				if (addspace) {
					sb.append(' ');
				}
				sb.append(image);
				addspace = true;
			}
			if (repeat != null) {
				if (addspace) {
					sb.append(' ');
				}
				sb.append(repeat);
				addspace = true;
			}
			if (attachment != null) {
				if (addspace) {
					sb.append(' ');
				}
				sb.append(attachment);
				addspace = true;
			}
			if (position != null) {
				if (addspace) {
					sb.append(' ');
				}
				sb.append(position);
			}
			return sb.toString();
		}
	}

	/**
	 * Set this property to be important.
	 * Overrides this method for a macro
	 */

	public void setImportant() {
		important = true;
		if (color != null) {
			color.important = true;
		}
		if (image != null) {
			image.important = true;
		}
		if (repeat != null) {
			repeat.important = true;
		}
		if (attachment != null) {
			attachment.important = true;
		}
		if (position != null) {
			position.important = true;
		}
	}

	/**
	 * Returns true if this property is important.
	 * Overrides this method for a macro
	 */
	public boolean getImportant() {
		if (same) {
			return important;
		}
		return ((color == null || color.important) &&
				(image == null || image.important) &&
				(repeat == null || repeat.important) &&
				(attachment == null || attachment.important) &&
				(position == null || position.important));
	}

	/**
	 * Set the context.
	 * Overrides this method for a macro
	 *
	 * @see org.w3c.css.css.CssCascadingOrder#order
	 * @see org.w3c.css.css.StyleSheetParser#handleRule
	 */
	public void setSelectors(CssSelectors selector) {
		super.setSelectors(selector);
		if (color != null) {
			color.setSelectors(selector);
		}
		if (image != null) {
			image.setSelectors(selector);
		}
		if (repeat != null) {
			repeat.setSelectors(selector);
		}
		if (attachment != null) {
			attachment.setSelectors(selector);
		}
		if (position != null) {
			position.setSelectors(selector);
		}
	}

	/**
	 * Add this property to the CssStyle
	 *
	 * @param style The CssStyle
	 */
	public void addToStyle(ApplContext ac, CssStyle style) {
		((Css1Style) style).cssBackground.same = same;
		((Css1Style) style).cssBackground.byUser = byUser;

		if (color != null) {
			color.addToStyle(ac, style);
		}
		if (image != null) {
			image.addToStyle(ac, style);
		}
		if (repeat != null) {
			repeat.addToStyle(ac, style);
		}
		if (attachment != null) {
			attachment.addToStyle(ac, style);
		}
		if (position != null) {
			position.addToStyle(ac, style);
		}
	}

	/**
	 * 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).getBackground();
		} else {
			return ((Css1Style) style).cssBackground;
		}
	}

}

--- NEW FILE: CssBackgroundPosition.java ---
// $Id: CssBackgroundPosition.java,v 1.1 2012/11/02 14:14:13 ylafon Exp $
// Author: Jean-Guilhem Rouel
// (c) COPYRIGHT MIT, ERCIM and Keio, 2005.
// Please first read the full copyright statement in file COPYRIGHT.html
package org.w3c.css.properties.mobile;

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.CssPercentage;
import org.w3c.css.values.CssTypes;
import org.w3c.css.values.CssValue;

import static org.w3c.css.values.CssOperator.SPACE;

/**
 * @spec http://www.w3.org/TR/2011/REC-CSS2-20110607/colors.html#propdef-background-position
 * @spec http://www.w3.org/TR/2008/CR-css-mobile-20081210/#properties
 */
public class CssBackgroundPosition extends org.w3c.css.properties.css.CssBackgroundPosition {

	public static CssIdent[] allowed_values;
	public static CssIdent center, top, bottom, left, right;
	private static CssPercentage defaultPercent0, defaultPercent50;
	private static CssPercentage defaultPercent100;

	static {
		top = CssIdent.getIdent("top");
		bottom = CssIdent.getIdent("bottom");
		left = CssIdent.getIdent("left");
		right = CssIdent.getIdent("right");
		center = CssIdent.getIdent("center");
		allowed_values = new CssIdent[5];
		allowed_values[0] = top;
		allowed_values[1] = bottom;
		allowed_values[2] = left;
		allowed_values[3] = right;
		allowed_values[4] = center;

		defaultPercent0 = new CssPercentage(0);
		defaultPercent50 = new CssPercentage(50);
		defaultPercent100 = new CssPercentage(100);
	}

	public static boolean checkMatchingIdent(CssIdent ident) {
		for (CssIdent id : allowed_values) {
			if (id.equals(ident)) {
				return true;
			}
		}
		return false;
	}

	public static CssIdent getMatchingIdent(CssIdent ident) {
		for (CssIdent id : allowed_values) {
			if (id.equals(ident)) {
				return id;
			}
		}
		return null;
	}

	/**
	 * Create a new CssBackgroundPosition
	 */
	public CssBackgroundPosition() {
		super();
	}

	/**
	 * Creates a new CssBackgroundPosition
	 *
	 * @param expression The expression for this property
	 * @throws org.w3c.css.util.InvalidParamException
	 *          Values are incorrect
	 */
	public CssBackgroundPosition(ApplContext ac, CssExpression expression,
								 boolean check) throws InvalidParamException {

		int nb_val = expression.getCount();

		if (check && nb_val > 2) {
			throw new InvalidParamException("unrecognize", ac);
		}

		setByUser();
		setByUser();
		CssValue val;
		CssBackgroundPositionValue b_val = null;
		char op;

		// we just accumulate values and check at validation
		while (!expression.end()) {
			val = expression.getValue();
			op = expression.getOperator();

			if (inherit.equals(val)) {
				if (expression.getCount() > 1) {
					throw new InvalidParamException("value", val,
							getPropertyName(), ac);
				}
				value = inherit;
				expression.next();
				return;
			}
			if (b_val == null) {
				b_val = new CssBackgroundPositionValue();
			}
			// we will check later
			b_val.add(val);
			expression.next();

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

		}
		// if we reach the end in a value that can come in pair
		if (b_val != null) {
			check(b_val, ac);
			value = b_val;
		}
	}

	// check the value

	public void check(CssBackgroundPositionValue v, ApplContext ac)
			throws InvalidParamException {
		int nb_keyword = 0;
		int nb_percentage = 0;
		int nb_length = 0;
		int nb_values = v.value.size();

		if (nb_values > 2) {
			throw new InvalidParamException("unrecognize", ac);
		}
		// basic check
		for (CssValue aValue : v.value) {
			switch (aValue.getType()) {
				case CssTypes.CSS_IDENT:
					nb_keyword++;
					break;
				default:
					throw new InvalidParamException("value", aValue,
							getPropertyName(), ac);
			}
		}

		// this is unnecessary complex, blame it on the CSS3 spec.
		switch (nb_keyword) {
			case 0:
				// no keyword, so it's easy, it depends on the number
				// of values :)
				switch (nb_values) {
					case 1:
						// If only one value is specified, the second value
						// is assumed to be 'center'.
						v.horizontal = v.value.get(0);
						v.val_horizontal = v.horizontal;
						v.val_vertical = defaultPercent50;
						break;
					case 2:
						v.horizontal = v.value.get(0);
						v.val_horizontal = v.horizontal;
						v.vertical = v.value.get(1);
						v.val_vertical = v.vertical;
						break;
					default:
						// should never happen
						throw new InvalidParamException("unrecognize",
								ac);

				}
				break;
			// we got one keyword... let's have fun...
			case 1:
				switch (nb_values) {
					case 1:
						CssIdent ident = (CssIdent) v.value.get(0);
						// ugly as we need to set values for equality tests
						v.val_vertical = defaultPercent50;
						v.val_horizontal = defaultPercent50;
						ident = getMatchingIdent(ident);
						if (ident != null) {
							if (isVertical(ident)) {
								v.vertical = ident;
								v.val_vertical = identToPercent(ident);
							} else {
								// horizontal || center
								v.horizontal = ident;
								v.val_horizontal = identToPercent(ident);
							}
							break;
						}
						throw new InvalidParamException("unrecognize",
								ident, getPropertyName(), ac);
					case 2:
						// one ident, two values... first MUST be horizontal
						// and second vertical
						CssValue val0 = v.value.get(0);
						if (val0.getType() == CssTypes.CSS_IDENT) {
							ident = getMatchingIdent((CssIdent) val0);
							if (ident == null) {
								throw new InvalidParamException("unrecognize",
										ident, getPropertyName(), ac);
							}
							if (isVertical(ident)) {
								throw new InvalidParamException("incompatible",
										ident, v.value.get(1), ac);
							}
							v.horizontal = ident;
							v.val_horizontal = identToPercent(ident);
							// and the vertical value...
							v.vertical = v.value.get(1);
							if (v.vertical.getType() == CssTypes.CSS_NUMBER) {
								v.vertical = defaultPercent0;
							}
							v.val_vertical = v.vertical;
						} else {
							CssValue value1 = v.value.get(1);
							if (value1.getType() != CssTypes.CSS_IDENT) {
								throw new InvalidParamException("unrecognize",
										value1, getPropertyName(), ac);
							}
							ident = getMatchingIdent((CssIdent) value1);
							if (ident == null) {
								throw new InvalidParamException("unrecognize",
										ident, getPropertyName(), ac);
							}
							if (isHorizontal(ident)) {
								throw new InvalidParamException("incompatible",
										val0, value1, ac);
							}
							v.vertical = ident;
							v.val_vertical = identToPercent(ident);
							// and the first value
							v.horizontal = val0;
							if (v.horizontal.getType() == CssTypes.CSS_NUMBER) {
								v.horizontal = defaultPercent0;
							}
							v.val_horizontal = v.horizontal;
						}
						break;
					default:
						// one ident, 3 or 4 values is not allowed
						throw new InvalidParamException("unrecognize",
								ac);
				}
				break;
			default:
				// we got two keywords for two values, yeah!
				CssIdent id1 = (CssIdent) v.value.get(0);
				CssIdent id2 = (CssIdent) v.value.get(1);


				if (((isVertical(id1) && isVertical(id2))) ||
						(isHorizontal(id1) && isHorizontal(id2))) {
					throw new InvalidParamException("incompatible",
							id1, id2, ac);
				}
				if (isVertical(id1) || isHorizontal(id2)) {
					v.horizontal = id2;
					v.val_horizontal = identToPercent(id2);
					v.vertical = id1;
					v.val_vertical = identToPercent(id1);
				} else {
					v.horizontal = id1;
					v.val_horizontal = identToPercent(id1);
					v.vertical = id2;
					v.val_vertical = identToPercent(id2);
				}
		}
	}

	public CssBackgroundPosition(ApplContext ac, CssExpression expression)
			throws InvalidParamException {
		this(ac, expression, false);
	}
}

--- NEW FILE: CssBackgroundImage.java ---
//
// $Id: CssBackgroundImage.java,v 1.1 2012/11/02 14:14:13 ylafon Exp $
// From Philippe Le Hegaret (Philippe.Le_Hegaret@sophia.inria.fr)
//
// (c) COPYRIGHT MIT and INRIA, 1997.
// Please first read the full copyright statement in file COPYRIGHT.html

package org.w3c.css.properties.mobile;

import org.w3c.css.parser.CssStyle;
import org.w3c.css.properties.css.CssProperty;
import org.w3c.css.properties.css1.Css1Style;
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;

/**
 * @spec http://www.w3.org/TR/2011/REC-CSS2-20110607/colors.html#propdef-background-image
 * @spec http://www.w3.org/TR/2008/CR-css-mobile-20081210/#properties
 */
public class CssBackgroundImage extends org.w3c.css.properties.css.CssBackgroundImage {

	public CssValue url = null;


	public static boolean checkMatchingIdent(CssIdent ident) {
		return none.equals(ident);
	}

	/**
	 * Create a new CssBackgroundImage
	 */
	public CssBackgroundImage() {
		url = none;
	}

	/**
	 * Creates a new CssBackgroundImage
	 *
	 * @param ac         The context
	 * @param expression The expression for this property
	 * @param check      if count check must be performed
	 * @throws org.w3c.css.util.InvalidParamException
	 *          Values are incorrect
	 */
	public CssBackgroundImage(ApplContext ac, CssExpression expression,
							  boolean check) throws InvalidParamException {

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

		setByUser();

		CssValue val = expression.getValue();
		switch (val.getType()) {
			case CssTypes.CSS_URL:
				url = val;
				break;
			case CssTypes.CSS_IDENT:
				if (inherit.equals(val)) {
					url = inherit;
					break;
				}
				if (none.equals(val)) {
					url = none;
					break;
				}
			default:
				throw new InvalidParamException("value", val,
						getPropertyName(), ac);
		}
		expression.next();
	}

	public CssBackgroundImage(ApplContext ac, CssExpression expression)
			throws InvalidParamException {
		this(ac, expression, false);
	}

	/**
	 * Returns the value of this property
	 */
	public Object get() {
		return url;
	}

	/**
	 * Returns true if this property is "softly" inherited
	 * e.g. his value equals inherit
	 */
	public boolean isSoftlyInherited() {
		return (url == inherit);
	}

	/**
	 * Returns a string representation of the object.
	 */
	public String toString() {
		return url.toString();
	}


	/**
	 * 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.image != null) {
			style.addRedefinitionWarning(ac, this);
		}
		cssBackground.image = this;
	}

	/**
	 * 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).getBackgroundImage();
		} else {
			return ((Css1Style) style).cssBackground.image;
		}
	}

	/**
	 * Compares two properties for equality.
	 *
	 * @param property The other property.
	 */
	public boolean equals(CssProperty property) {
		return ((property == null && url == null)
				|| (property instanceof CssBackgroundImage &&
				url != null &&
				url.equals(((CssBackgroundImage) property).url)));
	}

	/**
	 * 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 (url == none);
	}

}

--- NEW FILE: CssBackgroundColor.java ---
// $Id: CssBackgroundColor.java,v 1.1 2012/11/02 14:14:13 ylafon Exp $
// Author: Jean-Guilhem Rouel
// (c) COPYRIGHT MIT, ERCIM and Keio, 2005.
// Please first read the full copyright statement in file COPYRIGHT.html
package org.w3c.css.properties.mobile;

import org.w3c.css.util.ApplContext;
import org.w3c.css.util.InvalidParamException;
import org.w3c.css.values.CssExpression;
import org.w3c.css.values.CssTypes;
import org.w3c.css.values.CssValue;

/**
 * @spec http://www.w3.org/TR/2008/CR-css-mobile-20081210/#properties
 * @spec http://www.w3.org/TR/2011/REC-CSS2-20110607/colors.html#propdef-background-color
 */
public class CssBackgroundColor extends org.w3c.css.properties.css.CssBackgroundColor {

	public CssValue color;

	/**
	 * Create a new CssBackgroundColor
	 */
	public CssBackgroundColor() {
		color = transparent;
	}

	/**
	 * Create a new CssBackgroundColor
	 *
	 * @param expression The expression for this property
	 * @throws org.w3c.css.util.InvalidParamException
	 *          Values are incorrect
	 */
	public CssBackgroundColor(ApplContext ac, CssExpression expression,
							  boolean check) throws InvalidParamException {

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

		setByUser();
		CssValue val = expression.getValue();

		switch (val.getType()) {
			case CssTypes.CSS_HASH_IDENT:
				org.w3c.css.values.CssColor c = new org.w3c.css.values.CssColor();
				c.setShortRGBColor(val.toString(), ac);
				setColor(c);
				break;
			case CssTypes.CSS_COLOR:
				setColor(val);
				break;
			case CssTypes.CSS_IDENT:
				if (transparent.equals(val)) {
					setColor(transparent);
					break;
				}
				if (inherit.equals(val)) {
					setColor(inherit);
					break;
				}
				setColor(new org.w3c.css.values.CssColor(ac,
						(String) val.get()));
				break;
			default:
				throw new InvalidParamException("value", val.toString(),
						getPropertyName(), ac);
		}
		expression.next();
	}

	public CssBackgroundColor(ApplContext ac, CssExpression expression)
			throws InvalidParamException {
		this(ac, expression, false);
	}

	/**
	 * @param color The color to set.
	 */
	public void setColor(CssValue color) {
		this.color = color;
	}

	/**
	 * Returns the value of this property
	 */
	public Object get() {
		return color;
	}

	/**
	 * Returns the color
	 */
	public final CssValue getColor() {
		return color;
	}

	/**
	 * Returns true if this property is "softly" inherited
	 * e.g. his value equals inherit
	 */
	public boolean isSoftlyInherited() {
		return color.equals(inherit);
	}

	/**
	 * Returns a string representation of the object.
	 */
	public String toString() {
		if (color != null) {
			return color.toString();
		}
		return "";
	}

	/**
	 * 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 color == transparent;
	}
}

Received on Friday, 2 November 2012 14:14:18 UTC