2002/css-validator/org/w3c/css/parser AtRule.java,1.5,1.6 AtRuleFontFace.java,1.4,1.5 AtRuleImport.java,1.1,1.2 AtRuleNamespace.java,1.1,1.2 AtRulePage.java,1.5,1.6 AtRulePhoneticAlphabet.java,1.2,1.3 AtRulePreference.java,1.4,1.5 CssFouffa.java,1.56,1.57 CssPropertyFactory.java,1.29,1.30 CssSelectors.java,1.34,1.35 AtRuleMedia.java,1.15,NONE AtRuleMediaCSS1.java,1.6,NONE AtRuleMediaCSS2.java,1.7,NONE MediaEnumeration.java,1.3,NONE

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

Modified Files:
	AtRule.java AtRuleFontFace.java AtRuleImport.java 
	AtRuleNamespace.java AtRulePage.java 
	AtRulePhoneticAlphabet.java AtRulePreference.java 
	CssFouffa.java CssPropertyFactory.java CssSelectors.java 
Removed Files:
	AtRuleMedia.java AtRuleMediaCSS1.java AtRuleMediaCSS2.java 
	MediaEnumeration.java 
Log Message:
redone the Media Features of media queries, up to date per http://www.w3.org/TR/2010/CR-css3-mediaqueries-20100727/, todo, parsing of media in HTML form

Index: CssSelectors.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/parser/CssSelectors.java,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -d -r1.34 -r1.35
--- CssSelectors.java	4 Oct 2011 20:04:09 -0000	1.34
+++ CssSelectors.java	21 Oct 2011 01:49:08 -0000	1.35
@@ -555,11 +555,11 @@
     private boolean canMatch(CssSelectors selector) {
         boolean result = canApply(getSelectors(), selector.getSelectors());
         // current work
-        Util.verbose("canMatched this " + this + " selector: " + selector);
+        Util.verbose("canMatch this " + this + " selector: " + selector);
         Util.verbose("connector " + connector);
         Util.verbose(getSelectors().toString());
         Util.verbose(selector.getSelectors().toString());
-        Util.verbose("canMatched for attributes :" + result);
+        Util.verbose("canMatch for attributes :" + result);
 
         if ((hashElement != selector.hashElement) && hashElement != 0) {
             if ((connector == DESCENDANT) && (selector.next != null)) {
@@ -571,7 +571,7 @@
                 // here we are in this case :
                 // H1 and HTML
                 // H1 can't matched HTML and HTML don't have next
-                Util.verbose("canMatched RETURN FALSE");
+                Util.verbose("canMatch RETURN FALSE");
                 return false;
             }
         }
@@ -581,7 +581,7 @@
             // H1 and BODY HTML H1
             // or :
             // HTML BODY and BODY (this case won't appear in principle)
-            Util.verbose("canMatched RETURN " + result);
+            Util.verbose("canMatch RETURN " + result);
             return canApply(getSelectors(), selector.getSelectors());
         } else {
             // here we are in this case :

Index: CssPropertyFactory.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/parser/CssPropertyFactory.java,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- CssPropertyFactory.java	5 Oct 2011 07:12:16 -0000	1.29
+++ CssPropertyFactory.java	21 Oct 2011 01:49:08 -0000	1.30
@@ -7,6 +7,9 @@
 
 package org.w3c.css.parser;
 
+import org.w3c.css.media.AtRuleMedia;
+import org.w3c.css.media.Media;
+import org.w3c.css.media.MediaFeature;
 import org.w3c.css.properties.PropertiesLoader;
 import org.w3c.css.properties.css.CssProperty;
 import org.w3c.css.util.ApplContext;
@@ -77,50 +80,56 @@
         return list;
     }
 
-    // public void setUserMedium(String usermedium) {
-    // this.usermedium = usermedium;
-    // }
-
     // bug: FIXME
     // @media screen and (min-width: 400px) and (max-width: 700px), print {
     // a {
     // border: 0;
     // }
     // }
