- From: Yves Lafon via cvs-syncmail <cvsmail@w3.org>
- Date: Wed, 10 Dec 2008 15:23:00 +0000
- To: www-validator-cvs@w3.org
Update of /sources/public/2002/css-validator/org/w3c/css/parser In directory hutz:/tmp/cvs-serv1532 Modified Files: AtRuleMedia.java CssFouffa.java CssPropertyFactory.java Log Message: java5-isms Index: CssPropertyFactory.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/parser/CssPropertyFactory.java,v retrieving revision 1.22 retrieving revision 1.23 diff -u -d -r1.22 -r1.23 --- CssPropertyFactory.java 27 Sep 2007 10:08:48 -0000 1.22 +++ CssPropertyFactory.java 10 Dec 2008 15:22:58 -0000 1.23 @@ -23,244 +23,244 @@ /** * @version $Revision$ - * @author Philippe Le H�garet + * @author Philippe Le Hegaret */ public class CssPropertyFactory implements Cloneable { - // all recognized properties are here. - private Utf8Properties properties; + // all recognized properties are here. + private Utf8Properties properties; - //all used profiles are here (in the priority order) - private static String[] SORTEDPROFILES = PropertiesLoader.getProfiles(); + //all used profiles are here (in the priority order) + private static String[] SORTEDPROFILES = PropertiesLoader.getProfiles(); - // private Utf8Properties allprops; + // private Utf8Properties allprops; - // does not seem to be used - // private String usermedium; + // does not seem to be used + // private String usermedium; - public CssPropertyFactory getClone() { - try { - return (CssPropertyFactory) clone(); - } catch (CloneNotSupportedException ex) { - ex.printStackTrace(); - return null; - } + public CssPropertyFactory getClone() { + try { + return (CssPropertyFactory) clone(); + } catch (CloneNotSupportedException ex) { + ex.printStackTrace(); + return null; } + } - /** - * Create a new CssPropertyFactory - */ - /* - * public CssPropertyFactory(URL url, URL allprop_url) { properties = new - * Utf8Properties(); InputStream f = null; try { f = url.openStream(); - * properties.load(f); } catch (IOException e) { e.printStackTrace(); } - * finally { try { if (f != null) f.close(); } catch (Exception e) { - * e.printStackTrace(); } // ignore } - * // list of all properties allprops = new Utf8Properties(); InputStream - * f_all = null; try { f_all = allprop_url.openStream(); - * allprops.load(f_all); } catch (IOException e) { e.printStackTrace(); } - * finally { try { if (f_all != null) f_all.close(); } catch (Exception e) { - * e.printStackTrace(); } // ignore } } - */ - - public CssPropertyFactory(String profile) { - properties = PropertiesLoader.getProfile(profile); - // It's not good to have null properties :-/ - if (properties == null) { - throw new NullPointerException(); - } - } + /** + * Create a new CssPropertyFactory + */ + /* + * public CssPropertyFactory(URL url, URL allprop_url) { properties = new + * Utf8Properties(); InputStream f = null; try { f = url.openStream(); + * properties.load(f); } catch (IOException e) { e.printStackTrace(); } + * finally { try { if (f != null) f.close(); } catch (Exception e) { + * e.printStackTrace(); } // ignore } + * // list of all properties allprops = new Utf8Properties(); InputStream + * f_all = null; try { f_all = allprop_url.openStream(); + * allprops.load(f_all); } catch (IOException e) { e.printStackTrace(); } + * finally { try { if (f_all != null) f_all.close(); } catch (Exception e) { + * e.printStackTrace(); } // ignore } } + */ - public String getProperty(String name) { - return properties.getProperty(name); + public CssPropertyFactory(String profile) { + properties = PropertiesLoader.getProfile(profile); + // It's not good to have null properties :-/ + if (properties == null) { + throw new NullPointerException(); } + } - private Vector getVector(String media) { - Vector list = new Vector(4); - String medium = new String(); - StringTokenizer tok = new StringTokenizer(media, ","); + public String getProperty(String name) { + return properties.getProperty(name); + } - while (tok.hasMoreTokens()) { - medium = tok.nextToken(); - medium = medium.trim(); - list.addElement(medium); - } + private Vector<String> getVector(String media) { + Vector<String> list = new Vector<String>(4); + String medium = new String(); + StringTokenizer tok = new StringTokenizer(media, ","); - return list; + while (tok.hasMoreTokens()) { + medium = tok.nextToken(); + medium = medium.trim(); + list.addElement(medium); } - // public void setUserMedium(String usermedium) { - // this.usermedium = usermedium; - // } + return list; + } - // 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(); - int pos = -1; - int pos2 = media.toUpperCase().indexOf("AND"); + // public void setUserMedium(String usermedium) { + // this.usermedium = usermedium; + // } - if (pos2 == -1) { - pos2 = media.length(); - } + // 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(); + int pos = -1; + int pos2 = media.toUpperCase().indexOf("AND"); - if (media.toUpperCase().indexOf("NOT") != -1) { - pos = media.toUpperCase().indexOf("NOT"); - media = media.substring(pos + 4, pos2); - } else if (media.toUpperCase().indexOf("ONLY") != -1) { - pos = media.toUpperCase().indexOf("ONLY"); - media = media.substring(pos + 4, pos2); - } else { - pos = media.indexOf(" "); - media = media.substring(pos + 1, pos2); - } + if (pos2 == -1) { + pos2 = media.length(); + } - media = media.trim(); + if (media.toUpperCase().indexOf("NOT") != -1) { + pos = media.toUpperCase().indexOf("NOT"); + media = media.substring(pos + 4, pos2); + } else if (media.toUpperCase().indexOf("ONLY") != -1) { + pos = media.toUpperCase().indexOf("ONLY"); + media = media.substring(pos + 4, pos2); + } else { + pos = media.indexOf(" "); + media = media.substring(pos + 1, pos2); + } - String classname = properties.getProperty("mediafeature" + "." + property); + media = media.trim(); - if (classname == null) { - if (atRule instanceof AtRuleMedia && (!media.equals("all"))) { - // 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 { - // I don't know this property - throw new InvalidParamException("noexistence", property, media, ac); - } - } + String classname = properties.getProperty("mediafeature" + "." + property); - try { - // create an instance of your property class - Class expressionclass = new CssExpression().getClass(); - if (expression != null) { - expressionclass = expression.getClass(); - } - // Maybe it will be necessary to add the check parameter as for - // create property, so... FIXME - Class[] parametersType = { ac.getClass(), expressionclass }; - Constructor constructor = Class.forName(classname).getConstructor(parametersType); - Object[] parameters = { ac, expression }; - // invoke the constructor - return (CssProperty) constructor.newInstance(parameters); - } catch (InvocationTargetException e) { - // catch InvalidParamException - InvocationTargetException iv = e; - Exception ex = (Exception) iv.getTargetException(); - throw ex; - } + if (classname == null) { + if (atRule instanceof AtRuleMedia && (!media.equals("all"))) { + // 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 { + // I don't know this property + throw new InvalidParamException("noexistence", property, media, ac); + } + } + try { + // create an instance of your property class + Class expressionclass = new CssExpression().getClass(); + if (expression != null) { + expressionclass = expression.getClass(); + } + // Maybe it will be necessary to add the check parameter as for + // create property, so... FIXME + Class[] parametersType = { ac.getClass(), expressionclass }; + Constructor constructor = Class.forName(classname).getConstructor(parametersType); + Object[] parameters = { ac, expression }; + // invoke the constructor + return (CssProperty) constructor.newInstance(parameters); + } catch (InvocationTargetException e) { + // catch InvalidParamException + InvocationTargetException iv = e; + Exception ex = (Exception) iv.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(); - } + 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 ((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); - } + if (pos2 == -1) { + pos2 = media.length(); + } - media = media.trim(); + 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); + } - classname = setClassName(atRule, media, ac, property); + media = media.trim(); + + classname = setClassName(atRule, media, ac, property); - // the property does not exist in this profile - // this is an error... or a warning if it exists in another profile - if (classname == null) { - ArrayList pfsOk = new ArrayList(); + // the property does not exist in this profile + // this is an error... or a warning if it exists in another profile + if (classname == null) { + ArrayList<String> pfsOk = new ArrayList<String>(); - for (int i=0; i<SORTEDPROFILES.length; ++i) { - String p = String.valueOf(SORTEDPROFILES[i]); - if (!p.equals(ac.getCssVersion()) && PropertiesLoader.getProfile(p).containsKey(property)) { - pfsOk.add(p); - } - } + for (int i=0; i<SORTEDPROFILES.length; ++i) { + String p = String.valueOf(SORTEDPROFILES[i]); + if (!p.equals(ac.getCssVersion()) && PropertiesLoader.getProfile(p).containsKey(property)) { + pfsOk.add(p); + } + } - if (pfsOk.size() > 0) { - /* - // This should be uncommented when no-profile in enabled - if (ac.getProfile().equals("none")) { - // the last one should be the best one to use - String pf = (String) pfsOk.get(pfsOk.size()-1), - old_pf = ac.getCssVersion(); - 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.getCssVersion()), pfsOk.toString() }, ac); - } else { - throw new InvalidParamException("noexistence-at-all", property, ac); - } + if (pfsOk.size() > 0) { + /* + // This should be uncommented when no-profile in enabled + if (ac.getProfile().equals("none")) { + // the last one should be the best one to use + String pf = (String) pfsOk.get(pfsOk.size()-1), + old_pf = ac.getCssVersion(); + 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.getCssVersion()), pfsOk.toString() }, ac); + } else { + throw new InvalidParamException("noexistence-at-all", property, ac); + } + } - CssIdent initial = new CssIdent("initial"); + CssIdent initial = new CssIdent("initial"); - try { - if (expression.getValue().equals(initial) && ac.getCssVersion().equals("css3")) { - // create an instance of your property class - Class[] parametersType = {}; - Constructor constructor = Class.forName(classname).getConstructor(parametersType); - Object[] parameters = {}; - // invoke the constructor - return (CssProperty) constructor.newInstance(parameters); - } else { - // create an instance of your property class - Class[] parametersType = { ac.getClass(), expression.getClass(), boolean.class }; - Constructor constructor = Class.forName(classname).getConstructor(parametersType); - Object[] parameters = { ac, expression, new Boolean(true) }; - // invoke the constructor - return (CssProperty) constructor.newInstance(parameters); + try { + if (expression.getValue().equals(initial) && ac.getCssVersion().equals("css3")) { + // create an instance of your property class + Class[] parametersType = {}; + Constructor constructor = Class.forName(classname).getConstructor(parametersType); + Object[] parameters = {}; + // invoke the constructor + return (CssProperty) constructor.newInstance(parameters); + } else { + // create an instance of your property class + Class[] parametersType = { ac.getClass(), expression.getClass(), boolean.class }; + Constructor constructor = Class.forName(classname).getConstructor(parametersType); + Object[] parameters = { ac, expression, new Boolean(true) }; + // invoke the constructor + return (CssProperty) constructor.newInstance(parameters); - } - } catch (InvocationTargetException e) { - // catch InvalidParamException - InvocationTargetException iv = e; - Exception ex = (Exception) iv.getTargetException(); - throw ex; - } + } + } catch (InvocationTargetException e) { + // catch InvalidParamException + InvocationTargetException iv = e; + Exception ex = (Exception) iv.getTargetException(); + throw ex; } + } - private String setClassName(AtRule atRule, String media, ApplContext ac, String property) { - String className; - Vector list = new Vector(getVector(media)); - if (atRule instanceof AtRuleMedia) { - className = PropertiesLoader.getProfile(ac.getCssVersion()).getProperty(property); - // a list of media has been specified - if (className != null && !media.equals("all")) { - String propMedia = PropertiesLoader.mediaProperties.getProperty(property); - for (int i = 0; i < list.size(); i++) { - String medium = (String) list.elementAt(i); - if (propMedia.indexOf(medium.toLowerCase()) == -1 && !propMedia.equals("all")) { - ac.getFrame().addWarning("noexistence-media", new String[] { property, medium + " (" + propMedia + ")" }); - } - } - } - } else { - className = PropertiesLoader.getProfile(ac.getCssVersion()).getProperty("@" + atRule.keyword() + "." + property); + private String setClassName(AtRule atRule, String media, ApplContext ac, String property) { + String className; + Vector<String> list = new Vector<String>(getVector(media)); + if (atRule instanceof AtRuleMedia) { + className = PropertiesLoader.getProfile(ac.getCssVersion()).getProperty(property); + // a list of media has been specified + if (className != null && !media.equals("all")) { + String propMedia = PropertiesLoader.mediaProperties.getProperty(property); + for (int i = 0; i < list.size(); i++) { + String medium = list.elementAt(i); + if (propMedia.indexOf(medium.toLowerCase()) == -1 && !propMedia.equals("all")) { + ac.getFrame().addWarning("noexistence-media", new String[] { property, medium + " (" + propMedia + ")" }); + } } - return className; + } + } else { + className = PropertiesLoader.getProfile(ac.getCssVersion()).getProperty("@" + atRule.keyword() + "." + property); } + return className; + } } Index: AtRuleMedia.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/parser/AtRuleMedia.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- AtRuleMedia.java 26 Nov 2007 05:07:17 -0000 1.11 +++ AtRuleMedia.java 10 Dec 2008 15:22:58 -0000 1.12 @@ -34,7 +34,7 @@ String[] media = new String[mediaCSS3.length]; // media list coming from the stylesheet (ie. with case) String[] originalMedia = new String[mediaCSS3.length]; - Vector mediafeatures = new Vector(); + Vector<String> mediafeatures = new Vector<String>(); boolean empty = true; @@ -72,11 +72,12 @@ public void addMediaFeature(CssProperty prop) { if (prop != null) { - String expression = prop.getPropertyName(); - if (prop.toString() != null) { - expression += " : " + prop.toString(); + StringBuilder expression = new StringBuilder(prop.getPropertyName()); + String propval = prop.toString(); + if (propval != null) { + expression.append(" : ").append(propval); } - mediafeatures.addElement(expression); + mediafeatures.addElement(expression.toString()); } } @@ -137,7 +138,7 @@ * Returns a string representation of the object. */ public String toString() { - StringBuffer ret = new StringBuffer(); + StringBuilder ret = new StringBuilder(); ret.append('@'); ret.append(keyword()); @@ -161,7 +162,7 @@ for (int i = 0; i < mediafeatures.size(); i++) { ret.append(" and ("); - ret.append(((String)mediafeatures.elementAt(i))); + ret.append(mediafeatures.elementAt(i)); ret.append(')'); } return ret.toString(); Index: CssFouffa.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/parser/CssFouffa.java,v retrieving revision 1.42 retrieving revision 1.43 diff -u -d -r1.42 -r1.43 --- CssFouffa.java 11 Mar 2008 10:15:14 -0000 1.42 +++ CssFouffa.java 10 Dec 2008 15:22:58 -0000 1.43 @@ -79,7 +79,7 @@ // static private Utf8Properties config = null; // all listeners - Vector listeners; + Vector<CssValidatorListener> listeners; // all errors Errors errors; @@ -87,7 +87,7 @@ // origin of the style sheet int origin; - Vector visited = null; + Vector<String> visited = null; /** * Create a new CssFouffa with a data input and a begin line number. @@ -148,7 +148,7 @@ } properties = new CssPropertyFactory(profile); - listeners = new Vector(); + listeners = new Vector<CssValidatorListener>(); } /** @@ -203,7 +203,7 @@ * @exception IOException * if an I/O error occurs. */ - private CssFouffa(ApplContext ac, InputStream in, URL url, Vector listeners, Vector urlvisited, + private CssFouffa(ApplContext ac, InputStream in, URL url, Vector<CssValidatorListener> listeners, Vector<String> urlvisited, CssPropertyFactory cssfactory, boolean mode) throws IOException { this(ac, in, url, 0); this.visited = urlvisited; @@ -387,9 +387,9 @@ } // That's all folks, notify all errors and warnings - for (Enumeration e = listeners.elements(); e.hasMoreElements();) { + for (Enumeration<CssValidatorListener> e = listeners.elements(); e.hasMoreElements();) { CssValidatorListener listener; - listener = (CssValidatorListener) e.nextElement(); + listener = e.nextElement(); listener.notifyErrors(ac.getFrame().getErrors()); listener.notifyWarnings(ac.getFrame().getWarnings()); } @@ -417,7 +417,7 @@ String surl = importedURL.toString(); if (visited == null) { - visited = new Vector(2); + visited = new Vector<String>(2); } else { // check that we didn't already got this URL, or that the // number of imports is not exploding @@ -431,7 +431,7 @@ return; } } - Vector newVisited = (Vector) visited.clone(); + Vector<String> newVisited = new Vector<String>(visited); newVisited.addElement(surl); if (Util.importSecurity) { @@ -486,9 +486,9 @@ */ public void handleAtRule(String ident, String string) { if (mode) { - Enumeration e = listeners.elements(); + Enumeration<CssValidatorListener> e = listeners.elements(); while (e.hasMoreElements()) { - CssValidatorListener listener = (CssValidatorListener) e.nextElement(); + CssValidatorListener listener = e.nextElement(); listener.handleAtRule(ac, ident, string); } } else { @@ -593,8 +593,8 @@ } if (!Util.noErrorTrace) { - for (Enumeration e = listeners.elements(); e.hasMoreElements();) { - CssValidatorListener listener = (CssValidatorListener) e.nextElement(); + for (Enumeration<CssValidatorListener> e = listeners.elements(); e.hasMoreElements();) { + CssValidatorListener listener = e.nextElement(); listener.notifyErrors(ac.getFrame().getErrors()); listener.notifyWarnings(ac.getFrame().getWarnings()); } @@ -610,8 +610,8 @@ * added to the storage for the output */ public void newAtRule(AtRule atRule) { - for (Enumeration e = listeners.elements(); e.hasMoreElements();) { - ((CssValidatorListener) e.nextElement()).newAtRule(atRule); + for (Enumeration<CssValidatorListener> e = listeners.elements(); e.hasMoreElements();) { + e.nextElement().newAtRule(atRule); } } @@ -623,8 +623,8 @@ * @charset rule that has been found by the parser */ public void addCharSet(String charset) { - for (Enumeration e = listeners.elements(); e.hasMoreElements();) { - ((CssValidatorListener) e.nextElement()).addCharSet(charset); + for (Enumeration<CssValidatorListener> e = listeners.elements(); e.hasMoreElements();) { + e.nextElement().addCharSet(charset); } } @@ -635,8 +635,8 @@ * in it. */ public void endOfAtRule() { - for (Enumeration e = listeners.elements(); e.hasMoreElements();) { - ((CssValidatorListener) e.nextElement()).endOfAtRule(); + for (Enumeration<CssValidatorListener> e = listeners.elements(); e.hasMoreElements();) { + e.nextElement().endOfAtRule(); } } @@ -647,8 +647,8 @@ * true if the rule was declared important in the stylesheet */ public void setImportant(boolean important) { - for (Enumeration e = listeners.elements(); e.hasMoreElements();) { - ((CssValidatorListener) e.nextElement()).setImportant(important); + for (Enumeration<CssValidatorListener> e = listeners.elements(); e.hasMoreElements();) { + e.nextElement().setImportant(important); } } @@ -660,8 +660,8 @@ * stylesheet */ public void setSelectorList(Vector selectors) { - for (Enumeration e = listeners.elements(); e.hasMoreElements();) { - ((CssValidatorListener) e.nextElement()).setSelectorList(selectors); + for (Enumeration<CssValidatorListener> e = listeners.elements(); e.hasMoreElements();) { + e.nextElement().setSelectorList(selectors); } } @@ -674,8 +674,8 @@ * @rule) */ public void addProperty(Vector properties) { - for (Enumeration e = listeners.elements(); e.hasMoreElements();) { - ((CssValidatorListener) e.nextElement()).setProperty(properties); + for (Enumeration<CssValidatorListener> e = listeners.elements(); e.hasMoreElements();) { + e.nextElement().setProperty(properties); } } @@ -684,8 +684,8 @@ * been read by the parser */ public void endOfRule() { - for (Enumeration e = listeners.elements(); e.hasMoreElements();) { - ((CssValidatorListener) e.nextElement()).endOfRule(); + for (Enumeration<CssValidatorListener> e = listeners.elements(); e.hasMoreElements();) { + e.nextElement().endOfRule(); } } @@ -695,8 +695,8 @@ * won't appear on the screen */ public void removeThisRule() { - for (Enumeration e = listeners.elements(); e.hasMoreElements();) { - ((CssValidatorListener) e.nextElement()).removeThisRule(); + for (Enumeration<CssValidatorListener> e = listeners.elements(); e.hasMoreElements();) { + e.nextElement().removeThisRule(); } } @@ -707,8 +707,8 @@ * @rule from the memorystructure so that it won't appear on the screen */ public void removeThisAtRule() { - for (Enumeration e = listeners.elements(); e.hasMoreElements();) { - ((CssValidatorListener) e.nextElement()).removeThisAtRule(); + for (Enumeration<CssValidatorListener> e = listeners.elements(); e.hasMoreElements();) { + e.nextElement().removeThisAtRule(); } } @@ -721,8 +721,8 @@ * Properties to associate with contexts */ public void handleRule(CssSelectors selector, Vector declarations) { - for (Enumeration e = listeners.elements(); e.hasMoreElements();) { - ((CssValidatorListener) e.nextElement()).handleRule(ac, selector, declarations); + for (Enumeration<CssValidatorListener> e = listeners.elements(); e.hasMoreElements();) { + e.nextElement().handleRule(ac, selector, declarations); } }
Received on Wednesday, 10 December 2008 15:23:12 UTC