- From: Yves Lafon via cvs-syncmail <cvsmail@w3.org>
- Date: Wed, 14 Sep 2011 16:31:51 +0000
- To: www-validator-cvs@w3.org
Update of /sources/public/2002/css-validator/org/w3c/css/parser In directory hutz:/tmp/cvs-serv24952/parser Modified Files: CssFouffa.java CssPropertyFactory.java CssSelectors.java Log Message: reworking profile/version check ot avoid doing too many string comparisons, and user defaulting Index: CssSelectors.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/parser/CssSelectors.java,v retrieving revision 1.31 retrieving revision 1.32 diff -u -d -r1.31 -r1.32 --- CssSelectors.java 24 Aug 2011 19:46:55 -0000 1.31 +++ CssSelectors.java 14 Sep 2011 16:31:49 -0000 1.32 @@ -21,6 +21,8 @@ import org.w3c.css.selectors.TypeSelector; import org.w3c.css.selectors.attributes.AttributeExact; 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.Messages; import org.w3c.css.util.Util; @@ -173,12 +175,17 @@ return; } - String profile = ac.getProfile(); - if (profile == null || profile.equals("") || profile.equals("none")) { - profile = ac.getCssVersion(); + CssProfile profile = ac.getCssProfile(); + String spec; + if (profile != CssProfile.NONE) { + spec = profile.toString(); + } else { + CssVersion version = ac.getCssVersion(); + spec = version.toString(); } + // is it a pseudo-class? - String[] ps = PseudoFactory.getPseudoClass(profile); + String[] ps = PseudoFactory.getPseudoClass(spec); if (ps != null) { for (int i = 0; i < ps.length; i++) { if (pseudo.equals(ps[i])) { @@ -188,7 +195,7 @@ } } // it's not a pseudo-class, maybe one pseudo element exception - ps = PseudoFactory.getPseudoElementExceptions(profile); + ps = PseudoFactory.getPseudoElementExceptions(spec); if (ps != null) { for (int i = 0; i < ps.length; i++) { if (pseudo.equals(ps[i])) { @@ -204,14 +211,17 @@ if (pseudo == null) { return; } - - String profile = ac.getProfile(); - if (profile == null || profile.equals("") || profile.equals("none")) { - profile = ac.getCssVersion(); + CssProfile profile = ac.getCssProfile(); + String spec; + if (profile != CssProfile.NONE) { + spec = profile.toString(); + } else { + CssVersion version = ac.getCssVersion(); + spec = version.toString(); } // is it a pseudo-element? - String[] ps = PseudoFactory.getPseudoElement(profile); + String[] ps = PseudoFactory.getPseudoElement(spec); if (ps != null) { for (int i = 0; i < ps.length; i++) { if (pseudo.equals(ps[i])) { @@ -227,11 +237,16 @@ public void setPseudoFun(String pseudo, String param) throws InvalidParamException { - String profile = ac.getProfile(); - if (profile == null || profile.equals("") || profile.equals("none")) { - profile = ac.getCssVersion(); + CssProfile profile = ac.getCssProfile(); + String spec; + if (profile != CssProfile.NONE) { + spec = profile.toString(); + } else { + CssVersion version = ac.getCssVersion(); + spec = version.toString(); } - String[] ps = PseudoFactory.getPseudoFunction(profile); + + String[] ps = PseudoFactory.getPseudoFunction(spec); if (ps != null) { for (int i = 0; i < ps.length; i++) { if (pseudo.equals(ps[i])) { @@ -452,12 +467,10 @@ public void addAttribute(String attName, String value) throws InvalidParamException { - String profile = ac.getProfile(); - if (profile != null && profile.length() != 0) { - if (profile.equals("mobile")) { - throw new InvalidParamException("notformobile", "attributes", - ac); - } + CssProfile profile = ac.getCssProfile(); + if (profile == CssProfile.MOBILE) { + throw new InvalidParamException("notformobile", "attributes", + ac); } else { addAttribute(new AttributeExact(attName, value)); Invalidate(); @@ -480,7 +493,7 @@ } final boolean canApply(ArrayList<Selector> attrs, ArrayList<Selector> attrs2) { - if (attrs.size()>0) { + if (attrs.size() > 0) { int other_idx; Selector other; for (Selector selector : attrs) { Index: CssPropertyFactory.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/parser/CssPropertyFactory.java,v retrieving revision 1.26 retrieving revision 1.27 diff -u -d -r1.26 -r1.27 --- CssPropertyFactory.java 29 Aug 2011 07:21:00 -0000 1.26 +++ CssPropertyFactory.java 14 Sep 2011 16:31:49 -0000 1.27 @@ -10,6 +10,7 @@ import org.w3c.css.properties.PropertiesLoader; import org.w3c.css.properties.css.CssProperty; import org.w3c.css.util.ApplContext; +import org.w3c.css.util.CssVersion; import org.w3c.css.util.InvalidParamException; import org.w3c.css.util.Utf8Properties; import org.w3c.css.util.WarningParamException; @@ -193,7 +194,7 @@ for (int i = 0; i < SORTEDPROFILES.length; ++i) { String p = String.valueOf(SORTEDPROFILES[i]); - if (!p.equals(ac.getCssVersion()) && PropertiesLoader.getProfile(p).containsKey(property)) { + if (!p.equals(ac.getCssVersionString()) && PropertiesLoader.getProfile(p).containsKey(property)) { pfsOk.add(p); } } @@ -201,10 +202,10 @@ if (pfsOk.size() > 0) { /* // This should be uncommented when no-profile in enabled - if (ac.getProfile().equals("none")) { + 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.getCssVersion(); + 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); @@ -212,7 +213,7 @@ } else */ - throw new InvalidParamException("noexistence", new String[]{property, ac.getMsg().getString(ac.getCssVersion()), pfsOk.toString()}, ac); + throw new InvalidParamException("noexistence", new String[]{property, ac.getMsg().getString(ac.getCssVersionString()), pfsOk.toString()}, ac); } else { throw new InvalidParamException("noexistence-at-all", property, ac); } @@ -221,7 +222,7 @@ CssIdent initial = new CssIdent("initial"); try { - if (expression.getValue().equals(initial) && ac.getCssVersion().equals("css3")) { + if (expression.getValue().equals(initial) && (ac.getCssVersion() == CssVersion.CSS3)) { // create an instance of your property class Class[] parametersType = {}; Constructor constructor = Class.forName(classname).getConstructor(parametersType); @@ -248,7 +249,7 @@ String className; Vector<String> list = new Vector<String>(getVector(media)); if (atRule instanceof AtRuleMedia) { - className = PropertiesLoader.getProfile(ac.getCssVersion()).getProperty(property); + className = PropertiesLoader.getProfile(ac.getCssVersionString()).getProperty(property); // a list of media has been specified if (className != null && !media.equals("all")) { String propMedia = PropertiesLoader.mediaProperties.getProperty(property); @@ -260,7 +261,7 @@ } } } else { - className = PropertiesLoader.getProfile(ac.getCssVersion()).getProperty("@" + atRule.keyword() + "." + property); + className = PropertiesLoader.getProfile(ac.getCssVersionString()).getProperty("@" + atRule.keyword() + "." + property); } return className; } Index: CssFouffa.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/parser/CssFouffa.java,v retrieving revision 1.54 retrieving revision 1.55 diff -u -d -r1.54 -r1.55 --- CssFouffa.java 29 Aug 2011 07:21:00 -0000 1.54 +++ CssFouffa.java 14 Sep 2011 16:31:49 -0000 1.55 @@ -18,10 +18,11 @@ 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; import org.w3c.css.util.Util; -import org.w3c.css.util.Warning; import org.w3c.css.util.Warnings; import org.w3c.css.values.CssExpression; @@ -34,8 +35,6 @@ import java.net.URLConnection; import java.nio.charset.Charset; import java.util.ArrayList; -import java.util.Enumeration; -import java.util.Vector; /** * This class is a front end of the CSS1 parser. @@ -102,21 +101,26 @@ */ setURL(file); if (Util.onDebug) { - System.err.println("[DEBUG] CSS version " + ac.getCssVersion() + + System.err.println("[DEBUG] CSS version " + ac.getCssVersionString() + " medium " + ac.getMedium() + " at-rule " - + getAtRule() + " profile " + ac.getProfile()); + + getAtRule() + " profile " + ac.getProfileString()); } - String profile = ac.getProfile(); - if (profile == null || profile.equals("") || profile.equals("none")) { - profile = ac.getCssVersion(); + // load the CssStyle + CssProfile profile = ac.getCssProfile(); + String classStyle; + String spec; + if (profile != CssProfile.NONE) { + spec = profile.toString(); + } else { + CssVersion version = ac.getCssVersion(); + spec = version.toString(); } - // loadConfig(ac.getCssVersion(), ac.getProfile()); - // load the CssStyle - String classStyle = PropertiesLoader.config.getProperty(profile); + classStyle = PropertiesLoader.config.getProperty(spec); if (classStyle == null) { - classStyle = PropertiesLoader.config.getProperty("css2"); + spec = CssVersion.getDefault().toString(); + classStyle = PropertiesLoader.config.getProperty(spec); } Class style; @@ -129,7 +133,7 @@ e.printStackTrace(); } - properties = new CssPropertyFactory(profile); + properties = new CssPropertyFactory(spec); listeners = new ArrayList<CssValidatorListener>(); } @@ -202,9 +206,9 @@ super.ReInitWithAc(input, ac, ac.getCharsetForURL(file)); // @@this is a default media ... // AtRuleMedia media; - // if ("css1".equals(ac.getCssVersion())) { + // if ("css1".equals(ac.getCssVersionString())) { // media = new AtRuleMediaCSS1(); - // } else if ("css2".equals(ac.getCssVersion())) { + // } else if ("css2".equals(ac.getCssVersionString())) { // media = new AtRuleMediaCSS2(); // } else { // media = new AtRuleMediaCSS2(); @@ -218,19 +222,24 @@ */ setURL(file); if (Util.onDebug) { - System.err.println("[DEBUG] CSS version " + ac.getCssVersion() + " medium " + ac.getMedium() + " profile " - + ac.getProfile()); + System.err.println("[DEBUG] CSS version " + ac.getCssVersionString() + " medium " + ac.getMedium() + " profile " + + ac.getProfileString()); } - String profile = ac.getProfile(); - if (profile == null || profile.equals("") || profile.equals("none")) { - profile = ac.getCssVersion(); + CssProfile profile = ac.getCssProfile(); + String spec; + if (profile != CssProfile.NONE) { + spec = profile.toString(); + } else { + CssVersion version = ac.getCssVersion(); + spec = version.toString(); } // load the CssStyle - String classStyle = PropertiesLoader.config.getProperty(profile); + String classStyle = PropertiesLoader.config.getProperty(spec); if (classStyle == null) { - classStyle = PropertiesLoader.config.getProperty("css2"); + spec = CssVersion.getDefault().toString(); + classStyle = PropertiesLoader.config.getProperty(spec); } Class style; @@ -242,8 +251,8 @@ e.printStackTrace(); } - properties = new CssPropertyFactory(profile); - // loadConfig(ac.getCssVersion(), ac.getProfile()); + properties = new CssPropertyFactory(spec); + // loadConfig(ac.getCssVersionString(), ac.getProfileString()); } /** @@ -767,124 +776,7 @@ ac.setCssSelectorsStyle(style); } - /** - * Load the parser properties configuration. - * <p/> - * <p/> - * By default, the parser is configure for cascading style sheet 1. - * <p/> - * <OL> - * You have three parser properties : - * <LI> style: the class name of your CssStyle. - * <LI> properties: the file name where the parser can find all CSS - * properties names. - * <LI> extended-parser: <code>true</code> if you want to parse cascading - * style sheet 2 or 3. - * <OL> - */ - /* - * public void loadConfig(String version, String profile) { try { - * - * URL allprops = CssFouffa.class.getResource("allcss.properties"); URL url = - * null; - * - * if (version == null) { // load the CssStyle String classStyle = - * config.getProperty("style2"); Class style = Class.forName(classStyle); - * ac.setCssSelectorsStyle(style); - * - * properties = __s_nullprop.getClone(); - * // aural mode String mode0 = config.getProperty("extended-parser"); if - * (mode0 != null) { mode = mode0.equals("true"); } } else if - * (version.equals("css1")) { // load the CssStyle String classStyle = - * config.getProperty("style1"); Class style = Class.forName(classStyle); - * ac.setCssSelectorsStyle(style); - * - * if (__s_css1prop == null) { // css1 url = - * style.getResource(config.getProperty("properties1")); __s_css1prop = new - * CssPropertyFactory(url, allprops); } // load properties properties = - * __s_css1prop.getClone(); - * // aural mode String mode0 = config.getProperty("extended-parser"); if - * (mode0 != null) { mode = mode0.equals("true"); } } else if - * ("atsc-tv".equals(profile)) { String classStyle = - * config.getProperty("styleatsc"); Class style = Class.forName(classStyle); - * ac.setCssSelectorsStyle(style); if (__s_asc_tvprop == null) { url = - * style.getResource(config.getProperty("atsc-tv")); __s_asc_tvprop = new - * CssPropertyFactory(url, allprops); } properties = - * __s_asc_tvprop.getClone(); } else if (version.equals("css2")) { // load - * the CssStyle String classStyle = config.getProperty("style2"); Class - * style = Class.forName(classStyle); ac.setCssSelectorsStyle(style); - * // load properties if (profile == null || "".equals(profile)) { - * properties = __s_css2prop.getClone(); } else if - * (profile.equals("mobile")) { if (__s_css2mobileprop == null) { url = - * style.getResource(config.getProperty("mobile")); __s_css2mobileprop = new - * CssPropertyFactory(url, allprops); } properties = - * __s_css2mobileprop.getClone(); } else if (profile.equals("tv")) { if - * (__s_css2tvprop == null) { // css2-tv url = - * style.getResource(config.getProperty("tv")); __s_css2tvprop = new - * CssPropertyFactory(url, allprops); } properties = - * __s_css2tvprop.getClone(); } - * // aural mode String mode0 = config.getProperty("extended-parser"); if - * (mode0 != null) { mode = mode0.equals("true"); } } else if - * (version.equals("css3")) { // load the CssStyle String classStyle = - * config.getProperty("style3"); Class style = Class.forName(classStyle); - * ac.setCssSelectorsStyle(style); - * // load properties if (__s_css3prop == null) { url = - * style.getResource(config.getProperty("properties3")); __s_css3prop = new - * CssPropertyFactory(url, allprops); } properties = - * __s_css3prop.getClone(); - * // aural mode String mode0 = config.getProperty("extended-parser"); if - * (mode0 != null) { mode = mode0.equals("true"); } } else if - * (version.equals("svg")) { // load the CssStyle String classStyle = - * config.getProperty("svgstyle"); Class style = Class.forName(classStyle); - * ac.setCssSelectorsStyle(style); - * - * if (__s_svgprop == null) { url = - * style.getResource(config.getProperty("svg")); __s_svgprop = new - * CssPropertyFactory(url, allprops); } properties = __s_svgprop.getClone(); - * // aural mode String mode0 = config.getProperty("extended-parser"); if - * (mode0 != null) { mode = mode0.equals("true"); } } else if - * (version.equals("svgtiny")) { // load the CssStyle String classStyle = - * config.getProperty("svgtinystyle"); Class style = - * Class.forName(classStyle); ac.setCssSelectorsStyle(style); - * - * if (__s_svgtinyprop == null) { url = - * style.getResource(config.getProperty("svgtiny")); __s_svgtinyprop = new - * CssPropertyFactory(url, allprops); } properties = - * __s_svgtinyprop.getClone(); - * // aural mode String mode0 = config.getProperty("extended-parser"); if - * (mode0 != null) { mode = mode0.equals("true"); } } else if - * (version.equals("svgbasic")) { // load the CssStyle String classStyle = - * config.getProperty("svgbasicstyle"); Class style = - * Class.forName(classStyle); ac.setCssSelectorsStyle(style); - * - * if (__s_svgbasicprop == null) { url = - * style.getResource(config.getProperty("svgbasic")); __s_svgbasicprop = new - * CssPropertyFactory(url, allprops); } properties = - * __s_svgbasicprop.getClone(); - * // aural mode String mode0 = config.getProperty("extended-parser"); if - * (mode0 != null) { mode = mode0.equals("true"); } } - * } catch (Exception e) { - * System.err.println("org.w3c.css.parser.CssFouffa: couldn't" + " load the - * style"); e.printStackTrace(); } } - */ - /* config by default! */ - /* - * static { try { config = new Utf8Properties(); URL url = - * CssFouffa.class.getResource("Config.properties"); java.io.InputStream f = - * url.openStream(); config.load(f); f.close(); // null URL allprops = - * CssFouffa.class.getResource("allcss.properties"); String classStyle = - * config.getProperty("style2"); Class style = Class.forName(classStyle); - * url = style.getResource(config.getProperty("properties2")); __s_nullprop = - * new CssPropertyFactory(url, allprops); - * // css2 // classStyle = config.getProperty("style2"); // style = - * Class.forName(classStyle); // url = - * style.getResource(config.getProperty("properties2")); // __s_css2prop = - * new CssPropertyFactory(url, allprops); __s_css2prop = __s_nullprop; - * } catch (Exception e) { - * System.err.println("org.w3c.css.parser.CssFouffa: couldn't" + " load the - * config"); e.printStackTrace(); } } - */ public CssFouffa(java.io.InputStream stream) { super(stream); properties = new CssPropertyFactory("css2");
Received on Wednesday, 14 September 2011 16:32:07 UTC