-    public synchronized CssProperty createMediaFeature(ApplContext ac, AtRule atRule, String property,
-                                                       CssExpression expression) throws Exception {
-        // String result = "ok";
-        String media = atRule.toString();
-        String upmedia = media.toUpperCase();
-        int pos = -1;
-        int pos2 = upmedia.indexOf("AND");
+    public synchronized MediaFeature createMediaFeature(ApplContext ac, AtRule atRule, String feature,
+                                                        CssExpression expression) throws Exception {
+        String modifier = null;
+        String classname;
+        int dashpos = feature.indexOf('-');
+        feature = feature.toLowerCase();
 
-        if (pos2 == -1) {
-            pos2 = media.length();
-        }
-        pos = upmedia.indexOf("NOT");
-        if (pos != -1) {
-            media = media.substring(pos + 4, pos2);
-        } else if ((pos = upmedia.indexOf("ONLY")) != -1) {
-            media = media.substring(pos + 4, pos2);
-        } else {
-            pos = media.indexOf(" ");
-            media = media.substring(pos + 1, pos2);
+        if (dashpos != -1) {
+            if (dashpos == 0) {
+                // vendor media?
+                try {
+                    AtRuleMedia atRuleMedia = (AtRuleMedia) atRule;
+                    // I don't know this property
+                    // TODO get the latest media it applies to
+                    throw new InvalidParamException("noexistence-media", feature,
+                            atRuleMedia.getCurrentMedia(), ac);
+                } catch (ClassCastException cce) {
+                    // I don't know this property
+                    throw new InvalidParamException("noexistence", feature, "not media @rule", ac);
+                }
+            }
+            modifier = feature.substring(0, dashpos);
+            // clash between feature name and modifier...
+            // link min-width and color-index, so we check we have min- or max-
+            if (modifier.equals("min") || modifier.equals("max")) {
+                feature = feature.substring(dashpos + 1);
+            } else {
+                // back to normal
+                modifier = null;
+            }
         }
 
-        media = media.trim();
-
-        String classname = properties.getProperty("mediafeature" + "." + property);
+        classname = properties.getProperty("mediafeature" + "." + feature.toLowerCase());
 
         if (classname == null) {
-            if (atRule instanceof AtRuleMedia && (!media.equals("all"))) {
+            try {
+                AtRuleMedia atRuleMedia = (AtRuleMedia) atRule;
                 // I don't know this property
-                throw new InvalidParamException("noexistence-media", property, media, ac);
-                // ac.getFrame().addWarning("noexistence-media", property);
-                // classname = allprops.getProperty(property);
-            } else {
+                // TODO get the latest media it applies to
+                throw new InvalidParamException("noexistence-media", feature,
+                        atRuleMedia.getCurrentMedia(), ac);
+            } catch (ClassCastException cce) {
                 // I don't know this property
-                throw new InvalidParamException("noexistence", property, media, ac);
+                throw new InvalidParamException("noexistence", feature, "not media @rule", ac);
             }
         }
 
@@ -132,41 +141,37 @@
             }
             // Maybe it will be necessary to add the check parameter as for
             // create property, so... FIXME
-            Class[] parametersType = {ac.getClass(), expressionclass};
+            Class[] parametersType = {ac.getClass(), String.class, expressionclass};
             Constructor constructor = Class.forName(classname).getConstructor(parametersType);
-            Object[] parameters = {ac, expression};
+            Object[] parameters = {ac, modifier, expression};
             // invoke the constructor
-            return (CssProperty) constructor.newInstance(parameters);
+            return (MediaFeature) constructor.newInstance(parameters);
         } catch (InvocationTargetException e) {
             // catch InvalidParamException
             Exception ex = (Exception) e.getTargetException();
             throw ex;
         }
-
     }
 
     public synchronized CssProperty createProperty(ApplContext ac, AtRule atRule, String property,
                                                    CssExpression expression) throws Exception {
         String classname = null;
-        String media = atRule.toString();
-        int pos = -1;
-        String upperMedia = media.toUpperCase();
-        int pos2 = upperMedia.indexOf("AND ");
-
-        if (pos2 == -1) {
-            pos2 = media.length();
-        }
+        AtRuleMedia atRuleMedia;
+        String media = null;
 
-        if ((pos = upperMedia.indexOf("NOT")) != -1) {
-            media = media.substring(pos + 4, pos2);
-        } else if ((pos = upperMedia.indexOf("ONLY")) != -1) {
-            media = media.substring(pos + 4, pos2);
-        } else {
-            pos = media.indexOf(' ');
-            media = media.substring(pos + 1, pos2);
+        try {
+            atRuleMedia = (AtRuleMedia) atRule;
+            // TODO FIXME in fact, it should use a vector of media instead of extracting
+            // only one media, so let's use kludges
+            for (Media m : atRuleMedia.getMediaList()) {
+                if (!m.getNot()) {
+                    media = m.getMedia();
+                    break;
+                }
+            }
+        } catch (ClassCastException cce) {
+            media = "all";
         }
-
-        media = media.trim();
         classname = setClassName(atRule, media, ac, property);
 
         // the property does not exist in this profile
@@ -187,30 +192,30 @@
             }
             if (pfsOk.size() > 0) {
                 if (ac.getCssProfile() == CssProfile.NONE) {
-                    String latestVersion = pfsOk.get(pfsOk.size()-1);
+                    String latestVersion = pfsOk.get(pfsOk.size() - 1);
                     CssVersion v = CssVersion.resolve(ac, latestVersion);
                     // should always be true... otherwise there is an issue...
                     if (v.compareTo(ac.getCssVersion()) > 0) {
-                        ac.getFrame().addWarning("noexistence", new String[] { property, ac.getMsg().getString(ac.getPropertyKey()), pfsOk.toString() });
+                        ac.getFrame().addWarning("noexistence", new String[]{property, ac.getMsg().getString(ac.getPropertyKey()), pfsOk.toString()});
                         ac.setCssVersion(v);
                     }
                     classname = setClassName(atRule, media, ac, property);
                 } else {
 
-                /*
-            // This should be uncommented when no-profile in enabled
-            if (ac.getProfileString().equals("none")) {
-            // the last one should be the best one to use
-            String	pf = (String) pfsOk.get(pfsOk.size()-1),
-            old_pf = ac.getCssVersionString();
-            ac.setCssVersion(pf);
-            ac.getFrame().addWarning("noexistence", new String[] { property, ac.getMsg().getString(old_pf), pfsOk.toString() });
-            classname = setClassName(atRule, media, ac, property);
-            ac.setCssVersion(old_pf);
-            }
-            else
-            */
-                throw new InvalidParamException("noexistence", new String[]{property, ac.getMsg().getString(ac.getPropertyKey()), pfsOk.toString()}, ac);
+                    /*
+                    // This should be uncommented when no-profile in enabled
+                    if (ac.getProfileString().equals("none")) {
+                    // the last one should be the best one to use
+                    String	pf = (String) pfsOk.get(pfsOk.size()-1),
+                    old_pf = ac.getCssVersionString();
+                    ac.setCssVersion(pf);
+                    ac.getFrame().addWarning("noexistence", new String[] { property, ac.getMsg().getString(old_pf), pfsOk.toString() });
+                    classname = setClassName(atRule, media, ac, property);
+                    ac.setCssVersion(old_pf);
+                    }
+                    else
+                    */
+                    throw new InvalidParamException("noexistence", new String[]{property, ac.getMsg().getString(ac.getPropertyKey()), pfsOk.toString()}, ac);
                 }
             } else {
                 throw new InvalidParamException("noexistence-at-all", property, ac);

--- AtRuleMedia.java DELETED ---

Index: AtRulePage.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/parser/AtRulePage.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- AtRulePage.java	29 Aug 2011 07:21:00 -0000	1.5
+++ AtRulePage.java	21 Oct 2011 01:49:08 -0000	1.6
@@ -131,7 +131,7 @@
     /**
      * The second must only match this one
      */
-    public boolean canMatched(AtRule atRule) {
+    public boolean canMatch(AtRule atRule) {
         AtRulePage atRulePage;
         try {
             atRulePage = (AtRulePage) atRule;

Index: AtRulePreference.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/parser/AtRulePreference.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- AtRulePreference.java	14 Sep 2005 15:14:18 -0000	1.4
+++ AtRulePreference.java	21 Oct 2011 01:49:08 -0000	1.5
@@ -45,7 +45,7 @@
     /**
      * The second must only match this one
      */
-    public boolean canMatched(AtRule atRule) {
+    public boolean canMatch(AtRule atRule) {
 	return (atRule instanceof AtRulePreference);
     }
 

Index: CssFouffa.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/parser/CssFouffa.java,v
retrieving revision 1.56
retrieving revision 1.57
diff -u -d -r1.56 -r1.57
--- CssFouffa.java	17 Sep 2011 06:02:26 -0000	1.56
+++ CssFouffa.java	21 Oct 2011 01:49:08 -0000	1.57
@@ -11,6 +11,8 @@
 package org.w3c.css.parser;
 
 import org.w3c.css.css.StyleSheetOrigin;
+import org.w3c.css.media.AtRuleMedia;
+import org.w3c.css.media.MediaFeature;
 import org.w3c.css.parser.analyzer.CssParser;
 import org.w3c.css.parser.analyzer.CssParserTokenManager;
 import org.w3c.css.parser.analyzer.ParseException;
@@ -18,7 +20,6 @@
 import org.w3c.css.properties.PropertiesLoader;
 import org.w3c.css.properties.css.CssProperty;
 import org.w3c.css.util.ApplContext;
-import org.w3c.css.util.CssProfile;
 import org.w3c.css.util.CssVersion;
 import org.w3c.css.util.HTTPURL;
 import org.w3c.css.util.InvalidParamException;
@@ -112,7 +113,7 @@
 
         classStyle = PropertiesLoader.config.getProperty(spec);
         if (classStyle == null) {
-            spec =  CssVersion.getDefault().toString();
+            spec = CssVersion.getDefault().toString();
             classStyle = PropertiesLoader.config.getProperty(spec);
         }
 
@@ -202,9 +203,9 @@
         // if ("css1".equals(ac.getCssVersionString())) {
         // media = new AtRuleMediaCSS1();
         // } else if ("css2".equals(ac.getCssVersionString())) {
-        // media = new AtRuleMediaCSS2();
+        // media = new AtRuleMedia();
         // } else {
-        // media = new AtRuleMediaCSS2();
+        // media = new AtRuleMedia();
         // }
         /*
        * if (ac.getMedium() == null) { try { media.addMedia("all", ac); }
@@ -527,12 +528,7 @@
         }
 
         try {
-            if (getMediaDeclaration().equals("on") && (getAtRule() instanceof AtRuleMedia)) {
-                prop = properties.createMediaFeature(ac, getAtRule(), property, expression);
-            } else {
-                prop = properties.createProperty(ac, getAtRule(), property, expression);
-            }
-
+            prop = properties.createProperty(ac, getAtRule(), property, expression);
         } catch (InvalidParamException e) {
             throw e;
         } catch (Exception e) {
@@ -556,6 +552,42 @@
     }
 
     /**
+     * Assign an expression to a MediaFeature. This function create a new
+     * media feature with <code>feature</code> and assign to it the expression
+     *
+     * @param feature    the name of the media feature
+     * @param expression The expression representation of expression
+     * @return a CssProperty
+     * @throw InvalidParamException
+     * An error appears during the property creation.
+     */
+    public MediaFeature handleMediaFeature(String feature, CssExpression expression)
+            throws InvalidParamException {
+        MediaFeature mf;
+        if (Util.onDebug) {
+            System.err.println("Creating MediaFeature" + feature + ": " + expression);
+        }
+
+        try {
+            mf = properties.createMediaFeature(ac, getAtRule(), feature, expression);
+        } catch (InvalidParamException e) {
+            throw e;
+        } catch (Exception e) {
+            e.printStackTrace();
+            if (Util.onDebug) {
+                e.printStackTrace();
+            }
+            throw new InvalidParamException(e.toString(), ac);
+        }
+
+        mf.setOrigin(origin);
+        // set informations for errors and warnings
+        mf.setInfo(ac.getFrame().getLine(), ac.getFrame().getSourceFile());
+        // ok, return the new property
+        return mf;
+    }
+
+    /**
      * Parse only a list of declarations. This is useful to parse the
      * <code>STYLE</code> attribute in a HTML document.
      * <p/>

--- MediaEnumeration.java DELETED ---

Index: AtRulePhoneticAlphabet.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/parser/AtRulePhoneticAlphabet.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- AtRulePhoneticAlphabet.java	26 Nov 2007 05:07:17 -0000	1.2
+++ AtRulePhoneticAlphabet.java	21 Oct 2011 01:49:08 -0000	1.3
@@ -58,7 +58,7 @@
     /**
      * The second must only match this one
      */
-    public boolean canMatched(AtRule atRule) {
+    public boolean canMatch(AtRule atRule) {
 		return (atRule instanceof AtRulePhoneticAlphabet);
     }
 

Index: AtRuleNamespace.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/parser/AtRuleNamespace.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- AtRuleNamespace.java	13 Feb 2009 14:03:36 -0000	1.1
+++ AtRuleNamespace.java	21 Oct 2011 01:49:08 -0000	1.2
@@ -40,7 +40,7 @@
     /**
      * The second must only match this one
      */
-    public boolean canMatched(AtRule atRule) {
+    public boolean canMatch(AtRule atRule) {
 	return false;
     }
 

Index: AtRule.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/parser/AtRule.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- AtRule.java	13 Feb 2009 14:03:36 -0000	1.5
+++ AtRule.java	21 Oct 2011 01:49:08 -0000	1.6
@@ -29,7 +29,7 @@
     /**
      * The second must only match this one
      */
-    public abstract boolean canMatched(AtRule atRule);
+    public abstract boolean canMatch(AtRule atRule);
 
     public boolean isEmpty() {
 	return false;

--- AtRuleMediaCSS1.java DELETED ---

--- AtRuleMediaCSS2.java DELETED ---

Index: AtRuleImport.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/parser/AtRuleImport.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- AtRuleImport.java	13 Feb 2009 14:03:36 -0000	1.1
+++ AtRuleImport.java	21 Oct 2011 01:49:08 -0000	1.2
@@ -9,7 +9,7 @@
  */
 package org.w3c.css.parser;
 
-import java.net.URL;
+import org.w3c.css.media.AtRuleMedia;
 
 /**
  * This class manages all imports
@@ -41,7 +41,7 @@
     /**
      * The second must only match this one
      */
-    public boolean canMatched(AtRule atRule) {
+    public boolean canMatch(AtRule atRule) {
 	return false;
     }
 

Index: AtRuleFontFace.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/parser/AtRuleFontFace.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- AtRuleFontFace.java	26 Nov 2007 05:07:17 -0000	1.4
+++ AtRuleFontFace.java	21 Oct 2011 01:49:08 -0000	1.5
@@ -52,7 +52,7 @@
     /**
      * The second must only match this one
      */
-    public boolean canMatched(AtRule atRule) {
+    public boolean canMatch(AtRule atRule) {
 	return (atRule instanceof AtRuleFontFace);
     }
 

Received on Friday, 21 October 2011 01:49:49 UTC