W3C home > Mailing lists > Public > www-validator-cvs@w3.org > March 2008

2002/css-validator/org/w3c/css/values CssTypes.java,NONE,1.1 ATSCColor.java,1.6,1.7 CssAngle.java,1.6,1.7 CssColor.java,1.12,1.13 CssColorCSS1.java,1.9,1.10 CssColorCSS2.java,1.10,1.11 CssColorCSS21.java,1.3,1.4 CssDate.java,1.3,1.4 CssExpression.java,1.5,1.6 CssFrequency.java,1.5,1.6 CssIdent.java,1.6,1.7 CssLength.java,1.5,1.6 CssNumber.java,1.6,1.7 CssPercentage.java,1.5,1.6 CssResolution.java,1.3,1.4 CssString.java,1.5,1.6 CssTime.java,1.5,1.6 CssURL.java,1.5,1.6 CssUnicodeRange.java,1.4,1.5 CssValue.java,1.5,1.6 RGB.java,1.5,1.6

From: Yves Lafon via cvs-syncmail <cvsmail@w3.org>
Date: Tue, 25 Mar 2008 18:30:14 +0000
To: www-validator-cvs@w3.org
Message-Id: <E1JeDuY-0007fA-9a@lionel-hutz.w3.org>

Update of /sources/public/2002/css-validator/org/w3c/css/values
In directory hutz:/tmp/cvs-serv29386

Modified Files:
	ATSCColor.java CssAngle.java CssColor.java CssColorCSS1.java 
	CssColorCSS2.java CssColorCSS21.java CssDate.java 
	CssExpression.java CssFrequency.java CssIdent.java 
	CssLength.java CssNumber.java CssPercentage.java 
	CssResolution.java CssString.java CssTime.java CssURL.java 
	CssUnicodeRange.java CssValue.java RGB.java 
Added Files:
	CssTypes.java 
Log Message:
Various bug fixes + getTypes for more readable switch statements in some other constructions

Index: CssResolution.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/values/CssResolution.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- CssResolution.java	8 Sep 2005 12:24:10 -0000	1.3
+++ CssResolution.java	25 Mar 2008 18:30:11 -0000	1.4
@@ -24,6 +24,12 @@
  */
 public class CssResolution extends CssValue {
 
+    public static final int type = CssTypes.CSS_RESOLUTION;
+    
+    public final int getType() {
+	return type;
+    }
+
   /**
    * Create a new CssResolution
    */

Index: CssColorCSS2.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/values/CssColorCSS2.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- CssColorCSS2.java	15 May 2007 06:06:45 -0000	1.10
+++ CssColorCSS2.java	25 Mar 2008 18:30:11 -0000	1.11
@@ -6,7 +6,7 @@
 // Please first read the full copyright statement in file COPYRIGHT.html
 package org.w3c.css.values;
 
-import java.util.Hashtable;
+import java.util.HashMap;
 
 import org.w3c.css.util.ApplContext;
 import org.w3c.css.util.InvalidParamException;
@@ -161,11 +161,6 @@
  */
 public class CssColorCSS2 extends CssColor {
 
-    Object color;
-    RGB rgb;
-    static Hashtable definedColors;
-    static CssIdent inherit = new CssIdent("inherit");
-
     /**
      * Create a new CssColorCSS2.
      */
@@ -185,171 +180,6 @@
     }
 
     /**
-     * Set the value from a defined color RBG.
-     *
-     * @param s the string representation of the color.
-     * @exception InvalidParamException the color is incorrect.
-     */
-    public void set(String s, ApplContext ac)  throws InvalidParamException {
-	if (s.startsWith("#")) {
-	    setShortRGBColor(s.toLowerCase(), ac);
-	} else {
-	    setIdentColor(s, ac);
-	}
-    }
-
-    /**
-     * Return the internal value.
-     */
-    public Object get() {
-	if (color != null) {
-	    if (color == inherit) {
-		return null;
-	    } else {
-		return color;
-	    }
-	} else {
-	    return rgb.r;
-	}
-    }
-
-    /**
-     * Returns <code>true</code> if the internal value is the default value
-     * (e.g. 'inherited').
-     */
-    public boolean isDefault() {
-	return color == inherit;
-    }
-
-    /**
-     * Returns a string representation of the object.
-     */
-    public String toString() {
-	if (color != null) {
-	    if (color == inherit) {
-		return inherit.toString();
-	    } else {
-		return color.toString();
-	    }
-	} else {
-	    return rgb.toString();
-	}
-    }
-
-    /**
-     * Parse a RGB color.
-     * format rgb(<num>%?, <num>%?, <num>%?)
-     */
-    public void setRGBColor(CssExpression exp, ApplContext ac)
-  	    throws InvalidParamException {
-	CssValue val = exp.getValue();
-	char op = exp.getOperator();
-	color = null;
-	rgb = new RGB();
-
-	if (val == null || op != COMMA) {
-	    throw new InvalidParamException("invalid-color", ac);
-	}
-
-	if (val instanceof CssNumber) {
-	    CssNumber number = (CssNumber) val;
-	    rgb.r = clippedIntValue(number.getInt(), ac);
-	    rgb.setPercent(false);
-	} else if (val instanceof CssPercentage) {
-	    rgb.r = clippedPercentValue(((Float) val.get()).floatValue(), ac);
-	    rgb.setPercent(true);
-	} else {
-	    throw new InvalidParamException("rgb", val, ac);
-	}
-
-	exp.next();
-	val = exp.getValue();
-	op = exp.getOperator();
-
-	if (val == null || op != COMMA) {
-	    throw new InvalidParamException("invalid-color", ac);
-	}
-
-	if (val instanceof CssNumber) {
-	    CssNumber number = (CssNumber) val;
-	    if (rgb.isPercent()) {
-		throw new InvalidParamException("percent", val, ac);
-	    }
-	    rgb.g = clippedIntValue(number.getInt(), ac);
-	} else if (val instanceof CssPercentage) {
-	    if (!rgb.isPercent()) {
-		throw new InvalidParamException("integer", val, ac);
-	    }
-	    rgb.g = clippedPercentValue(((Float) val.get()).floatValue(), ac);
-	} else {
-	    throw new InvalidParamException("rgb", val, ac);
-	}
-
-	exp.next();
-	val = exp.getValue();
-	op = exp.getOperator();
-
-	if (val == null) {
-	    throw new InvalidParamException("invalid-color", ac);
-	}
-
-	if (val instanceof CssNumber) {
-	    CssNumber number = (CssNumber) val;
-	    if (rgb.isPercent()) {
-		throw new InvalidParamException("percent", val, ac);
-	    }
-	    rgb.b = clippedIntValue(number.getInt(), ac);
-	} else if (val instanceof CssPercentage) {
-	    if (!rgb.isPercent()) {
-		throw new InvalidParamException("integer", val, ac);
-	    }
-	    rgb.b = clippedPercentValue(((Float) val.get()).floatValue(), ac);
-	} else {
-	    throw new InvalidParamException("rgb", val, ac);
-	}
-
-	exp.next();
-	if (exp.getValue() != null) {
-	    throw new InvalidParamException("rgb", exp.getValue(), ac);
-	}
-    }
-
-    /**
-     * Parse a RGB color.
-     * format #(3-6)<hexnum>
-     */
-    private void setShortRGBColor(String s, ApplContext ac)
-	    throws InvalidParamException {
-	int r;
-	int g;
-	int b;
-
-	rgb = new RGB();
-	color = null;
-	s = s.substring(1);
-
-	if (s.length() != 3 && s.length() != 6) {
-	    throw new InvalidParamException("rgb", s, ac);
-	}
-	if (s.length() == 3) {
-	    String sh = s.substring(0,1);
-	    r = Integer.parseInt(sh+sh, 16);
-	    sh = s.substring(1,2);
-	    g = Integer.parseInt(sh+sh, 16);
-	    sh = s.substring(2,3);
-	    b = Integer.parseInt(sh+sh, 16);
-	} else {
-	    r = Integer.parseInt(s.substring(0,2), 16);
-	    g = Integer.parseInt(s.substring(2,4), 16);
-	    b = Integer.parseInt(s.substring(4,6), 16);
-	}
-	rgb.r = new Integer(r);
-	rgb.g = new Integer(g);
-	rgb.b = new Integer(b);
-	rgb.output = "#" + s;
-    }
-
-    /**
      * Parse an ident color.
      */
     private void setIdentColor(String s, ApplContext ac)
@@ -375,125 +205,40 @@
 	throw new InvalidParamException("value", s, "color", ac);
     }
 
