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

2002/css-validator/org/w3c/css/util CssProfile.java,NONE,1.1 CssVersion.java,NONE,1.1 ApplContext.java,1.19,1.20

From: Yves Lafon via cvs-syncmail <cvsmail@w3.org>
Date: Wed, 14 Sep 2011 16:31:52 +0000
To: www-validator-cvs@w3.org
Message-Id: <E1R3sNM-0006XC-NH@lionel-hutz.w3.org>
Update of /sources/public/2002/css-validator/org/w3c/css/util
In directory hutz:/tmp/cvs-serv24952/util

Modified Files:
	ApplContext.java 
Added Files:
	CssProfile.java CssVersion.java 
Log Message:
reworking profile/version check ot avoid doing too many string comparisons, and user defaulting

--- NEW FILE: CssVersion.java ---
// $Id: CssVersion.java,v 1.1 2011/09/14 16:31:50 ylafon Exp $
//
// (c) COPYRIGHT MIT, ERCIM and Keio University, 2011
// Please first read the full copyright statement in file COPYRIGHT.html

package org.w3c.css.util;

public enum CssVersion {
    CSS1("css1"), CSS2("css2"), CSS21("css21"), CSS3("css3");
    private final String version;

    CssVersion(String version) {
        this.version = version;
    }

    public String toString() {
        return version;
    }

    static CssVersion resolve(ApplContext ac, String s)
  //          throws InvalidParamException {
    {
        for (CssVersion v : CssVersion.values()) {
            if (v.toString().equals(s)) {
                return v;
            }
        }
        // TODO this or get the default ???
 //       throw new InvalidParamException("invalid-level", s, ac);
        return getDefault();
    }

    // get the default version of CSS
    static public CssVersion getDefault() {
        return CSS21;
    }
}

--- NEW FILE: CssProfile.java ---
// $Id: CssProfile.java,v 1.1 2011/09/14 16:31:50 ylafon Exp $
//
// (c) COPYRIGHT MIT, ERCIM and Keio University, 2011
// Please first read the full copyright statement in file COPYRIGHT.html

package org.w3c.css.util;

public enum CssProfile {
    NONE("none"), SVG("svg"), SVGBASIC("svgbasic"), SVGTINY("svgtiny"),
    MOBILE("mobile"), TV("tv"), ATSCTV("atsc-tv");
    private final String profile;

    CssProfile(String version) {
        this.profile = version;
    }

    public String toString() {
        return profile;
    }

    static CssProfile resolve(ApplContext ac, String s)
  //          throws InvalidParamException {
    {
        for (CssProfile p : CssProfile.values()) {
            if (p.toString().equals(s)) {
                return p;
            }
        }
        // TODO this or get the default ???
 //       throw new InvalidParamException("invalid-level", s, ac);
        return NONE;
    }
}


Index: ApplContext.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/util/ApplContext.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- ApplContext.java	29 Aug 2011 07:21:01 -0000	1.19
+++ ApplContext.java	14 Sep 2011 16:31:50 -0000	1.20
@@ -59,8 +59,8 @@
     String lang;
     Messages msgs;
     Frame frame;
-    String cssversion;
-    String profile;
+    CssVersion version = CssVersion.getDefault();
+    CssProfile profile = CssProfile.NONE;
     String input;
     Class cssselectorstyle;
     int origin = -1;
@@ -156,27 +156,42 @@
     }
 
     public void setCssVersion(String cssversion) {
-        this.cssversion = cssversion;
+        version = CssVersion.resolve(this, cssversion);
     }
 
-    public String getCssVersion() {
-        if (cssversion == null) {
-            cssversion = "css2";
-        }
-        return cssversion;
+    public String getCssVersionString() {
+        return version.toString();
+    }
+
+    public CssVersion getCssVersion() {
+        return version;
     }
 
     public void setProfile(String profile) {
-        this.profile = profile;
+        this.profile = CssProfile.resolve(this, profile);
     }
 
-    public String getProfile() {
-        if (profile == null) {
-            return "";
-        }
+    public CssProfile getCssProfile() {
         return profile;
     }
 
+    public String getProfileString() {
+        return profile.toString();
+    }
+
+    public void setCssVersionAndProfile(String spec) {
+        // for things like SVG, version will be set to the default one
+        // CSS21 in that case, as defined in CssVersion
+        // and profile will be resolved to svg.
+        //
+        // if the version resolve then profile will default to NONE
+
+        // TODO should we check profile first and if SVG or MOBILE
+        // set specific version of CSS (like CSS2 and not CSS21 for MOBILE) ?
+        version = CssVersion.resolve(this, spec);
+        profile = CssProfile.resolve(this, spec);
+    }
+
     public void setOrigin(int origin) {
         this.origin = origin;
     }
Received on Wednesday, 14 September 2011 16:32:07 UTC

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