2002/css-validator/org/w3c/css/parser/analyzer CssParser.java,1.73,1.74 CssParser.jj,1.74,1.75 CssParserTokenManager.java,1.38,1.39

Update of /sources/public/2002/css-validator/org/w3c/css/parser/analyzer
In directory hutz:/tmp/cvs-serv24952/parser/analyzer

Modified Files:
	CssParser.java CssParser.jj CssParserTokenManager.java 
Log Message:
reworking profile/version check ot avoid doing too many string comparisons, and user defaulting

Index: CssParserTokenManager.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/parser/analyzer/CssParserTokenManager.java,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -d -r1.38 -r1.39
--- CssParserTokenManager.java	9 Sep 2011 12:16:41 -0000	1.38
+++ CssParserTokenManager.java	14 Sep 2011 16:31:49 -0000	1.39
@@ -24,7 +24,6 @@
 import org.w3c.css.values.CssResolution;
 import org.w3c.css.properties.css.CssProperty;
 import org.w3c.css.parser.Frame;
-import org.w3c.css.util.ApplContext;
 import org.w3c.css.parser.CssError;
 import org.w3c.css.parser.CssSelectors;
 import org.w3c.css.parser.CssParseException;
@@ -35,6 +34,9 @@
 import org.w3c.css.parser.AtRulePreference;
 import org.w3c.css.parser.AtRulePhoneticAlphabet;
 import org.w3c.css.properties.svg.AtRuleColorProfile;
[...5151 lines suppressed...]
@@ -6087,8 +6105,8 @@
    0x2L, 0x0L, 
 };
 protected SimpleCharStream input_stream;