-    private static Integer clippedIntValue(int rgb, ApplContext ac) {
-	if (rgb < 0 || rgb > 255) {
-	    ac.getFrame().addWarning("out-of-range", Util.displayFloat(rgb));
-	    return new Integer((rgb<0)?0:255);
-	}
-	else return(new Integer(rgb));
-    }
-
-    private static Float clippedPercentValue(float p, ApplContext ac) {
-	if (p < 0. || p > 100.) {
-	    ac.getFrame().addWarning("out-of-range", Util.displayFloat(p));
-	    return new Float((p<0.)?0.:100.);
-	}
-	else return(new Float(p));
-    }
-
-    /**
-     * Compares two values for equality.
-     *
-     * @param value The other value.
-     */
-    public boolean equals(Object cssColor) {
-	return ((cssColor instanceof CssColorCSS2) &&
-		((color != null && color.equals(((CssColorCSS2) cssColor).color))
-		 || ((color == null)
-		     && (rgb != null)
-		     && (((CssColorCSS2) cssColor).rgb != null)
-		     && (rgb.r.equals(((CssColorCSS2) cssColor).rgb.r)
-			 && rgb.g.equals(((CssColorCSS2) cssColor).rgb.g)
-			 && rgb.b.equals(((CssColorCSS2) cssColor).rgb.b)))));
-    }
-
-    /**
-     * Gets the red component of this color.
-     */
-    public Object getRed() {
-	return rgb.r;
-    }
-
-    /**
-     * Gets the green component of this color.
-     */
-    public Object getGreen() {
-	return rgb.g;
-    }
-
-    /**
-     * Gets the blue component of this color.
-     */
-    public Object getBlue() {
-	return rgb.b;
-    }
-
     static {
-	definedColors = new Hashtable();
+	definedColors = new HashMap<String,Object>();
 	definedColors.put("black",
-			  new RGB(new Integer(0),
-				  new Integer(0),
-				  new Integer(0)));
+			  new RGB(0, 0, 0));
 	definedColors.put("silver",
-			  new RGB(new Integer(192),
-				  new Integer(192),
-				  new Integer(192)));
+			  new RGB(192, 192, 192));
 	definedColors.put("gray",
-			  new RGB(new Integer(128),
-				  new Integer(128),
-				  new Integer(128)));
+			  new RGB(128, 128, 128));
 	definedColors.put("white",
-			  new RGB(new Integer(255),
-				  new Integer(255),
-				  new Integer(255)));
+			  new RGB(255, 255, 255));
 	definedColors.put("maroon",
-			  new RGB(new Integer(128),
-				  new Integer(0),
-				  new Integer(0)));
+			  new RGB(128, 0, 0));
 	definedColors.put("red",
-			  new RGB(new Integer(255),
-				  new Integer(0),
-				  new Integer(0)));
+			  new RGB(255, 0, 0));
 	definedColors.put("purple",
-			  new RGB(new Integer(128),
-				  new Integer(0),
-				  new Integer(128)));
+			  new RGB(128, 0, 128));
 	definedColors.put("fuchsia",
-			  new RGB(new Integer(255),
-				  new Integer(0),
-				  new Integer(255)));
+			  new RGB(255, 0, 255));
 	definedColors.put("green",
-			  new RGB(new Integer(0),
-				  new Integer(128),
-				  new Integer(0)));
+			  new RGB(0, 128, 0));
 	definedColors.put("lime",
-			  new RGB(new Integer(0),
-				  new Integer(255),
-				  new Integer(0)));
+			  new RGB(0, 255, 0));
 	definedColors.put("olive",
-			  new RGB(new Integer(128),
-				  new Integer(128),
-				  new Integer(0)));
+			  new RGB(128, 128, 0));
 	definedColors.put("yellow",
-			  new RGB(new Integer(255),
-				  new Integer(255),
-				  new Integer(0)));
+			  new RGB(255, 255, 0));
 	definedColors.put("navy",
-			  new RGB(new Integer(0),
-				  new Integer(0),
-				  new Integer(128)));
+			  new RGB(0, 0, 128));
 	definedColors.put("blue",
-			  new RGB(new Integer(0),
-				  new Integer(0),
-				  new Integer(255)));
+			  new RGB(0, 0, 255));
 	definedColors.put("teal",
-			  new RGB(new Integer(0),
-				  new Integer(128),
-				  new Integer(128)));
+			  new RGB(0, 128, 128));
 	definedColors.put("aqua",
-			  new RGB(new Integer(0),
-				  new Integer(255),
-				  new Integer(255)));
+			  new RGB(0, 255, 255));
         definedColors.put("activeborder", "ActiveBorder");
         definedColors.put("activecaption", "ActiveCaption");
         definedColors.put("appworkspace", "AppWorkspace");

