- From: Yves Lafon via cvs-syncmail <cvsmail@w3.org>
- Date: Wed, 10 Dec 2008 15:10:17 +0000
- To: www-validator-cvs@w3.org
Update of /sources/public/2002/css-validator/org/w3c/css/css In directory hutz:/tmp/cvs-serv26442/org/w3c/css/css Modified Files: StyleSheetGenerator.java TagSoupStyleSheetHandler.java Log Message: Fix for http://www.w3.org/Bugs/Public/show_bug.cgi?id=6297 Handling TokenMgrError while processing CSS fragments in HTML (we might ass other errors if needed). Reworked CssError to access Exceptions and Errors (Throwable), and modified StyleSheetGenerator accordingly. + some remaining optimisation+templating Index: StyleSheetGenerator.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/css/StyleSheetGenerator.java,v retrieving revision 1.18 retrieving revision 1.19 diff -u -d -r1.18 -r1.19 --- StyleSheetGenerator.java 3 Jul 2008 14:20:39 -0000 1.18 +++ StyleSheetGenerator.java 10 Dec 2008 15:10:15 -0000 1.19 @@ -29,6 +29,7 @@ import org.w3c.css.util.Messages; import org.w3c.css.util.Utf8Properties; import org.w3c.css.util.Warnings; +import org.w3c.css.util.Warning; /** * @author Julien Grand-Mourcel @@ -120,7 +121,7 @@ String name; for (int i = 0; i < Messages.languages_name.size(); ++i) { name = String.valueOf(Messages.languages_name.get(i)); - HashMap l = new HashMap(); + HashMap<String,String> l = new HashMap<String,String>(); l.put("name", name); l.put("real", ((Utf8Properties) Messages.languages.get(name)).getProperty("language_name")); languages[i] = l; @@ -234,8 +235,8 @@ int nbError = error.length; for (int i=0; i < nbError; i++) { CssError csserror = error[i]; - Exception ex = csserror.getException(); - Hashtable h = new Hashtable(); + Throwable ex = csserror.getException(); + Hashtable<String,Object> h = new Hashtable<String,Object>(); errors_content[i] = h; h.put("Error", csserror); h.put("CtxName", "nocontext"); @@ -312,7 +313,7 @@ * @param error, the error to check * @param ht_error, the Hastable with information about this error */ - private void produceParseException(CssParseException error, Hashtable ht_error) { + private void produceParseException(CssParseException error, Hashtable<String,Object> ht_error) { if (error.getContexts() != null && error.getContexts().size() != 0) { ht_error.put("CtxName", "codeContext"); StringBuffer buf = new StringBuffer(); @@ -390,7 +391,7 @@ private String queryReplace(String s) { if (s != null) { int len = s.length(); - StringBuffer ret = new StringBuffer(len); + StringBuilder ret = new StringBuilder(len+16); char c; for (int i = 0; i < len; i++) { Index: TagSoupStyleSheetHandler.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/css/TagSoupStyleSheetHandler.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- TagSoupStyleSheetHandler.java 18 Sep 2007 17:59:21 -0000 1.4 +++ TagSoupStyleSheetHandler.java 10 Dec 2008 15:10:15 -0000 1.5 @@ -20,10 +20,12 @@ import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; -import java.util.Hashtable; +import java.util.HashMap; import org.w3c.css.parser.CssError; import org.w3c.css.parser.Errors; +import org.w3c.css.parser.Errors; +import org.w3c.css.parser.analyzer.TokenMgrError; import org.w3c.css.util.Warning; import org.w3c.css.util.Warnings; import org.w3c.css.util.ApplContext; @@ -70,7 +72,7 @@ String media = null; String type = null; String title = null; - StringBuffer text = new StringBuffer(255); + StringBuilder text = new StringBuilder(255); Locator locator; @@ -132,12 +134,12 @@ public void processingInstruction (String target, String data) throws SAXException { - Hashtable atts = getValues(data); + HashMap<String,String> atts = getValues(data); if ("xml-stylesheet".equals(target)) { - String rel = (String) atts.get("alternate"); - String type = (String) atts.get("type"); - String href = (String) atts.get("href"); + String rel = atts.get("alternate"); + String type = atts.get("type"); + String href = atts.get("href"); if (Util.onDebug) { System.err.println("<?xml-stylesheet alternate=\"" + rel @@ -195,13 +197,13 @@ + "should parse CSS url: " + url.toString() + "]"); } - String media = (String) atts.get("media"); + String media = atts.get("media"); if (media == null) { media="all"; } styleSheetParser.parseURL(ac, url, - (String) atts.get("title"), + atts.get("title"), rel, media, StyleSheetOrigin.AUTHOR); @@ -408,19 +410,29 @@ public void handleStyleAttribute(String value, String id) { if (id == null) { // but we have no id: create one. // a normal id should NOT contain a "#" character. - id = "#autoXML" + autoIdCount; - // workaround a java hashcode bug. - id += "" + autoIdCount++; + StringBuilder sb = new StringBuilder("#autoXML"); + sb.append(autoIdCount); + // FIXME why two times? + sb.append(autoIdCount++); + id = sb.toString(); } int line = 0; if (locator != null) { line = locator.getLineNumber(); } // parse the style attribute. - styleSheetParser - .parseStyleAttribute(ac, - new ByteArrayInputStream(value.getBytes()), - id, documentURI, line); + try { + styleSheetParser + .parseStyleAttribute(ac, + new ByteArrayInputStream(value.getBytes()), + id, documentURI, line); + } catch (TokenMgrError ex) { + CssError err = new CssError(baseURI.toString(), line, + ex); + Errors errs = new Errors(); + errs.addError(err); + styleSheetParser.notifyErrors(errs); + } } public StyleSheet getStyleSheet() { @@ -617,15 +629,15 @@ } } - Hashtable getValues(String data) { + HashMap<String,String> getValues(String data) { int length = data.length(); int current = 0; char c; - StringBuffer name = new StringBuffer(10); - StringBuffer value = new StringBuffer(128); - StringBuffer entity_name = new StringBuffer(16); + StringBuilder name = new StringBuilder(10); + StringBuilder value = new StringBuilder(128); + StringBuilder entity_name = new StringBuilder(16); int state = 0; - Hashtable table = new Hashtable(); + HashMap<String,String> table = new HashMap<String,String>(); while (current < length) { c = data.charAt(current);
Received on Wednesday, 10 December 2008 15:10:28 UTC