W3C home > Mailing lists > Public > www-validator-cvs@w3.org > October 2011

2002/css-validator/org/w3c/css/css StyleSheetParser.java,1.19,1.20

From: Yves Lafon via cvs-syncmail <cvsmail@w3.org>
Date: Fri, 21 Oct 2011 12:52:30 +0000
To: www-validator-cvs@w3.org
Message-Id: <E1RHEaM-0006Zc-U3@lionel-hutz.w3.org>
Update of /sources/public/2002/css-validator/org/w3c/css/css
In directory hutz:/tmp/cvs-serv25180/css/css

Modified Files:
	StyleSheetParser.java 
Log Message:
parsing of mediaquerylist for html links is now done reusing the same logic (parsing mediaquerylist form the parser, using a String Reader), so that should finish media queries per http://www.w3.org/TR/2010/CR-css3-mediaqueries-20100727/

Index: StyleSheetParser.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/css/StyleSheetParser.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- StyleSheetParser.java	21 Oct 2011 01:49:06 -0000	1.19
+++ StyleSheetParser.java	21 Oct 2011 12:52:28 -0000	1.20
@@ -16,10 +16,12 @@
 import org.w3c.css.parser.CssSelectors;
 import org.w3c.css.parser.CssValidatorListener;
 import org.w3c.css.parser.Errors;
+import org.w3c.css.parser.analyzer.ParseException;
 import org.w3c.css.parser.analyzer.TokenMgrError;
 import org.w3c.css.properties.css.CssProperty;
 import org.w3c.css.selectors.IdSelector;
 import org.w3c.css.util.ApplContext;
+import org.w3c.css.util.CssVersion;
 import org.w3c.css.util.InvalidParamException;
 import org.w3c.css.util.Util;
 import org.w3c.css.util.Warning;
@@ -28,6 +30,7 @@
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.StringReader;
 import java.lang.reflect.Constructor;
 import java.net.URL;
 import java.util.ArrayList;
@@ -77,7 +80,7 @@
     /**
      * Adds a vector of properties to a selector.
      *
-     * @param selector     the selector
+     * @param selector   the selector
      * @param properties Properties to associate with contexts
      */
     public void handleRule(ApplContext ac, CssSelectors selector,
@@ -225,12 +228,24 @@
         }
     }
 
-    // TODO this is not OK for CSS3...
-    // big FIXME here, we should reuse the parser...
+    // add media, easy version for CSS version < 3, otherwise, reuse the parser
     private void addMedias(AtRuleMedia m, String medias, ApplContext ac) throws InvalidParamException {
-        StringTokenizer tokens = new StringTokenizer(medias, ",");
-        while (tokens.hasMoreTokens()) {
-            m.addMedia(null, tokens.nextToken().trim(), ac);
+        // before CSS3, let's parse it the easy way...
+        if (ac.getCssVersion().compareTo(CssVersion.CSS3) < 0) {
+            StringTokenizer tokens = new StringTokenizer(medias, ",");
+            while (tokens.hasMoreTokens()) {
+                m.addMedia(null, tokens.nextToken().trim(), ac);
+            }
+        } else {
+            CssFouffa muP = new CssFouffa(ac, new StringReader(medias));
+            try {
+                AtRuleMedia arm = muP.parseMediaDeclaration();
+                if (arm != null) {
+                    m.allMedia = arm.allMedia;
+                }
+            } catch (ParseException pex) {
+                // error already added, so nothing else to do
+            }
         }
     }
 
Received on Friday, 21 October 2011 12:52:32 UTC

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