Index: CssColorCSS1.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/values/CssColorCSS1.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- CssColorCSS1.java	15 May 2007 06:06:45 -0000	1.9
+++ CssColorCSS1.java	25 Mar 2008 18:30:11 -0000	1.10
@@ -6,7 +6,7 @@
 // Please first read the full copyright statement in file COPYRIGHT.html
 package org.w3c.css.values;
 
-import java.util.Hashtable;
+import java.util.HashMap;
 
 import org.w3c.css.util.ApplContext;
 import org.w3c.css.util.InvalidParamException;
@@ -161,11 +161,6 @@
  */
 public class CssColorCSS1 extends CssColor {
 
-    Object color;
-    RGB rgb;
-    static Hashtable definedColors;
-    static CssIdent inherit = new CssIdent("inherit");
-
     /**
      * Create a new CssColorCSS1
      */
@@ -185,171 +180,6 @@
     }
 
     /**
-     * Set the value from a defined color RBG.
-     *
-     * @param s the string representation of the color.
-     * @exception InvalidParamException the color is incorrect.
-     */
-    public void set(String s, ApplContext ac)  throws InvalidParamException {
-	if (s.startsWith("#")) {
-	    setShortRGBColor(s.toLowerCase(), ac);
-	} else {
-	    setIdentColor(s, ac);
-	}
-    }
-
-    /**
-     * Return the internal value.
-     */
-    public Object get() {
-	if (color != null) {
-	    if (color == inherit) {
-		return null;
-	    } else {
-		return color;
-	    }
-	} else {
-	    return rgb.r;
-	}
-    }
-
-    /**
-     * Returns <code>true</code> if the internal value is the default value
-     * (e.g. 'inherited').
-     */
-    public boolean isDefault() {
-	return color == inherit;
-    }
-
-    /**
-     * Returns a string representation of the object.
-     */
-    public String toString() {
-	if (color != null) {
-	    if (color == inherit) {
-		return inherit.toString();
-	    } else {
-		return color.toString();
-	    }
-	} else {
-	    return rgb.toString();
-	}
-    }
-
-    /**
-     * Parse a RGB color.
-     * format rgb(<num>%?, <num>%?, <num>%?)
-     */
-    public void setRGBColor(CssExpression exp, ApplContext ac)
-  	    throws InvalidParamException {
-	CssValue val = exp.getValue();
-	char op = exp.getOperator();
-	color = null;
-	rgb = new RGB();
-
-	if (val == null || op != COMMA) {
-	    throw new InvalidParamException("invalid-color", ac);
-	}
-
-	if (val instanceof CssNumber) {
-	    CssNumber number = (CssNumber) val;
-	    rgb.r = clippedIntValue(number.getInt(), ac);
-	    rgb.setPercent(false);
-	} else if (val instanceof CssPercentage) {
-	    rgb.r = clippedPercentValue(((Float) val.get()).floatValue(), ac);
-	    rgb.setPercent(true);
-	} else {
-	    throw new InvalidParamException("rgb", val, ac);
-	}
-
-	exp.next();
-	val = exp.getValue();
-	op = exp.getOperator();
-
-	if (val == null || op != COMMA) {
-	    throw new InvalidParamException("invalid-color", ac);
-	}
-
-	if (val instanceof CssNumber) {
-	    CssNumber number = (CssNumber) val;
-	    if (rgb.isPercent()) {
-		throw new InvalidParamException("percent", val, ac);
-	    }
-	    rgb.g = clippedIntValue(number.getInt(), ac);
-	} else if (val instanceof CssPercentage) {
-	    if (!rgb.isPercent()) {
-		throw new InvalidParamException("integer", val, ac);
-	    }
-	    rgb.g = clippedPercentValue(((Float) val.get()).floatValue(), ac);
-	} else {
-	    throw new InvalidParamException("rgb", val, ac);
-	}
-
-	exp.next();
-	val = exp.getValue();
-	op = exp.getOperator();
-
-	if (val == null) {
-	    throw new InvalidParamException("invalid-color", ac);
-	}
-
-	if (val instanceof CssNumber) {
-	    if (rgb.isPercent()) {
-		throw new InvalidParamException("percent", val, ac);
-	    }
-	    rgb.b = clippedIntValue(((Float) val.get()).intValue(), ac);
-	} else if (val instanceof CssPercentage) {
-	    CssNumber number = (CssNumber) val;
-	    if (rgb.isPercent()) {
-		throw new InvalidParamException("percent", val, ac);
-	    }
-	    rgb.b = clippedPercentValue(number.getInt(), ac);
-	} else {
-	    throw new InvalidParamException("rgb", val, ac);
-	}
-
-	exp.next();
-	if (exp.getValue() != null) {
-	    throw new InvalidParamException("rgb", exp.getValue(), ac);
-	}
-    }
-
-    /**
-     * Parse a RGB color.
-     * format #(3-6)<hexnum>
-     */
-    private void setShortRGBColor(String s, ApplContext ac)
-	    throws InvalidParamException {
-	int r;
-	int g;
-	int b;
-
-	rgb = new RGB();
-	color = null;
-	s = s.substring(1);
-
-	if (s.length() != 3 && s.length() != 6) {
-	    throw new InvalidParamException("rgb", s, ac);
-	}
-	if (s.length() == 3) {
-	    String sh = s.substring(0,1);
-	    r = Integer.parseInt(sh+sh, 16);
-	    sh = s.substring(1,2);
-	    g = Integer.parseInt(sh+sh, 16);
-	    sh = s.substring(2,3);
-	    b = Integer.parseInt(sh+sh, 16);
-	} else {
-	    r = Integer.parseInt(s.substring(0,2), 16);
-	    g = Integer.parseInt(s.substring(2,4), 16);
-	    b = Integer.parseInt(s.substring(4,6), 16);
-	}
-	rgb.r = new Integer(r);
-	rgb.g = new Integer(g);
-	rgb.b = new Integer(b);
-	rgb.output = "#" + s;
-    }
-
-    /**
      * Parse an ident color.
      */
     private void setIdentColor(String s, ApplContext ac)
