- From: Yves Lafon via cvs-syncmail <cvsmail@w3.org>
- Date: Wed, 14 May 2008 10:13:11 +0000
- To: www-validator-cvs@w3.org
Update of /sources/public/2002/css-validator/org/w3c/css/selectors/attributes
In directory hutz:/tmp/cvs-serv25329
Modified Files:
AttributeBegin.java AttributeExact.java AttributeOneOf.java
AttributeStart.java AttributeSubstr.java AttributeSuffix.java
Log Message:
done selector attribute conflict matching, including oneOf and all possible clash test between the different kind of attributes
Index: AttributeOneOf.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/selectors/attributes/AttributeOneOf.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- AttributeOneOf.java 13 May 2008 09:37:27 -0000 1.4
+++ AttributeOneOf.java 14 May 2008 10:13:09 -0000 1.5
@@ -14,11 +14,13 @@
*/
public class AttributeOneOf extends AttributeSelector {
- String value;
+ String value;
+ String[] values;
public AttributeOneOf(String name, String value) {
setName(name);
this.value = value;
+ this.values = null;
}
/**
@@ -33,6 +35,7 @@
*/
public void setValue(String value) {
this.value = value;
+ values = null;
}
public boolean canApply(Selector other) {
@@ -62,11 +65,89 @@
return "[" + getName() + "~=\"" + value + "\"]";
}
+ private String[] computeValues() {
+ values = value.split("\\s");
+ return values;
+ }
+
public void applyAttribute(ApplContext ac, AttributeSelector attr) {
- if (getName().equals(attr.getName())) {
- if((attr instanceof AttributeExact) &&
- !value.equals(((AttributeExact) attr).getValue())) {
- ac.getFrame().addWarning("incompatible", new String[] { toString(), attr.toString() });
+ String name = getName();
+ int i;
+ String val;
+ boolean ok;
+
+ if (name.equals(attr.getName())) {
+ if (values == null) {
+ computeValues();
+ }
+ if (attr instanceof AttributeExact) {
+ val = ((AttributeExact) attr).getValue();
+ ok = false;
+ for (i=0;!ok && i<values.length; i++) {
+ ok = val.equals(values[i]);
+ }
+ if (!ok) {
+ ac.getFrame().addWarning("incompatible",
+ new String[] { toString(), attr.toString() });
+ }
+ } else if (attr instanceof AttributeBegin) {
+ val = ((AttributeBegin) attr).getValue();
+ ok = false;
+ String pval = val + '-';
+ for (i=0;!ok && i<values.length; i++) {
+ ok = values[i].equals(val) || values[i].startsWith(pval);
+ }
+ if (!ok) {
+ ac.getFrame().addWarning("incompatible",
+ new String[] { toString(), attr.toString() });
+ }
+ } else if (attr instanceof AttributeStart) {
+ val = ((AttributeStart) attr).getValue();
+ ok = false;
+ for (i=0;!ok && i<values.length; i++) {
+ ok = values[i].startsWith(val);
+ }
+ if (!ok) {
+ ac.getFrame().addWarning("incompatible",
+ new String[] { toString(), attr.toString() });
+ }
+ } else if (attr instanceof AttributeSubstr) {
+ val = ((AttributeSubstr) attr).getValue();
+ ok = false;
+ for (i=0;!ok && i<values.length; i++) {
+ ok = (values[i].indexOf(val) >= 0);
+ }
+ if (!ok) {
+ ac.getFrame().addWarning("incompatible",
+ new String[] { toString(), attr.toString() });
+ }
+ } else if (attr instanceof AttributeSuffix) {
+ val = ((AttributeSuffix) attr).getValue();
+ ok = false;
+ for (i=0;!ok && i<values.length; i++) {
+ ok = values[i].endsWith(val);
+ }
+ if (!ok) {
+ ac.getFrame().addWarning("incompatible",
+ new String[] { toString(), attr.toString() });
+ }
+ } else if (attr instanceof AttributeOneOf) {
+ AttributeOneOf otherattr = (AttributeOneOf) attr;
+ String[] othervalues = otherattr.values;
+ int j;
+ if (othervalues == null) {
+ othervalues = otherattr.computeValues();
+ }
+ ok = false;
+ for (i=0;!ok && i<values.length; i++) {
+ for(j=0;!ok && j<othervalues.length; j++) {
+ ok = values[i].equals(othervalues[j]);
+ }
+ }
+ if (!ok) {
+ ac.getFrame().addWarning("incompatible",
+ new String[] { toString(), attr.toString() });
+ }
}
}
}
Index: AttributeBegin.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/selectors/attributes/AttributeBegin.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- AttributeBegin.java 13 Sep 2007 10:12:07 -0000 1.3
+++ AttributeBegin.java 14 May 2008 10:13:09 -0000 1.4
@@ -67,23 +67,30 @@
}
public void applyAttribute(ApplContext ac, AttributeSelector attr) {
- if (attr instanceof AttributeExact) {
- String v = ((AttributeExact) attr).getValue();
- int index = v.indexOf('-');
- if (index > 0) {
- v = v.substring(0, index);
- }
- if (!value.equals(v)) {
- // [lang|=fr][lang=en-US]
- ac.getFrame().addWarning("incompatible", new String[] { toString(), attr.toString() });
- }
- } else if (attr instanceof AttributeBegin) {
- if (!value.equals(((AttributeBegin) attr).value)) {
- // [lang|=fr][lang|=en]
- ac.getFrame().addWarning("incompatible", new String[] { toString(), attr.toString() });
+ String name = getName();
+ if (name.equals(attr.getName())) {
+ // attribute exact knows how to match, delegate...
+ if (attr instanceof AttributeExact) {
+ ((AttributeExact) attr).applyAttribute(ac, this);
+ } else if (attr instanceof AttributeBegin) {
+ String val = ((AttributeBegin) attr).getValue();
+ // check if one start with the other or not
+ if (!val.equals(value) && !value.startsWith(val+'-')
+ && !val.startsWith(value+'-')) {
+ ac.getFrame().addWarning("incompatible",
+ new String[] { toString(), attr.toString() });
+ }
+ } else if (attr instanceof AttributeStart) {
+ String val = ((AttributeStart) attr).getValue();
+ if (!val.equals(value) && !value.startsWith(val)
+ && !val.startsWith(value+'-')) {
+ ac.getFrame().addWarning("incompatible",
+ new String[] { toString(), attr.toString() });
+ }
+ } else if (attr instanceof AttributeOneOf) {
+ ((AttributeOneOf) attr).applyAttribute(ac, this);
}
}
-
}
public String toString() {
Index: AttributeExact.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/selectors/attributes/AttributeExact.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- AttributeExact.java 13 May 2008 16:11:43 -0000 1.9
+++ AttributeExact.java 14 May 2008 10:13:09 -0000 1.10
@@ -70,13 +70,8 @@
new String[] { toString(), attr.toString() });
}
} else if(attr instanceof AttributeOneOf) {
- // FIXME check that the parsed one of value are matching
- // before doing the conclict check requires breaking down
- // the OneOf
- if (!value.equals(((AttributeOneOf) attr).getValue())) {
- ac.getFrame().addWarning("incompatible",
- new String[] { toString(), attr.toString() });
- }
+ // delegate the match to OneOf
+ ((AttributeOneOf)attr).applyAttribute(ac, this);
} else if(attr instanceof AttributeBegin) {
String othervalue = ((AttributeBegin) attr).getValue();
// check if [lang|=en][lang=fr-FR] are incompatible
Index: AttributeStart.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/selectors/attributes/AttributeStart.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- AttributeStart.java 14 Sep 2005 15:15:32 -0000 1.2
+++ AttributeStart.java 14 May 2008 10:13:09 -0000 1.3
@@ -44,7 +44,17 @@
}
public void applyAttribute(ApplContext ac, AttributeSelector attr) {
-
+ String name = getName();
+ if (name.equals(attr.getName())) {
+ // attribute exact knows how to match, delegate...
+ if (attr instanceof AttributeExact) {
+ ((AttributeExact) attr).applyAttribute(ac, this);
+ } else if (attr instanceof AttributeBegin) {
+ ((AttributeBegin) attr).applyAttribute(ac, this);
+ } else if (attr instanceof AttributeOneOf) {
+ ((AttributeOneOf) attr).applyAttribute(ac, this);
+ }
+ }
}
}
Index: AttributeSuffix.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/selectors/attributes/AttributeSuffix.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- AttributeSuffix.java 14 Sep 2005 15:15:32 -0000 1.2
+++ AttributeSuffix.java 14 May 2008 10:13:09 -0000 1.3
@@ -44,7 +44,15 @@
}
public void applyAttribute(ApplContext ac, AttributeSelector attr) {
-
+ String name = getName();
+ if (name.equals(attr.getName())) {
+ // attribute exact knows how to match, delegate...
+ if (attr instanceof AttributeExact) {
+ ((AttributeExact) attr).applyAttribute(ac, this);
+ } else if (attr instanceof AttributeOneOf) {
+ ((AttributeOneOf) attr).applyAttribute(ac, this);
+ }
+ }
}
}
Index: AttributeSubstr.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/selectors/attributes/AttributeSubstr.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- AttributeSubstr.java 14 Sep 2005 15:15:32 -0000 1.2
+++ AttributeSubstr.java 14 May 2008 10:13:09 -0000 1.3
@@ -44,8 +44,15 @@
}
public void applyAttribute(ApplContext ac, AttributeSelector attr) {
- // TODO Auto-generated method stub
-
+ String name = getName();
+ if (name.equals(attr.getName())) {
+ // attribute exact knows how to match, delegate...
+ if (attr instanceof AttributeExact) {
+ ((AttributeExact) attr).applyAttribute(ac, this);
+ } else if (attr instanceof AttributeOneOf) {
+ ((AttributeOneOf) attr).applyAttribute(ac, this);
+ }
+ }
}
}
Received on Wednesday, 14 May 2008 10:13:44 UTC