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

2002/css-validator/org/w3c/css/properties/css1 CssTextAlign.java,1.5,1.6

From: Yves Lafon via cvs-syncmail <cvsmail@w3.org>
Date: Mon, 03 Sep 2012 15:05:45 +0000
To: www-validator-cvs@w3.org
Message-Id: <E1T8YDh-0004Gd-Lg@lionel-hutz.w3.org>
Update of /sources/public/2002/css-validator/org/w3c/css/properties/css1
In directory hutz:/tmp/cvs-serv16342/css1

Modified Files:
	CssTextAlign.java 
Log Message:
reimpl of text-ident

Index: CssTextAlign.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/properties/css1/CssTextAlign.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- CssTextAlign.java	5 Jan 2010 13:49:45 -0000	1.5
+++ CssTextAlign.java	3 Sep 2012 15:05:43 -0000	1.6
@@ -1,219 +1,84 @@
-//
 // $Id$
-// From Philippe Le Hegaret (Philippe.Le_Hegaret@sophia.inria.fr)
+// Author: Yves Lafon <ylafon@w3.org>
 //
-// (c) COPYRIGHT MIT and INRIA, 1997.
+// (c) COPYRIGHT MIT, ERCIM and Keio University, 2012.
 // Please first read the full copyright statement in file COPYRIGHT.html
 package org.w3c.css.properties.css1;
 
-import org.w3c.css.parser.CssStyle;
-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;
 import org.w3c.css.values.CssIdent;
-import org.w3c.css.values.CssString;
+import org.w3c.css.values.CssTypes;
 import org.w3c.css.values.CssValue;
 
 /**
- *   <H4>
- *     <A NAME="text-align">5.4.6 &nbsp;&nbsp; 'text-align'</A>
- *   </H4>
- *   <P>
- *   <EM>Value:</EM> left | right | center | justify<BR>
- *   <EM>Initial:</EM> UA specific<BR>
- *   <EM>Applies to:</EM> block-level elements<BR>
- *   <EM>Inherited:</EM> yes<BR>
- *   <EM>Percentage values:</EM> N/A<BR>
- *   <P>
- *   This property describes how text is aligned within the element. The actual
- *   justification algorithm used is UA and human language dependent.
- *   <P>
- *   Example:
- *   <PRE>
- *   DIV.center { text-align: center }
- * </PRE>
- *   <P>
- *   Since 'text-align' inherits, all block-level elements inside the 'DIV' element
- *   with 'CLASS=center' will be centered. Note that alignments are relative to
- *   the width of the element, not the canvas. If 'justify' is not supported,
- *   the UA will supply a replacement. Typically, this will be 'left' for western
- *   languages.
- * @version $Revision$
+ * @spec http://www.w3.org/TR/2008/REC-CSS1-20080411/#text-align
  */