@@ -375,125 +205,40 @@
 	throw new InvalidParamException("value", s, "color", ac);
     }
 
-    private static Integer clippedIntValue(int rgb, ApplContext ac) {
-	if (rgb < 0 || rgb > 255) {
-	    ac.getFrame().addWarning("out-of-range", Util.displayFloat(rgb));
-	    return new Integer((rgb<0)?0:255);
-	}
-	else return(new Integer(rgb));
-    }
-
-    private static Float clippedPercentValue(float p, ApplContext ac) {
-	if (p < 0. || p > 100.) {
-	    ac.getFrame().addWarning("out-of-range", Util.displayFloat(p));
-	    return new Float((p<0.)?0.:100.);
-	}
-	else return(new Float(p));
-    }
-
-    /**
-     * Compares two values for equality.
-     *
-     * @param value The other value.
-     */
-    public boolean equals(Object cssColor) {
-	return ((cssColor instanceof CssColorCSS1) &&
-		((color != null && color.equals(((CssColorCSS1) cssColor).color))
-		 || ((color == null)
-		     && (rgb != null)
-		     && (((CssColorCSS1) cssColor).rgb != null)
-		     && (rgb.r.equals(((CssColorCSS1) cssColor).rgb.r)
-			 && rgb.g.equals(((CssColorCSS1) cssColor).rgb.g)
-			 && rgb.b.equals(((CssColorCSS1) cssColor).rgb.b)))));
-    }
-
-    /**
-     * Gets the red component of this color.
-     */
-    public Object getRed() {
-	return rgb.r;
-    }
-
-    /**
-     * Gets the green component of this color.
-     */
-    public Object getGreen() {
-	return rgb.g;
-    }
-
-    /**
-     * Gets the blue component of this color.
-     */
-    public Object getBlue() {
-	return rgb.b;
-    }
-
     static {
-	definedColors = new Hashtable();
+	definedColors = new HashMap<String,Object>();
 	definedColors.put("black",
-			  new RGB(new Integer(0),
-				  new Integer(0),
-				  new Integer(0)));
+			  new RGB(0, 0, 0));
 	definedColors.put("silver",
-			  new RGB(new Integer(192),
-				  new Integer(192),
-				  new Integer(192)));
+			  new RGB(192, 192, 192));
 	definedColors.put("gray",
-			  new RGB(new Integer(128),
-				  new Integer(128),
-				  new Integer(128)));
+			  new RGB(128, 128, 128));
 	definedColors.put("white",
-			  new RGB(new Integer(255),
-				  new Integer(255),
-				  new Integer(255)));
+			  new RGB(255, 255, 255));
 	definedColors.put("maroon",
-			  new RGB(new Integer(128),
-				  new Integer(0),
-				  new Integer(0)));
+			  new RGB(128, 0, 0));
 	definedColors.put("red",
-			  new RGB(new Integer(255),
-				  new Integer(0),
-				  new Integer(0)));
+			  new RGB(255, 0, 0));
 	definedColors.put("purple",
-			  new RGB(new Integer(128),
-				  new Integer(0),
-				  new Integer(128)));
+			  new RGB(128, 0, 128));
 	definedColors.put("fuchsia",
-			  new RGB(new Integer(255),
-				  new Integer(0),
-				  new Integer(255)));
+			  new RGB(255, 0, 255));
 	definedColors.put("green",
-			  new RGB(new Integer(0),
-				  new Integer(128),
-				  new Integer(0)));
+			  new RGB(0, 128, 0));
 	definedColors.put("lime",
-			  new RGB(new Integer(0),
-				  new Integer(255),
-				  new Integer(0)));
+			  new RGB(0, 255, 0));
 	definedColors.put("olive",
-			  new RGB(new Integer(128),
-				  new Integer(128),
-				  new Integer(0)));
+			  new RGB(128, 128, 0));
 	definedColors.put("yellow",
-			  new RGB(new Integer(255),
-				  new Integer(255),
-				  new Integer(0)));
+			  new RGB(255, 255, 0));
 	definedColors.put("navy",
-			  new RGB(new Integer(0),
-				  new Integer(0),
-				  new Integer(128)));
+			  new RGB(0, 0, 128));
 	definedColors.put("blue",
-			  new RGB(new Integer(0),
-				  new Integer(0),
-				  new Integer(255)));
+			  new RGB(0, 0, 255));
 	definedColors.put("teal",
-			  new RGB(new Integer(0),
-				  new Integer(128),
-				  new Integer(128)));
+			  new RGB(0, 128, 128));
 	definedColors.put("aqua",
-			  new RGB(new Integer(0),
-				  new Integer(255),
-				  new Integer(255)));
+			  new RGB(0, 255, 255));
     }
 
 }