-private final int[] jjrounds = new int[728];
-private final int[] jjstateSet = new int[1456];
+private final int[] jjrounds = new int[732];
+private final int[] jjstateSet = new int[1464];
 protected char curChar;
 /** Constructor. */
 public CssParserTokenManager(SimpleCharStream stream){
@@ -6115,7 +6133,7 @@
 {
    int i;
    jjround = 0x80000001;
-   for (i = 728; i-- > 0;)
+   for (i = 732; i-- > 0;)
       jjrounds[i] = 0x80000000;
 }
 

Index: CssParser.jj
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/parser/analyzer/CssParser.jj,v
retrieving revision 1.74
retrieving revision 1.75
diff -u -d -r1.74 -r1.75
--- CssParser.jj	9 Sep 2011 12:16:41 -0000	1.74
+++ CssParser.jj	14 Sep 2011 16:31:49 -0000	1.75
@@ -46,7 +46,6 @@
 import org.w3c.css.values.CssResolution;
 import org.w3c.css.properties.css.CssProperty;
 import org.w3c.css.parser.Frame;
-import org.w3c.css.util.ApplContext;
 import org.w3c.css.parser.CssError;
 import org.w3c.css.parser.CssSelectors;
 import org.w3c.css.parser.CssParseException;
@@ -57,6 +56,9 @@
 import org.w3c.css.parser.AtRulePreference;
 import org.w3c.css.parser.AtRulePhoneticAlphabet;
 import org.w3c.css.properties.svg.AtRuleColorProfile;
+import org.w3c.css.util.ApplContext;
+import org.w3c.css.util.CssProfile;
+import org.w3c.css.util.CssVersion;
 import org.w3c.css.util.InvalidParamException;
 import org.w3c.css.util.WarningParamException;
 import org.w3c.css.util.Util;
@@ -322,7 +324,7 @@
 			  char operator, Token n, int token) 
 	throws ParseException {
 	if (n != null) {
-	    if (ac.getCssVersion().equals("css1") && 
+	    if (ac.getCssVersion() == CssVersion.CSS1 &&
 		(n.image).equals("inherit")) {
 		incompatible_error = true;
 	    }	
@@ -506,7 +508,7 @@
 	           | <NUM> "px" >
   | < EMS        : <NUM> "em" >
   | < EXS        : <NUM> "ex" >
-  | < ANGLE      : <NUM> ( "deg" | "grad" | "rad" ) >
+  | < ANGLE      : <NUM> ( "deg" | "grad" | "rad" | "turn" ) >
   | < TIME       : <NUM> ( "ms" | "s" ) >
   | < FREQ       : <NUM> "Hz" | <NUM> "kHz" >
   | < RESOLUTION : <NUM> "dpi" | <NUM> "dpcm" >
@@ -654,6 +656,7 @@
     Token space2Token = null;
     Token semicolonToken = null;
     int nb_S = 0;
+    CssVersion version = ac.getCssVersion();
 }
 {  
     try {
@@ -670,12 +673,13 @@
 		    throw new ParseException(
 				  ac.getMsg().getString("parser.charset"));
 		}
-		if ("css1".equals(ac.getCssVersion())) {
+		if (version == CssVersion.CSS1) {
 		    throw new ParseException(ac.getMsg().getString(
 							 "parser.charsetcss1"));
 		}
 	        // stricter rule for CSS21 and soon for CSS3
-		if ("css21".equals(ac.getCssVersion())) {
+	     // if equal of above CSS21
+		if (version.compareTo(CssVersion.CSS21) >= 0) {
 		    // single space before
 		    // case sensitive
 		    // no space before ;
@@ -781,7 +785,8 @@
       <SEMICOLON> 
       ( <S> )*
       ) {
-	if (!ac.getCssVersion().equals("css3")) {
+    // If less than CSS 3
+	if (ac.getCssVersion().compareTo(CssVersion.CSS3) < 0) {
 	    addError(new InvalidParamException("at-rule", "@namespace", ac),
 		     (n==null)?"default":n.toString());
 	} else {
@@ -844,6 +849,7 @@
     setAtRule(newRule);
     Token n;
     CssProperty p = null;
+    boolean isCss1 =  (ac.getCssVersion() == CssVersion.CSS1);
 }
 {
     try {
@@ -866,23 +872,22 @@
 		    ac.getFrame().addWarning("noothermedium", 
 					     getAtRule().toString());
 		}
-		if (ac.getCssVersion().equals("css1")) {
+		if (isCss1) {
 		    skipStatement();
 		    addError(new InvalidParamException("noatruleyet", "", ac),
 			     getAtRule().toString());
-		}
-		if (!ac.getCssVersion().equals("css1")) {
-		    newAtRule(getAtRule());	
+		} else {
+		    newAtRule(getAtRule());
 		}
 	    }
 	<LBRACE> ( <S> )* ( ruleSet() )* <RBRACE> ( <S> )*
 	     {
-		 if (!ac.getCssVersion().equals("css1")) {
+		 if (!isCss1) {
 		     endOfAtRule();
 		 }
 	     }
     } catch (ParseException e) {
-	if (!ac.getCssVersion().equals("css1")) {
+	if (!isCss1) {
 	    addError(e, skipStatement()); 
 	}
     } finally {
@@ -939,6 +944,7 @@
     AtRulePage   newRule  = new AtRulePage()    ;
     setAtRule(newRule);
     s.setAtRule(getAtRule());
+    boolean isCss1 = (ac.getCssVersion() == CssVersion.CSS1);
 }
 {
     try {
@@ -953,11 +959,8 @@
 		}
 							  ) <RBRACE> ( <S> )*
 	    {
-		if (!ac.getCssVersion().equals("css1")) {
+		if (!isCss1) {
 		    newAtRule(getAtRule());
-		}
-
-		if (!ac.getCssVersion().equals("css1")) {
 		    addProperty(collectv);
 		    endOfRule();
 		    endOfAtRule();
@@ -969,13 +972,13 @@
 		}
 	    }
     } catch (InvalidParamException ie) {
-	if (!ac.getCssVersion().equals("css1")) {
+	if (!isCss1) {
 	    skipStatement();
 	    removeThisAtRule();
 	    ac.getFrame().addError(new CssError(ie));
 	}
     } catch (ParseException e) {
-	if (!ac.getCssVersion().equals("css1")) {
+	if (!isCss1) {
 	    removeThisAtRule();
 	    addError(e, skipStatement()); 
 	}
@@ -1034,24 +1037,24 @@
     setAtRule(new AtRuleFontFace());
     CssSelectors s = new CssSelectors(ac);
     s.setAtRule(getAtRule());
+    boolean isCss1 = (ac.getCssVersion() == CssVersion.CSS1);
 }
 {
     try {
 	<FONT_FACE_SYM> ( <S> )* 
 	    {
-		if (ac.getCssVersion().equals("css1")) {
+		if (isCss1) {
 		    skipStatement();
 		    addError(new InvalidParamException("noatruleyet", "", ac),
 			     getAtRule().toString());
-		}
-		if (!ac.getCssVersion().equals("css1")) {
-		    newAtRule(getAtRule());	
+		} else {
+		    newAtRule(getAtRule());
 		}
 
 	    }
 	<LBRACE> ( <S> )* v=declarations() <RBRACE> ( <S> )*
 	     {
-		 if (!ac.getCssVersion().equals("css1")) {
+		 if (!isCss1) {
 		     addProperty(v);
 		     endOfRule();
 		     endOfAtRule();
@@ -1063,7 +1066,7 @@
 		 }
 	     }
     } catch (ParseException e) {
-	if (!ac.getCssVersion().equals("css1")) {
+	if (!isCss1) {
 	    addError(e, skipStatement()); 
         }
     } finally {
@@ -1078,24 +1081,27 @@
     setAtRule(new AtRuleColorProfile());
     CssSelectors s = new CssSelectors(ac);
     s.setAtRule(getAtRule());
+    CssProfile profile = ac.getCssProfile();
+    boolean isSVG = ((profile == CssProfile.SVG) ||
+                     (profile == CssProfile.SVGBASIC) ||
+                     (profile == CssProfile.SVGTINY));
 }
 {
     try {
 	<COLOR_PROFILE> ( <S> )*
 	    {
-		if (!ac.getCssVersion().equals("svg")) {
+		if (!isSVG) {
 		    skipStatement();
 		    addError(new InvalidParamException("onlysvg", "", ac),
 			     getAtRule().toString());
-		}
-		if (ac.getCssVersion().equals("svg")) {
-		    newAtRule(getAtRule());	
+		} else {
+		    newAtRule(getAtRule());
 		}
 
 	    }
 	<LBRACE> ( <S> )* v=declarations() <RBRACE> ( <S> )*
 	     {
-		 if (ac.getCssVersion().equals("svg")) {
+		 if (isSVG) {
 		     addProperty(v);
 		     endOfRule();
 		     endOfAtRule();
@@ -1109,7 +1115,7 @@
 	     }
     }
     catch (ParseException e) {
-	if (ac.getCssVersion().equals("svg")) {
+	if (isSVG) {
             addError(e, skipStatement());
 	}
     } finally {
@@ -1125,24 +1131,24 @@
     setAtRule(new AtRulePreference());
     CssSelectors s = new CssSelectors(ac);
     s.setAtRule(getAtRule());
+    boolean isCSS1 = (ac.getCssVersion() == CssVersion.CSS1);
 }
 {
     try {
 	<PREF_SYM> ( <S> )*
 	    {
-		if (ac.getCssVersion().equals("css1")) {
+		if (isCSS1) {
 		    skipStatement();
 		    addError(new InvalidParamException("noatruleyet", "", ac),
 			     getAtRule().toString());
-		}
-		if (!ac.getCssVersion().equals("css1")) {
-		    newAtRule(getAtRule());	
+		} else {
+		    newAtRule(getAtRule());
 		}
 
 	    }
 	<LBRACE> ( <S> )* v=declarations() <RBRACE> ( <S> )*
 	     {
-		 if (!ac.getCssVersion().equals("css1")) {
+		 if (!isCSS1) {
 		     addProperty(v);
 		     endOfRule();
 		     endOfAtRule();
@@ -1156,7 +1162,7 @@
 	     }
     }
     catch (ParseException e) {
-	if (!ac.getCssVersion().equals("css1")) {
+	if (!isCSS1) {
             addError(e, skipStatement());
 	}
     } finally {
@@ -1170,12 +1176,14 @@
     AtRulePhoneticAlphabet alphabetrule = new AtRulePhoneticAlphabet();
     setAtRule(alphabetrule);
     Token n;
+    CssVersion version = ac.getCssVersion();
 }
 {
     try {
 	<PHONETIC_ALPHABET_SYM> ( <S> )* n=<STRING> ( <S> )* ";"
 	    {
-		if (!ac.getCssVersion().equals("css3")) {
+	    // FIXME comparison > CSS3
+		if (version.compareTo(CssVersion.CSS3) < 0) {
 		    skipStatement();
 		    addError(new InvalidParamException("noatruleyet", "", ac),
 			     getAtRule().toString());
@@ -1183,13 +1191,13 @@
 
 		alphabetrule.addAlphabet(convertIdent(n.image), ac);
 
-		if (!ac.getCssVersion().equals("css1") && !ac.getCssVersion().equals("css2")) {
+		if ((version != CssVersion.CSS1) && (version != CssVersion.CSS2)) {
 		    newAtRule(getAtRule());	
 		}
         
 	    }
     } catch (ParseException e) {
-	if (!ac.getCssVersion().equals("css1")) {
+	if (version != CssVersion.CSS1) {
 	    addError(e, skipStatement()); 
         }
     } finally {
@@ -1329,10 +1337,8 @@
 		currentContext = null;
 	    }
     } catch (ParseException e) {
-	if (ac.getProfile() != null) {
-	    if (!ac.getProfile().equals("mobile") && !context_set.isEmpty()) {
+    if ((ac.getCssProfile() != CssProfile.MOBILE) && !context_set.isEmpty()) {
 		addError(e, skipStatement()); 
-	    }
 	}
     } catch (TokenMgrError e) {
 	addError(new ParseException(e.getMessage()), skipStatement());
@@ -1393,24 +1399,25 @@
     try {
 	current=simple_selector(null) 
 	    (  
-	      comb=combinator() { 
-		if (ac.getProfile() != null) {
-		    if (ac.getProfile().equals("mobile") || 
+	    comb=combinator() {
+		if ((ac.getCssProfile() == CssProfile.MOBILE) ||
 			getAtRule().toString().equals("@media atsc-tv") ||
-			ac.getCssVersion().equals("css1")) {
-			if (comb == '+')
+			(ac.getCssVersion() == CssVersion.CSS1)) {
+			if (comb == '+') {
 			    throw new InvalidParamException("nocomb", "+", ac);
-			if (comb == '>')
+			}
+			if (comb == '>') {
 			    throw new InvalidParamException("nocomb", ">", ac);
-		    } else if (ac.getProfile().equals("tv")) {
-			if (comb == '+')
+			}
+		} else if (ac.getCssProfile() == CssProfile.TV) {
+			if (comb == '+') {
 			    throw new InvalidParamException("nocomb", "+", ac);
-		   
 		    }
 		}
-		if (!ac.getCssVersion().equals("css3")) {
+		// FIXME should be >= css3
+		if (ac.getCssVersion().compareTo(CssVersion.CSS3) < 0) {
 		    if (comb == '~') {
-			throw new InvalidParamException("nocomb", "~", ac);
+			    throw new InvalidParamException("nocomb", "~", ac);
 		    }
 		}
 		switch(comb) {
@@ -1533,12 +1540,13 @@
 	    // the class with the first digit escaped
 	    String cl = "."+hexEscapeFirst(n.image);
 
-	    String profile = ac.getProfile();
-	    if(profile == null || profile.equals("") || profile.equals("none")) {
-		profile = ac.getCssVersion(); 
-	    }     
+        CssVersion version = ac.getCssVersion();
+//	    String profile = ac.getProfile();
+//	    if(profile == null || profile.equals("") || profile.equals("none")) {
+//		profile = ac.getCssVersionString();
+//	    }
           
-	    if(!profile.equals("css1")) {
+	    if(version != CssVersion.CSS1) {
 		StringBuilder sb = new StringBuilder();
 		ArrayList<String> param_err = new ArrayList<String>(2);
 		param_err.add(n.image);
@@ -1616,14 +1624,15 @@
     ( LOOKAHEAD(2) (n=<IDENT> | n=<ANY>)? p="|" )? {
 	// FIXME namespace, check versions of CSS in a better way.
 	if (p != null) {
-	    if (!ac.getCssVersion().equals("css3")) {
+	    // FIXME should be > CSS3
+	    if (ac.getCssVersion().compareTo(CssVersion.CSS3) < 0) {
 		StringBuilder sb = new StringBuilder("namespace \"");
 		if (n != null) sb.append(n.toString());
 		sb.append("\"");
 		ac.getFrame().addError(new CssError(new 
 					  InvalidParamException("notversion",
 								"namespace",
-							    ac.getCssVersion(),
+							    ac.getCssVersionString(),
 								ac)));
 		removeThisRule();
 	    } else if (n!=null) {
@@ -1645,12 +1654,12 @@
 	s.addType(new TypeSelector(prefix, convertIdent(n.image)));
     }
     | <ANY> { 
-        if (!ac.getCssVersion().equals("css1")) {
+        if (ac.getCssVersion() != CssVersion.CSS1) {
 	    //          s.setElement(null);
             s.addUniversal(new UniversalSelector(prefix));
         } else {
 	    ac.getFrame().addError(new CssError(new InvalidParamException("notversion",
-									  "*", ac.getCssVersion(), ac)));
+									  "*", ac.getCssVersionString(), ac)));
 	}
     }
 	)
@@ -1682,7 +1691,7 @@
 	   ( <S> )* )?
   <RBRACKET>
       {
-	  if ("css1".equals(ac.getCssVersion())) {
+	  if (ac.getCssVersion() == CssVersion.CSS1) {
 	      StringBuilder reason;
 	      CssParseException cp;
 	      ParseException p;
@@ -1786,12 +1795,13 @@
     <PSEUDOELEMENT_SYM> ( ( n=<IDENT>
 	{ 
 	    try {
-		if (ac.getCssVersion().equals("css3")) {
+	    // should be >CSS3
+		if (ac.getCssVersion().compareTo(CssVersion.CSS3) >= 0) {
 		    s.addPseudoElement(convertIdent(n.image).toLowerCase());
 		} else {
 		    throw new InvalidParamException("pseudo-element",
 						    "::" + convertIdent(n.image).toLowerCase() ,
-						    ac.getCssVersion() ,ac);
+						    ac.getCssVersionString() ,ac);
 		}
 	    } catch(InvalidParamException e) {
 		//	removeThisRule();
@@ -1844,13 +1854,11 @@
 {
   n=<HASHIDENT>  {
       n.image = n.image.substring(1);
-      if(Character.isDigit(n.image.charAt(0))) { 
-	  String profile = ac.getProfile();
-	  if(profile == null || profile.equals("") || profile.equals("none")) {
-	      profile = ac.getCssVersion(); 
-	  }     
-	  
-	  if(!profile.equals("css1")) {
+      if(Character.isDigit(n.image.charAt(0))) {
+
+      CssVersion version = ac.getCssVersion();
+
+      if (version != CssVersion.CSS1) {
 	      // the id with the first digit escaped
 	      String cl = "\\" + Integer.toString(n.image.charAt(0), 16);
 	      cl += n.image.substring(1);
@@ -2332,7 +2340,7 @@
 		    int numValue = Character.digit(c, 16);
 		    int count = 1;
 		    if (maxCount == 0) {
-			maxCount = (ac.getCssVersion().equals("css1") ? 
+			maxCount = ((ac.getCssVersion() == CssVersion.CSS1) ?
 				    4 : 6);
 		    }
 		    while (index + 1 < len) {

Index: CssParser.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/parser/analyzer/CssParser.java,v
retrieving revision 1.73
retrieving revision 1.74
diff -u -d -r1.73 -r1.74
--- CssParser.java	9 Sep 2011 12:16:41 -0000	1.73
+++ CssParser.java	14 Sep 2011 16:31:49 -0000	1.74
@@ -26,7 +26,6 @@
 import org.w3c.css.values.CssResolution;
 import org.w3c.css.properties.css.CssProperty;
 import org.w3c.css.parser.Frame;
-import org.w3c.css.util.ApplContext;
 import org.w3c.css.parser.CssError;
 import org.w3c.css.parser.CssSelectors;
 import org.w3c.css.parser.CssParseException;
@@ -37,6 +36,9 @@
 import org.w3c.css.parser.AtRulePreference;
 import org.w3c.css.parser.AtRulePhoneticAlphabet;
 import org.w3c.css.properties.svg.AtRuleColorProfile;
+import org.w3c.css.util.ApplContext;
+import org.w3c.css.util.CssProfile;
+import org.w3c.css.util.CssVersion;
 import org.w3c.css.util.InvalidParamException;
 import org.w3c.css.util.WarningParamException;
 import org.w3c.css.util.Util;
@@ -302,7 +304,7 @@
                           char operator, Token n, int token)
         throws ParseException {
         if (n != null) {
-            if (ac.getCssVersion().equals("css1") &&
+            if (ac.getCssVersion() == CssVersion.CSS1 &&
                 (n.image).equals("inherit")) {
                 incompatible_error = true;
             }
@@ -479,6 +481,7 @@
     Token space2Token = null;
     Token semicolonToken = null;
     int nb_S = 0;
+    CssVersion version = ac.getCssVersion();
     try {
       charsetToken = jj_consume_token(CHARSET_SYM);
       label_6:
@@ -518,12 +521,13 @@
                     {if (true) throw new ParseException(
                                   ac.getMsg().getString("parser.charset"));}
                 }
-                if ("css1".equals(ac.getCssVersion())) {
+                if (version == CssVersion.CSS1) {
                     {if (true) throw new ParseException(ac.getMsg().getString(
                                                          "parser.charsetcss1"));}
                 }
                 // stricter rule for CSS21 and soon for CSS3
-                if ("css21".equals(ac.getCssVersion())) {
+             // if equal of above CSS21
+                if (version.compareTo(CssVersion.CSS21) >= 0) {
                     // single space before
                     // case sensitive
                     // no space before ;
@@ -760,7 +764,8 @@
       }
       jj_consume_token(S);
     }
-        if (!ac.getCssVersion().equals("css3")) {
+    // If less than CSS 3
+        if (ac.getCssVersion().compareTo(CssVersion.CSS3) < 0) {
             addError(new InvalidParamException("at-rule", "@namespace", ac),
                      (n==null)?"default":n.toString());
         } else {
@@ -890,6 +895,7 @@
     setAtRule(newRule);
     Token n;
     CssProperty p = null;
+    boolean isCss1 =  (ac.getCssVersion() == CssVersion.CSS1);
     try {
       jj_consume_token(MEDIA_SYM);
       label_20:
@@ -1011,12 +1017,11 @@
                     ac.getFrame().addWarning("noothermedium",
                                              getAtRule().toString());
                 }
-                if (ac.getCssVersion().equals("css1")) {
+                if (isCss1) {
                     skipStatement();
                     addError(new InvalidParamException("noatruleyet", "", ac),
                              getAtRule().toString());
-                }
-                if (!ac.getCssVersion().equals("css1")) {
+                } else {
                     newAtRule(getAtRule());
                 }
       jj_consume_token(LBRACE);
@@ -1074,11 +1079,11 @@
         }
         jj_consume_token(S);
       }
-                 if (!ac.getCssVersion().equals("css1")) {
+                 if (!isCss1) {
                      endOfAtRule();
                  }
     } catch (ParseException e) {
-        if (!ac.getCssVersion().equals("css1")) {
+        if (!isCss1) {
             addError(e, skipStatement());
         }
     } finally {
@@ -1164,6 +1169,7 @@
     AtRulePage   newRule  = new AtRulePage()    ;
     setAtRule(newRule);
     s.setAtRule(getAtRule());
+    boolean isCss1 = (ac.getCssVersion() == CssVersion.CSS1);
     try {
       jj_consume_token(PAGE_SYM);
       label_34:
@@ -1235,11 +1241,8 @@
         }
         jj_consume_token(S);
       }
-                if (!ac.getCssVersion().equals("css1")) {
+                if (!isCss1) {
                     newAtRule(getAtRule());
-                }
-
-                if (!ac.getCssVersion().equals("css1")) {
                     addProperty(collectv);
                     endOfRule();
                     endOfAtRule();
@@ -1250,13 +1253,13 @@
                     handleRule(s, collectv);
                 }
     } catch (InvalidParamException ie) {
-        if (!ac.getCssVersion().equals("css1")) {
+        if (!isCss1) {
             skipStatement();
             removeThisAtRule();
             ac.getFrame().addError(new CssError(ie));
         }
     } catch (ParseException e) {
-        if (!ac.getCssVersion().equals("css1")) {
+        if (!isCss1) {
             removeThisAtRule();
             addError(e, skipStatement());
         }
@@ -1384,6 +1387,7 @@
     setAtRule(new AtRuleFontFace());
     CssSelectors s = new CssSelectors(ac);
     s.setAtRule(getAtRule());
+    boolean isCss1 = (ac.getCssVersion() == CssVersion.CSS1);
     try {
       jj_consume_token(FONT_FACE_SYM);
       label_42:
@@ -1398,12 +1402,11 @@
         }
         jj_consume_token(S);
       }
-                if (ac.getCssVersion().equals("css1")) {
+                if (isCss1) {
                     skipStatement();
                     addError(new InvalidParamException("noatruleyet", "", ac),
                              getAtRule().toString());
-                }
-                if (!ac.getCssVersion().equals("css1")) {
+                } else {
                     newAtRule(getAtRule());
                 }
       jj_consume_token(LBRACE);
@@ -1433,7 +1436,7 @@
         }
         jj_consume_token(S);
       }
-                 if (!ac.getCssVersion().equals("css1")) {
+                 if (!isCss1) {
                      addProperty(v);
                      endOfRule();
                      endOfAtRule();
@@ -1444,7 +1447,7 @@
                      handleRule(s, v);
                  }
     } catch (ParseException e) {
-        if (!ac.getCssVersion().equals("css1")) {
+        if (!isCss1) {
             addError(e, skipStatement());
         }
     } finally {
@@ -1458,6 +1461,10 @@
     setAtRule(new AtRuleColorProfile());
     CssSelectors s = new CssSelectors(ac);
     s.setAtRule(getAtRule());
+    CssProfile profile = ac.getCssProfile();
+    boolean isSVG = ((profile == CssProfile.SVG) ||
+                     (profile == CssProfile.SVGBASIC) ||
+                     (profile == CssProfile.SVGTINY));
     try {
       jj_consume_token(COLOR_PROFILE);
       label_45:
@@ -1472,12 +1479,11 @@
         }
         jj_consume_token(S);
       }
-                if (!ac.getCssVersion().equals("svg")) {
+                if (!isSVG) {
                     skipStatement();
                     addError(new InvalidParamException("onlysvg", "", ac),
                              getAtRule().toString());
-                }
-                if (ac.getCssVersion().equals("svg")) {
+                } else {
                     newAtRule(getAtRule());
                 }
       jj_consume_token(LBRACE);
@@ -1507,7 +1513,7 @@
         }
         jj_consume_token(S);
       }
-                 if (ac.getCssVersion().equals("svg")) {
+                 if (isSVG) {
                      addProperty(v);
                      endOfRule();
                      endOfAtRule();
@@ -1519,7 +1525,7 @@
                      handleRule(s, v);
                  }
     } catch (ParseException e) {
-        if (ac.getCssVersion().equals("svg")) {
+        if (isSVG) {
             addError(e, skipStatement());
         }
     } finally {
@@ -1533,6 +1539,7 @@
     setAtRule(new AtRulePreference());
     CssSelectors s = new CssSelectors(ac);
     s.setAtRule(getAtRule());
+    boolean isCSS1 = (ac.getCssVersion() == CssVersion.CSS1);
     try {
       jj_consume_token(PREF_SYM);
       label_48:
@@ -1547,12 +1554,11 @@
         }
         jj_consume_token(S);
       }
-                if (ac.getCssVersion().equals("css1")) {
+                if (isCSS1) {
                     skipStatement();
                     addError(new InvalidParamException("noatruleyet", "", ac),
                              getAtRule().toString());
-                }
-                if (!ac.getCssVersion().equals("css1")) {
+                } else {
                     newAtRule(getAtRule());
                 }
       jj_consume_token(LBRACE);
@@ -1582,7 +1588,7 @@
         }
         jj_consume_token(S);
       }
-                 if (!ac.getCssVersion().equals("css1")) {
+                 if (!isCSS1) {
                      addProperty(v);
                      endOfRule();
                      endOfAtRule();
@@ -1594,7 +1600,7 @@
                      handleRule(s, v);
                  }
     } catch (ParseException e) {
-        if (!ac.getCssVersion().equals("css1")) {
+        if (!isCSS1) {
             addError(e, skipStatement());
         }
     } finally {
@@ -1607,6 +1613,7 @@
     AtRulePhoneticAlphabet alphabetrule = new AtRulePhoneticAlphabet();
     setAtRule(alphabetrule);
     Token n;
+    CssVersion version = ac.getCssVersion();
     try {
       jj_consume_token(PHONETIC_ALPHABET_SYM);
       label_51:
@@ -1635,7 +1642,8 @@
         jj_consume_token(S);
       }
       jj_consume_token(SEMICOLON);
-                if (!ac.getCssVersion().equals("css3")) {
+            // FIXME comparison > CSS3
+                if (version.compareTo(CssVersion.CSS3) < 0) {
                     skipStatement();
                     addError(new InvalidParamException("noatruleyet", "", ac),
                              getAtRule().toString());
@@ -1643,11 +1651,11 @@
 
                 alphabetrule.addAlphabet(convertIdent(n.image), ac);
 
-                if (!ac.getCssVersion().equals("css1") && !ac.getCssVersion().equals("css2")) {
+                if ((version != CssVersion.CSS1) && (version != CssVersion.CSS2)) {
                     newAtRule(getAtRule());
                 }
     } catch (ParseException e) {
-        if (!ac.getCssVersion().equals("css1")) {
+        if (version != CssVersion.CSS1) {
             addError(e, skipStatement());
         }
     } finally {
@@ -1916,10 +1924,8 @@
                 }
                 currentContext = null;
     } catch (ParseException e) {
-        if (ac.getProfile() != null) {
-            if (!ac.getProfile().equals("mobile") && !context_set.isEmpty()) {
+    if ((ac.getCssProfile() != CssProfile.MOBILE) && !context_set.isEmpty()) {
                 addError(e, skipStatement());
-            }
         }
     } catch (TokenMgrError e) {
         addError(new ParseException(e.getMessage()), skipStatement());
@@ -2021,23 +2027,24 @@
           break label_63;
         }
         comb = combinator();
-                if (ac.getProfile() != null) {
-                    if (ac.getProfile().equals("mobile") ||
+                if ((ac.getCssProfile() == CssProfile.MOBILE) ||
                         getAtRule().toString().equals("@media atsc-tv") ||
-                        ac.getCssVersion().equals("css1")) {
-                        if (comb == '+')
+                        (ac.getCssVersion() == CssVersion.CSS1)) {
+                        if (comb == '+') {
                             {if (true) throw new InvalidParamException("nocomb", "+", ac);}
-                        if (comb == '>')
+                        }
+                        if (comb == '>') {
                             {if (true) throw new InvalidParamException("nocomb", ">", ac);}
-                    } else if (ac.getProfile().equals("tv")) {
-                        if (comb == '+')
+                        }
+                } else if (ac.getCssProfile() == CssProfile.TV) {
+                        if (comb == '+') {
                             {if (true) throw new InvalidParamException("nocomb", "+", ac);}
-
                     }
                 }
-                if (!ac.getCssVersion().equals("css3")) {
+                // FIXME should be >= css3
+                if (ac.getCssVersion().compareTo(CssVersion.CSS3) < 0) {
                     if (comb == '~') {
-                        {if (true) throw new InvalidParamException("nocomb", "~", ac);}
+                            {if (true) throw new InvalidParamException("nocomb", "~", ac);}
                     }
                 }
                 switch(comb) {
@@ -2314,12 +2321,13 @@
             // the class with the first digit escaped
             String cl = "."+hexEscapeFirst(n.image);
 
-            String profile = ac.getProfile();
-            if(profile == null || profile.equals("") || profile.equals("none")) {
-                profile = ac.getCssVersion();
-            }
+        CssVersion version = ac.getCssVersion();
+//	    String profile = ac.getProfile();
+//	    if(profile == null || profile.equals("") || profile.equals("none")) {
+//		profile = ac.getCssVersionString();
+//	    }
 
-            if(!profile.equals("css1")) {
+            if(version != CssVersion.CSS1) {
                 StringBuilder sb = new StringBuilder();
                 ArrayList<String> param_err = new ArrayList<String>(2);
                 param_err.add(n.image);
@@ -2441,14 +2449,15 @@
     }
         // FIXME namespace, check versions of CSS in a better way.
         if (p != null) {
-            if (!ac.getCssVersion().equals("css3")) {
+            // FIXME should be > CSS3
+            if (ac.getCssVersion().compareTo(CssVersion.CSS3) < 0) {
                 StringBuilder sb = new StringBuilder("namespace \u005c"");
                 if (n != null) sb.append(n.toString());
                 sb.append("\u005c"");
                 ac.getFrame().addError(new CssError(new
                                           InvalidParamException("notversion",
                                                                 "namespace",
-                                                            ac.getCssVersion(),
+                                                            ac.getCssVersionString(),
                                                                 ac)));
                 removeThisRule();
             } else if (n!=null) {
@@ -2473,12 +2482,12 @@
       break;
     case ANY:
       jj_consume_token(ANY);
-        if (!ac.getCssVersion().equals("css1")) {
+        if (ac.getCssVersion() != CssVersion.CSS1) {
             //          s.setElement(null);
             s.addUniversal(new UniversalSelector(prefix));
         } else {
             ac.getFrame().addError(new CssError(new InvalidParamException("notversion",
-                                                                          "*", ac.getCssVersion(), ac)));
+                                                                          "*", ac.getCssVersionString(), ac)));
         }
       break;
     default:
@@ -2602,7 +2611,7 @@
       ;
     }
     jj_consume_token(RBRACKET);
-          if ("css1".equals(ac.getCssVersion())) {
+          if (ac.getCssVersion() == CssVersion.CSS1) {
               StringBuilder reason;
               CssParseException cp;
               ParseException p;
@@ -2748,12 +2757,13 @@
       jj_consume_token(PSEUDOELEMENT_SYM);
       n = jj_consume_token(IDENT);
             try {
-                if (ac.getCssVersion().equals("css3")) {
+            // should be >CSS3
+                if (ac.getCssVersion().compareTo(CssVersion.CSS3) >= 0) {
                     s.addPseudoElement(convertIdent(n.image).toLowerCase());
                 } else {
                     {if (true) throw new InvalidParamException("pseudo-element",
                                                     "::" + convertIdent(n.image).toLowerCase() ,
-                                                    ac.getCssVersion() ,ac);}
+                                                    ac.getCssVersionString() ,ac);}
                 }
             } catch(InvalidParamException e) {
                 //	removeThisRule();
@@ -2882,12 +2892,10 @@
       n = jj_consume_token(HASHIDENT);
       n.image = n.image.substring(1);
       if(Character.isDigit(n.image.charAt(0))) {
-          String profile = ac.getProfile();
-          if(profile == null || profile.equals("") || profile.equals("none")) {
-              profile = ac.getCssVersion();
-          }
 
-          if(!profile.equals("css1")) {
+      CssVersion version = ac.getCssVersion();
+
+      if (version != CssVersion.CSS1) {
               // the id with the first digit escaped
               String cl = "\u005c\u005c" + Integer.toString(n.image.charAt(0), 16);
               cl += n.image.substring(1);
@@ -3625,7 +3633,7 @@
                     int numValue = Character.digit(c, 16);
                     int count = 1;
                     if (maxCount == 0) {
-                        maxCount = (ac.getCssVersion().equals("css1") ?
+                        maxCount = ((ac.getCssVersion() == CssVersion.CSS1) ?
                                     4 : 6);
                     }
                     while (index + 1 < len) {

Received on Wednesday, 14 September 2011 16:32:07 UTC