-public class CssTextAlign extends CssProperty
-        implements CssTextPropertiesConstants {
-
-    int value;
-    CssValue valueString;
-
-    private static int[] hash_values;
-
-    static CssIdent start = new CssIdent("start");
-    static CssIdent end = new CssIdent("end");
+public class CssTextAlign extends org.w3c.css.properties.css.CssTextAlign {
 
-    /**
-     * Create a new CssTextAlign
-     */
-    public CssTextAlign() {
-	// depends on user agent and writing direction
-    }
+	private static CssIdent[] allowed_values;
 
-    /**
-     * Create a new CssTextAlign
-     * @param expression The expression for this property
-     * @exception InvalidParamException Values are incorrect
-     */
-    public CssTextAlign(ApplContext ac, CssExpression expression, boolean check)
-    	throws InvalidParamException {
+	static {
+		String[] _allowed_values = {"left", "right", "center", "justify"};
 
-	if(check && expression.getCount() > 1) {
-	    throw new InvalidParamException("unrecognize", ac);
+		allowed_values = new CssIdent[_allowed_values.length];
+		int i = 0;
+		for (String s : _allowed_values) {
+			allowed_values[i++] = CssIdent.getIdent(s);
+		}
 	}
 
-	CssValue val = expression.getValue();
-	int hash = val.hashCode();
-
-	setByUser();
-
-	if (val.equals(inherit)) {
-	    valueString = inherit;
-	    expression.next();
-	    return;
-	} else if (val instanceof CssString) {
-	    valueString = val;
-	    expression.next();
-	    return;
-	} else if (val instanceof CssIdent) {
-	    for (int i = 0; i < TEXTALIGN.length; i++) {
-		if (hash_values[i] == hash) {
-		    value = i;
-		    expression.next();
-		    if (val.equals(start) || val.equals(end)) {
-			ac.getFrame().addWarning("xsl", val.toString());
-		    }
-		    return;
+	public static CssIdent getMatchingIdent(CssIdent ident) {
+		for (CssIdent id : allowed_values) {
+			if (id.equals(ident)) {
+				return id;
+			}
 		}
-	    }
+		return null;
 	}
 
-	throw new InvalidParamException("value", val.toString(), getPropertyName(), ac);
-    }
-
-    public CssTextAlign(ApplContext ac, CssExpression expression)
-	throws InvalidParamException {
-	this(ac, expression, false);
-    }
-
-    /**
-     * @return Returns the value.
-     */
-    public int getValue() {
-        return value;
-    }
-
-    /**
-     * @param value The value to set.
-     */
-    public void setValue(int value) {
-        this.value = value;
-    }
-
-    /**
-     * @return Returns the valueString.
-     */
-    public CssValue getValueString() {
-        return valueString;
-    }
-
-    /**
-     * @param valueString The valueString to set.
-     */
-    public void setValueString(CssValue valueString) {
-        this.valueString = valueString;
-    }
-
-    /**
-     * Returns the value of this property
-     */
-    public Object get() {
-	if (valueString != null) {
-	    return valueString;
-	} else {
-	    return TEXTALIGN[value];
+	/**
+	 * Create a new CssTextAlign
+	 */
+	public CssTextAlign() {
 	}
-    }
 
-    /**
-     * Returns the name of this property
-     */
-    public String getPropertyName() {
-	return "text-align";
-    }
-
-    /**
-     * Returns true if this property is "softly" inherited
-     * e.g. his value equals inherit
-     */
-    public boolean isSoftlyInherited() {
-	return valueString == inherit;
-    }
-
-    /**
-     * Returns a string representation of the object.
-     */
-    public String toString() {
-	if (valueString != null) {
-	    return valueString.toString();
-	} else {
-	    return TEXTALIGN[value];
-	}
-    }
+	/**
+	 * Creates a new CssTextAlign
+	 *
+	 * @param expression The expression for this property
+	 * @throws org.w3c.css.util.InvalidParamException
+	 *          Expressions are incorrect
+	 */
+	public CssTextAlign(ApplContext ac, CssExpression expression, boolean check)
+			throws InvalidParamException {
+		setByUser();
+		CssValue val = expression.getValue();
 
-    /**
-     * Add this property to the CssStyle.
-     *
-     * @param style The CssStyle
-     */
-    public void addToStyle(ApplContext ac, CssStyle style) {
-	Css1Style style0 = (Css1Style) style;
-	if (style0.cssTextAlign != null)
-	    style0.addRedefinitionWarning(ac, this);
-	style0.cssTextAlign = this;
-    }
+		if (check && expression.getCount() > 1) {
+			throw new InvalidParamException("unrecognize", ac);
+		}
 
-    /**
-     * 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).getTextAlign();
-	} else {
-	    return ((Css1Style) style).cssTextAlign;
+		if (val.getType() != CssTypes.CSS_IDENT) {
+			throw new InvalidParamException("value",
+					expression.getValue(),
+					getPropertyName(), ac);
+		}
+		// ident, so inherit, or allowed value
+		val = getMatchingIdent((CssIdent) val);
+		if (val == null) {
+			throw new InvalidParamException("value",
+					expression.getValue(),
+					getPropertyName(), ac);
+		}
+		value = val;
+		expression.next();
 	}
-    }
 
-    /**
-     * Compares two properties for equality.
-     *
-     * @param value The other property.
-     */
-    public boolean equals(CssProperty property) {
-	if (valueString != null) {
-	    return (property instanceof CssTextAlign
-  	    && valueString.equals(((CssTextAlign) property).valueString));
-	} else {
-	    return (property instanceof CssTextAlign
-		    && value == ((CssTextAlign) property).value);
+	public CssTextAlign(ApplContext ac, CssExpression expression)
+			throws InvalidParamException {
+		this(ac, expression, false);
 	}
-    }
-
-    static {
-	hash_values = new int[TEXTALIGN.length];
-	for (int i=0; i<TEXTALIGN.length; i++)
-	    hash_values[i] = TEXTALIGN[i].hashCode();
-    }
 }
+
Received on Monday, 3 September 2012 15:05:59 UTC

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