Index: CssURL.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/values/CssURL.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- CssURL.java	14 Sep 2005 15:15:33 -0000	1.5
+++ CssURL.java	25 Mar 2008 18:30:11 -0000	1.6
@@ -48,7 +48,14 @@
  */
 public class CssURL extends CssValue {
 
+    public static final int type = CssTypes.CSS_URL;
+
+    public final int getType() {
+	return type;
+    }
+
     String value;
+    String full = null;
 
     URL base;
 
@@ -79,14 +86,14 @@
 	String urlname = s.substring(4, s.length()-1).trim();
 	this.base = base;
 
-	try {
-	    CssString convert = new CssString();
-	    convert.set(urlname, ac);
-	    value = (String) convert.get();
-	} catch (InvalidParamException e) {
+//	try {
+//	    CssString convert = new CssString();
+//	    convert.set(urlname, ac);
+//	    value = (String) convert.get();
+//	} catch (InvalidParamException e) {
 	    value = urlname;
-	}
-
+	    full = null;
+//	}
 	if (!urlHeading.startsWith("url"))
 	    throw new InvalidParamException("url", s, ac);
     }
@@ -109,7 +116,12 @@
      * Returns a string representation of the object.
      */
     public String toString() {
-	return "url(" + value + ")";
+	if (full != null) {
+	    return full;
+	}
+	StringBuilder sb = new StringBuilder("url(");
+	sb.append(value).append(')');
+	return full = sb.toString();
     }
 
     /**

Index: CssUnicodeRange.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/values/CssUnicodeRange.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- CssUnicodeRange.java	14 Sep 2005 15:15:33 -0000	1.4
+++ CssUnicodeRange.java	25 Mar 2008 18:30:12 -0000	1.5
@@ -14,6 +14,12 @@
  */
 public class CssUnicodeRange extends CssValue {
 
+    public static final int type = CssTypes.CSS_UNICODE_RANGE;
+    
+    public final int getType() {
+	return type;
+    }
+
     String value;
 
     /**

Index: CssValue.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/values/CssValue.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- CssValue.java	14 Sep 2005 15:15:33 -0000	1.5
+++ CssValue.java	25 Mar 2008 18:30:12 -0000	1.6
@@ -14,8 +14,14 @@
  */
 public abstract class CssValue {
 
+    public static int type = CssTypes.CSS_UNKNOWN;
+
     String cssversion;
 
+    public int getType() {
+	return type;
+    }
+    
   /**
    * Set the value of this value.
    *

Index: CssIdent.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/values/CssIdent.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- CssIdent.java	20 Mar 2008 16:51:17 -0000	1.6
+++ CssIdent.java	25 Mar 2008 18:30:11 -0000	1.7
@@ -13,8 +13,14 @@
  */
 public class CssIdent extends CssValue {
 
+    public static final int type = CssTypes.CSS_IDENT;
+    
     private int hashcode = 0;
 
+    public final int getType() {
+	return type;
+    }
+    
     /**
      * Create a new CssIdent
      */
@@ -65,9 +71,19 @@
     }
 
     /**
+     * Compares two values for equality.
+     *
+     * @param value The other value.
+     */
+    public boolean equals(CssIdent value) {
+	return (value.hashCode() == hashCode());
+    }
+
+    /**
      * Returns a hashcode for this ident.
      */
     public int hashCode() {
+	// we cache, as we use toLowerCase and don't store the resulting string
 	if (hashcode == 0) {
 	    hashcode = value.toLowerCase().hashCode();
 	}

Index: CssString.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/values/CssString.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- CssString.java	14 Sep 2005 15:15:33 -0000	1.5
+++ CssString.java	25 Mar 2008 18:30:11 -0000	1.6
@@ -17,8 +17,14 @@
  */
 public class CssString extends CssValue {
 
+    public static final int type = CssTypes.CSS_STRING;
+    
     String value;
 
+    public final int getType() {
+	return type;
+    }
+
     /**
      * Create a new CssString
      */
@@ -40,10 +46,11 @@
      * @exception InvalidParamException The unit is incorrect
      */
     public void set(String s, ApplContext ac) throws InvalidParamException {
-	if (s.indexOf('\'') == -1 &&
-	    s.indexOf('"') == -1) {
-	    throw new InvalidParamException("string", s, ac);
-	}
+//	if (s.indexOf('\'') == -1 &&
+//	    s.indexOf('"') == -1) {
+//	    throw new InvalidParamException("string", s, ac);
+//      }
+// tokenizer is taking care of the validity of the value
 	value = s;
     }
 

Index: CssLength.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/values/CssLength.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- CssLength.java	14 Sep 2005 15:15:33 -0000	1.5
+++ CssLength.java	25 Mar 2008 18:30:11 -0000	1.6
@@ -90,95 +90,102 @@
  */
 public class CssLength extends CssValue {
 
-  /**
-   * Create a new CssLength
-   */
-  public CssLength() {
-    value = defaultValue;
-  }
+    public static final int type = CssTypes.CSS_LENGTH;
+    
+    public final int getType() {
+	return type;
+    }
+    
+    /**
+     * Create a new CssLength
+     */
+    public CssLength() {
+	value = defaultValue;
+    }
 
-  /**
-   * Set the value of this length.
-   *
-   * @param s     the string representation of the length.
-   * @param frame For errors and warnings reports.
-   * @exception InvalidParamException The unit is incorrect
-   */
-  public void set(String s, ApplContext ac) throws InvalidParamException {
-    s = s.toLowerCase();
-    int length = s.length();
-    String unit = s.substring(length-2, length);
-    this.value = new Float(s.substring(0, length-2));
+    /**
+     * Set the value of this length.
+     *
+     * @param s     the string representation of the length.
+     * @param frame For errors and warnings reports.
+     * @exception InvalidParamException The unit is incorrect
+     */
+    public void set(String s, ApplContext ac) throws InvalidParamException {
+	s = s.toLowerCase();
+	int length = s.length();
+	String unit = s.substring(length-2, length);
+	this.value = new Float(s.substring(0, length-2));
 
-    this.unit = 2; // there is no unit by default
+	this.unit = 2; // there is no unit by default
 
-    if (unit.equals("gd") && (cssversion.equals("css2"))) {
-	throw new InvalidParamException("unit", unit, ac);
-    }
+	if (unit.equals("gd") && (cssversion.equals("css2"))) {
+	    throw new InvalidParamException("unit", unit, ac);
+	}
 
-    if (value.floatValue() != 0) {
-      int hash = unit.hashCode();
-      int i = 0;
-      while (i<units.length) {
-	if (hash == hash_units[i]) {
-	  this.unit = i;
-	  return;
+	if (value.floatValue() != 0) {
+	    int hash = unit.hashCode();
+	    int i = 0;
+	    while (i<units.length) {
+		if (hash == hash_units[i]) {
+		    this.unit = i;
+		    return;
+		}
+		i++;
+	    }
+	} else {
+	    return;
 	}
-	i++;
-      }
-    } else {
-      return;
-    }
 
-    throw new InvalidParamException("unit", unit, ac);
-  }
+	throw new InvalidParamException("unit", unit, ac);
+    }
 
-  /**
-   * Returns the current value
-   */
-  public Object get() {
-    return value;
-  }
+    /**
+     * Returns the current value
+     */
+    public Object get() {
+	return value;
+    }
 
-  /**
-   * Returns the current value
-   */
-  public String getUnit() {
-    return units[unit];
-  }
+    /**
+     * Returns the current value
+     */
+    public String getUnit() {
+	return units[unit];
+    }
 
-  /**
-   * Returns a string representation of the object.
-   */
-  public String toString() {
-      if (value.floatValue() != 0) {
-	  return Util.displayFloat(value) + getUnit();
-      } else {
-	  return Util.displayFloat(value);
-      }
-  }
+    /**
+     * Returns a string representation of the object.
+     */
+    public String toString() {
+	if (value.floatValue() != 0) {
+	    return Util.displayFloat(value) + getUnit();
+	} else {
+	    return Util.displayFloat(value);
+	}
+    }
 
-  /**
-   * Compares two values for equality.
-   *
-   * @param value The other value.
-   */
-  public boolean equals(Object value) {
-    return (value instanceof CssLength &&
-	    this.value.equals(((CssLength) value).value) &&
-	     unit == ((CssLength) value).unit);
-  }
+    /**
+     * Compares two values for equality.
+     *
+     * @param value The other value.
+     */
+    public boolean equals(Object value) {
+	return (value instanceof CssLength &&
+		this.value.equals(((CssLength) value).value) &&
+		unit == ((CssLength) value).unit);
+    }
 
-  private Float value;
-  private int unit;
-  private static String[] units = { "mm", "cm", "pt", "pc", "em", "ex", "px", "in", "gd" };
-  private static int[] hash_units;
-  private static Float defaultValue = new Float(0);
+    private Float value;
+    private int unit;
+    private static String[] units = { "mm", "cm", "pt", "pc", "em", 
+				      "ex", "px", "in", "gd" };
+    private static int[] hash_units;
+    private static Float defaultValue = new Float(0);
 
-  static {
-    hash_units = new int[units.length];
-    for (int i=0; i<units.length; i++)
-      hash_units[i] = units[i].hashCode();
-  }
+    static {
+	hash_units = new int[units.length];
+	for (int i=0; i<units.length; i++)
+	    hash_units[i] = units[i].hashCode();
+    }
 }
 

Index: CssColorCSS21.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/values/CssColorCSS21.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- CssColorCSS21.java	15 May 2007 06:06:45 -0000	1.3
+++ CssColorCSS21.java	25 Mar 2008 18:30:11 -0000	1.4
@@ -29,7 +29,9 @@
 	}
     }
 
-    public CssColorCSS21(ApplContext ac, String s) throws InvalidParamException {
+    public CssColorCSS21(ApplContext ac, String s)
+	throws InvalidParamException 
+    {
 	setIdentColor(s, ac);
     }
 
@@ -39,7 +41,6 @@
     private void setIdentColor(String s, ApplContext ac)
 	    throws InvalidParamException {
 	String lower_s = s.toLowerCase();
-
 	int hash = lower_s.hashCode();
 
 	int indexOfColor = searchColor(hash, tableColorHash);

Index: ATSCColor.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/values/ATSCColor.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- ATSCColor.java	15 May 2007 06:06:45 -0000	1.6
+++ ATSCColor.java	25 Mar 2008 18:30:11 -0000	1.7
@@ -6,7 +6,7 @@
 // Please first read the full copyright statement in file COPYRIGHT.html
 package org.w3c.css.values;
 
-import java.util.Hashtable;
+import java.util.HashMap;
 
 import org.w3c.css.util.ApplContext;
 import org.w3c.css.util.InvalidParamException;
@@ -163,7 +163,7 @@
 
     Object color;
     RGBATSC rgb;
-    static Hashtable definedColors;
+    static HashMap<String,Object> definedColors;
     static CssIdent inherit = new CssIdent("inherit");
 
     /**
@@ -471,7 +471,7 @@
     }
 
     static {
-	definedColors = new Hashtable();
+	definedColors = new HashMap<String,Object>();
 	definedColors.put("black",
 			  new RGBATSC(new Integer(0),
 				      new Integer(0),

Index: CssColor.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/values/CssColor.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- CssColor.java	15 May 2007 06:06:45 -0000	1.12
+++ CssColor.java	25 Mar 2008 18:30:11 -0000	1.13
@@ -7,7 +7,7 @@
 
 package org.w3c.css.values;
 
-import java.util.Hashtable;
+import java.util.HashMap;
 import java.util.Vector;
 
 import org.w3c.css.util.ApplContext;
@@ -164,15 +164,20 @@
 public class CssColor extends CssValue
     implements CssColorConstants, CssOperator {
[...1041 lines suppressed...]
-			new Integer(105)));
+		new RGB(105, 105, 105));
 	definedColors.put("lightgray",
-		new RGB(new Integer(211),
-			new Integer(211),
-			new Integer(211)));
+		new RGB(211, 211, 211));
 	definedColors.put("lightslategrey",
-		new RGB(new Integer(119),
-			new Integer(136),
-			new Integer(153)));
+		new RGB(119, 136, 153));
 	definedColors.put("slategrey",
-		new RGB(new Integer(112),
-			new Integer(128),
-			new Integer(144)));
+		new RGB(112, 128, 144));
 	definedColors.put("transparent",
 		new RGBA(new Integer(0),
 			new Integer(0),

Index: CssDate.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/values/CssDate.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- CssDate.java	8 Sep 2005 12:24:10 -0000	1.3
+++ CssDate.java	25 Mar 2008 18:30:11 -0000	1.4
@@ -17,10 +17,16 @@
  * @version $Revision$
  */
 public class CssDate extends CssValue {
+    
+    public static final int type = CssTypes.CSS_DATE;
+    
+    public final int getType() {
+	return type;
+    }
 
-	String day = new String();
-	String month = new String();
-	String year = new String();
+    String day = new String();
+    String month = new String();
+    String year = new String();
 
   /**
    * Create a new CssDate.

Index: CssTime.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/values/CssTime.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- CssTime.java	14 Sep 2005 15:15:33 -0000	1.5
+++ CssTime.java	25 Mar 2008 18:30:11 -0000	1.6
@@ -28,6 +28,12 @@
  */
 public class CssTime extends CssValue {
 
+    public static final int type = CssTypes.CSS_TIME;
+    
+    public final int getType() {
+	return type;
+    }
+
   /**
    * Create a new CssTime.
    */

Index: RGB.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/values/RGB.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- RGB.java	14 Sep 2005 15:15:33 -0000	1.5
+++ RGB.java	25 Mar 2008 18:30:12 -0000	1.6
@@ -16,26 +16,46 @@
 public class RGB {
 
     String output = null;
-    Object r;
-    Object g;
-    Object b;
-
+    int r, g, b;
+    float fr, fg, fb;
+    
     boolean percent = false;
 
     /**
      * @return Returns the percent.
      */
-    public boolean isPercent() {
+    public final boolean isPercent() {
         return percent;
     }
 
     /**
      * @param percent The percent to set.
      */
-    public void setPercent(boolean percent) {
+    public final void setPercent(boolean percent) {
         this.percent = percent;
     }
 
+    public final void setRed(int r) {
+	this.r = r;
+    }
+    public final void setRed(float fr) {
+	this.fr = fr;
+    }
+
+    public final void setGreen(int g) {
+	this.g = g;
+    }
+    public final void setGreen(float gr) {
+	this.fg = fg;
+    }
+
+    public final void setBlue(int b) {
+	this.b = b;
+    }
+    public final void setBlue(float fb) {
+	this.fb = fb;
+    }
+
     /**
      * Create a new RGB
      */
@@ -45,21 +65,54 @@
     /**
      * Create a new RGB with default values
      */
-    public RGB(Object r, Object g, Object b) {
+    public RGB(int r, int g, int b) {
 	this.r = r;
 	this.g = g;
 	this.b = b;
     }
+    
+    public RGB(float fr, float fg, float fb) {
+	this.fr = fr;
+	this.fg = fg;
+	this.fb = fb;
+	percent = true;
+    }
 
+    public boolean equals(RGB other) {
+	if (other != null) {
+	    if (percent) {
+		if (other.percent) {
+		    return ((fr == other.fr) &&
+			    (fg == other.fg) &&
+			    (fb == other.fb));
+		}
+	    } else {
+		if (!other.percent) {
+		    return ((r == other.r) &&
+			    (g == other.g) &&
+			    (b == other.b));		    
+		}
+	    }
+	}
+	return false;
+    }
     /**
      * Returns a string representation of the object.
      */
     public String toString() {
 	if (output == null) {
-	    String unit = (isPercent()) ? "%" : "";
-	    return "rgb(" + r + unit + ", " + g + unit + ", " + b + unit + ")";
-	} else {
-	    return output;
-	}
+	    StringBuilder sb = new StringBuilder("rgb(");
+	    if (isPercent()) {
+		sb.append(fr).append("%, ");
+		sb.append(fg).append("%, ");
+		sb.append(fb).append("%)");
+	    } else {
+		sb.append(r).append(", ");
+		sb.append(g).append(", ");
+		sb.append(b).append(')');
+	    }
+	    output = sb.toString();
+	} 
+	return output;
     }
 }

Index: CssNumber.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/values/CssNumber.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- CssNumber.java	14 Sep 2005 15:15:33 -0000	1.6
+++ CssNumber.java	25 Mar 2008 18:30:11 -0000	1.7
@@ -16,6 +16,12 @@
  */
 public class CssNumber extends CssValue implements CssValueFloat {
 
+    public static final int type = CssTypes.CSS_NUMBER;
+    
+    public final int getType() {
+	return type;
+    }
+
     ApplContext ac;
     Float value;
     boolean isInt = false;

Index: CssFrequency.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/values/CssFrequency.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- CssFrequency.java	14 Sep 2005 15:15:33 -0000	1.5
+++ CssFrequency.java	25 Mar 2008 18:30:11 -0000	1.6
@@ -28,6 +28,12 @@
  */
 public class CssFrequency extends CssValue {
 
+    public static final int type = CssTypes.CSS_FREQUENCY;
+    
+    public final int getType() {
+	return type;
+    }
+
   /**
    * Create a new CssFrequency
    */

Index: CssPercentage.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/values/CssPercentage.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- CssPercentage.java	14 Sep 2005 15:15:33 -0000	1.5
+++ CssPercentage.java	25 Mar 2008 18:30:11 -0000	1.6
@@ -34,6 +34,12 @@
  */
 public class CssPercentage extends CssValue {
 
+    public static final int type = CssTypes.CSS_PERCENTAGE;
+    
+    public final int getType() {
+	return type;
+    }
+
     static Float defaultValue = new Float(0);
     Float value;
 

Index: CssAngle.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/values/CssAngle.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- CssAngle.java	14 Sep 2005 15:15:33 -0000	1.6
+++ CssAngle.java	25 Mar 2008 18:30:11 -0000	1.7
@@ -29,6 +29,12 @@
  * @version $Revision$ */
 public class CssAngle extends CssValue implements CssValueFloat {
 
+    public static final int type = CssTypes.CSS_ANGLE;
+    
+    public final int getType() {
+	return type;
+    }
+
     Float value;
     int unit;
     static String[] units = { "deg", "grad", "rad" };

Index: CssExpression.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/values/CssExpression.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- CssExpression.java	17 Mar 2008 17:51:33 -0000	1.5
+++ CssExpression.java	25 Mar 2008 18:30:11 -0000	1.6
@@ -15,6 +15,10 @@
  */
 public class CssExpression implements CssOperator {
 
+    private Vector<ValueOperator> items = new Vector<ValueOperator>();
+    private int count = 0;
+    private int index = 0;
+
     /**
      * Add a value to the end of the expression
      * By default the next operator is a space
@@ -34,7 +38,7 @@
      * @see CssOperator
      */
     public void setOperator(char operator) {
-	((ValueOperator) items.elementAt(count-1)).operator = operator;
+	(items.elementAt(count-1)).operator = operator;
     }
 
     /**
@@ -45,7 +49,7 @@
      * @see CssOperator
      */
     public void setCurrentOperator(char operator) {
-	((ValueOperator) items.elementAt(index)).operator = operator;
+	(items.elementAt(index)).operator = operator;
     }
 
     /**
@@ -56,7 +60,7 @@
 	if (index == count)
 	    return null;
 	else
-	    return ((ValueOperator) items.elementAt(index)).value;
+	    return (items.elementAt(index)).value;
     }
 
     /**
@@ -67,7 +71,7 @@
 	if (index+1 >= count)
 	    return null;
 	else
-	    return ((ValueOperator) items.elementAt(index+1)).value;
+	    return (items.elementAt(index+1)).value;
     }
 
     /* Modified by Sijtsche de Jong */
@@ -79,7 +83,7 @@
 	if (index == count)
 	    return SPACE;
 	else
-	    return ((ValueOperator) items.elementAt(index)).operator;
+	    return (items.elementAt(index)).operator;
     }
 
     /**
@@ -151,7 +155,7 @@
     public String toString() {
 	StringBuilder sb = new StringBuilder();
 	for (int i = index; i < count; i++) {
-	    ValueOperator vo = (ValueOperator) items.elementAt(i);
+	    ValueOperator vo = items.elementAt(i);
 	    sb.append(vo.value.toString()).append(vo.operator);
 	}
 	// remove the last one
@@ -168,7 +172,7 @@
     public String toStringFromStart() {
 	StringBuilder sb = new StringBuilder();
 	for (int i = 0; i < index; i++) {
-	    ValueOperator vo = (ValueOperator) items.elementAt(i);
+	    ValueOperator vo = items.elementAt(i);
 	    sb.append(vo.value.toString()).append(vo.operator);
 	}
 
@@ -183,8 +187,4 @@
 	CssValue value;
 	char operator;
     }
-
-    private Vector items = new Vector();
-    private int count = 0;
-    private int index = 0;
 }

--- NEW FILE: CssTypes.java ---
//
// $Id: CssTypes.java,v 1.1 2008/03/25 18:30:11 ylafon Exp $
//
// (c) COPYRIGHT MIT, ERCIM and Keio University, 2008.
// Please first read the full copyright statement in file COPYRIGHT.html

package org.w3c.css.values;

public class CssTypes {

    public static final int CSS_UNKNOWN       = -1;

    public static final int CSS_IDENT         =  0;
    public static final int CSS_STRING        =  1;
    public static final int CSS_URL           =  2;
    public static final int CSS_COLOR         =  3;
    public static final int CSS_PERCENTAGE    =  4;
    public static final int CSS_NUMBER        =  5;
    public static final int CSS_LENGTH        =  6;
    public static final int CSS_ANGLE         =  7;
    public static final int CSS_TIME          =  8;
    public static final int CSS_FREQUENCY     =  9;
    public static final int CSS_RESOLUTION    = 10;
    public static final int CSS_DATE          = 11;
    public static final int CSS_UNICODE_RANGE = 12;

}
Received on Tuesday, 25 March 2008 18:31:09 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Thursday, 26 April 2012 12:55:00 GMT