- From: Yves Lafon via cvs-syncmail <cvsmail@w3.org>
- Date: Tue, 25 Mar 2008 18:43:32 +0000
- To: www-validator-cvs@w3.org
Update of /sources/public/2002/css-validator/org/w3c/css/properties/css1 In directory hutz:/tmp/cvs-serv7487/css1 Modified Files: CssBackgroundAttachmentCSS2.java CssBackgroundImageCSS2.java CssBackgroundPositionCSS2.java CssBackgroundRepeatCSS2.java CssBorderFaceWidthCSS2.java CssBorderTopCSS2.java CssProperty.java Log Message: various code clarification/updates Index: CssBackgroundImageCSS2.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/properties/css1/CssBackgroundImageCSS2.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- CssBackgroundImageCSS2.java 14 Sep 2005 15:14:31 -0000 1.3 +++ CssBackgroundImageCSS2.java 25 Mar 2008 18:43:30 -0000 1.4 @@ -12,6 +12,7 @@ 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.CssURL; import org.w3c.css.values.CssValue; @@ -38,7 +39,16 @@ CssValue url; - private static CssIdent none = new CssIdent("none"); + public static CssIdent none; + private static final String property_name = "background-image"; + + static { + none = new CssIdent("none"); + } + + static public boolean checkMatchingIdent(CssIdent idval) { + return none.hashCode() == idval.hashCode(); + } /** * Create a new CssBackgroundImageCSS2 @@ -59,25 +69,30 @@ if(check && expression.getCount() > 1) { throw new InvalidParamException("unrecognize", ac); } - + setByUser(); - + CssValue val = expression.getValue(); - if (val instanceof CssURL) { + switch (val.getType()) { + case CssTypes.CSS_URL: url = val; - expression.next(); - } else if (val.equals(inherit)) { - url = inherit; - expression.next(); - } else if (val.equals(none)) { - url = none; - expression.next(); - } else { - throw new InvalidParamException("value", expression.getValue(), + 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 CssBackgroundImageCSS2(ApplContext ac, CssExpression expression) throws InvalidParamException { this(ac, expression, false); @@ -96,7 +111,7 @@ */ public boolean isSoftlyInherited() { if (url != null) { - return url.equals(inherit); + return inherit.equals(url); } return false; } @@ -115,7 +130,7 @@ * Returns the name of this property */ public String getPropertyName() { - return "background-image"; + return property_name; } /** @@ -125,8 +140,9 @@ */ public void addToStyle(ApplContext ac, CssStyle style) { CssBackgroundCSS2 cssBackground = ((Css1Style) style).cssBackgroundCSS2; - if (cssBackground.image != null) + if (cssBackground.image != null) { style.addRedefinitionWarning(ac, this); + } cssBackground.image = this; } Index: CssBorderFaceWidthCSS2.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/properties/css1/CssBorderFaceWidthCSS2.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- CssBorderFaceWidthCSS2.java 14 Sep 2005 15:14:31 -0000 1.3 +++ CssBorderFaceWidthCSS2.java 25 Mar 2008 18:43:30 -0000 1.4 @@ -12,6 +12,7 @@ import org.w3c.css.values.CssIdent; import org.w3c.css.values.CssLength; import org.w3c.css.values.CssNumber; +import org.w3c.css.values.CssTypes; import org.w3c.css.values.CssValue; /** @@ -20,7 +21,16 @@ public class CssBorderFaceWidthCSS2 { CssValue value; - + private static CssIdent thin; + private static CssIdent medium; + private static CssIdent thick; + + static { + thin = new CssIdent("thin"); + medium = new CssIdent("medium"); + thick = new CssIdent("thick"); + } + /** * Create a new CssBorderFaceWidthCSS2 */ @@ -52,26 +62,40 @@ CssValue val = expression.getValue(); - if (val instanceof CssLength) { + switch (val.getType()) { + case CssTypes.CSS_LENGTH: float f = ((Float) val.get()).floatValue(); - if (f >= 0) + if (f >= 0) { this.value = val; - else + } else { throw new InvalidParamException("negative-value", val.toString(), ac); - } else if (val instanceof CssNumber) { + } + break; + case CssTypes.CSS_NUMBER: value = ((CssNumber) val).getLength(); - } else if (val.equals(thin)) { - value = thin; - } else if (val.equals(medium)) { - value = medium; - } else if (val.equals(thick)) { - value = thick; - } else if (val.equals(CssProperty.inherit)) { - value = CssProperty.inherit; - } else { + break; + case CssTypes.CSS_IDENT: + CssIdent ci = (CssIdent) val; + if (CssProperty.inherit.equals(ci)) { + value = CssProperty.inherit; + break; + } + if (thin.equals(ci)) { + value = thin; + break; + } + if (medium.equals(ci)) { + value = medium; + break; + } + if (thick.equals(ci)) { + value = thick; + break; + } + default: throw new InvalidParamException("value", val.toString(), "width", ac); } - + expression.next(); } @@ -106,9 +130,7 @@ return value.equals(another.value); // FIXME } - private static CssIdent thin = new CssIdent("thin"); - private static CssIdent medium = new CssIdent("medium"); - private static CssIdent thick = new CssIdent("thick"); + } Index: CssBorderTopCSS2.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/properties/css1/CssBorderTopCSS2.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- CssBorderTopCSS2.java 14 Sep 2005 15:14:31 -0000 1.4 +++ CssBorderTopCSS2.java 25 Mar 2008 18:43:30 -0000 1.5 @@ -50,10 +50,11 @@ */ public class CssBorderTopCSS2 extends CssProperty implements CssOperator { - CssBorderTopWidthCSS2 width; - CssBorderTopStyleCSS2 style; - CssBorderTopColorCSS2 color; - + CssBorderTopWidthCSS2 width = null; + CssBorderTopStyleCSS2 style = null; + CssBorderTopColorCSS2 color = null; + String output = null; + /** * Create a new CssBorderFaceCSS2 */ @@ -164,6 +165,7 @@ */ public void setColor(CssBorderTopColorCSS2 color) { this.color = color; + output = null; } /** @@ -171,6 +173,7 @@ */ public void setStyle(CssBorderTopStyleCSS2 style) { this.style = style; + output = null; } /** @@ -178,6 +181,7 @@ */ public void setWidth(CssBorderTopWidthCSS2 width) { this.width = width; + output = null; } /** @@ -193,9 +197,8 @@ public CssValue getColor() { if (color != null) { return color.getColor(); - } else { - return null; } + return null; } /** @@ -204,9 +207,8 @@ public CssValue getWidth() { if (width != null) { return width.getValue(); - } else { - return null; } + return null; } /** @@ -215,34 +217,40 @@ public String getStyle() { if (style != null) { return style.getStyle(); - } else { - return null; } + return null; } /** * Returns a string representation of the object. */ public String toString() { - String ret = ""; + if (output != null) { + return output; + } + StringBuilder sb = new StringBuilder(); + boolean first = true; if(width != null) { - ret += width; + sb.append(width.toString()); + first = false; } if(style != null) { - if(!ret.equals("")) { - ret += " "; - } - ret += style; + if (!first) { + sb.append(' '); + } + first = false; + sb.append(style.toString()); } if(color != null) { - if(!ret.equals("")) { - ret += " "; - } - ret += color; + if (!first) { + sb.append(' '); + } + sb.append(color); } - return ret; + output = sb.toString(); + return output; } - + /** * Returns the name of this property */ Index: CssBackgroundAttachmentCSS2.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/properties/css1/CssBackgroundAttachmentCSS2.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- CssBackgroundAttachmentCSS2.java 14 Sep 2005 15:14:31 -0000 1.3 +++ CssBackgroundAttachmentCSS2.java 25 Mar 2008 18:43:30 -0000 1.4 @@ -159,9 +159,20 @@ return attachment == 0; } + static public boolean checkMatchingIdent(CssIdent idval) { + for (int i=0 ; i < hash_values.length; i++) { + if (hash_values[i] == idval.hashCode()) { + return true; + } + } + return false; + } + static { hash_values = new int[ATTACHMENT.length]; for (int i = 0; i < ATTACHMENT.length; i++) hash_values[i] = ATTACHMENT[i].hashCode(); } + + } Index: CssBackgroundRepeatCSS2.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/properties/css1/CssBackgroundRepeatCSS2.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- CssBackgroundRepeatCSS2.java 14 Sep 2005 15:14:31 -0000 1.3 +++ CssBackgroundRepeatCSS2.java 25 Mar 2008 18:43:30 -0000 1.4 @@ -163,6 +163,15 @@ return repeat == 0; } + static public boolean checkMatchingIdent(CssIdent idval) { + for (int i=0 ; i < hash_values.length; i++) { + if (hash_values[i] == idval.hashCode()) { + return true; + } + } + return false; + } + static { hash_values = new int[REPEAT.length]; for (int i = 0; i < REPEAT.length; i++) Index: CssProperty.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/properties/css1/CssProperty.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- CssProperty.java 14 Sep 2005 15:14:31 -0000 1.3 +++ CssProperty.java 25 Mar 2008 18:43:30 -0000 1.4 @@ -78,18 +78,23 @@ /** * This keyword is used a lot of time in CSS2 */ - public static final CssIdent inherit = new CssIdent("inherit"); - + public static final CssIdent inherit; + /** * Used in all CSS versions */ - public static final CssIdent transparent = new CssIdent("transparent"); + public static final CssIdent transparent; /** * Value introduced in CSS3 */ - public static final CssIdent initial = new CssIdent("initial"); + public static final CssIdent initial; + static { + inherit = new CssIdent("inherit"); + transparent = new CssIdent("transparent"); + initial = new CssIdent("initial"); + } /** * Create a new CssProperty. */ Index: CssBackgroundPositionCSS2.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/properties/css1/CssBackgroundPositionCSS2.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- CssBackgroundPositionCSS2.java 19 Apr 2006 11:28:05 -0000 1.7 +++ CssBackgroundPositionCSS2.java 25 Mar 2008 18:43:30 -0000 1.8 @@ -493,6 +493,15 @@ return -1; } + static public boolean checkMatchingIdent(CssIdent idval) { + for (int i=0 ; i < hash_values.length; i++) { + if (hash_values[i] == idval.hashCode()) { + return true; + } + } + return false; + } + private static int[] hash_values; //private static int INVALID = -1;
Received on Tuesday, 25 March 2008 18:44:04 UTC