- From: Yves Lafon via cvs-syncmail <cvsmail@w3.org>
- Date: Thu, 09 Feb 2012 17:36:28 +0000
- To: www-validator-cvs@w3.org
Update of /sources/public/2002/css-validator/org/w3c/css/css In directory hutz:/tmp/cvs-serv25830/w3c/css/css Modified Files: CssParser.java HTMLParserStyleSheetHandler.java StyleSheetParser.java TagSoupStyleSheetHandler.java XMLStyleSheetHandler.java Log Message: various things: Use of BigIntegers to avoid limits, background-* are now avoiding multiplication of checks and properties in CssXStyles impls, various updates for other properties, use of a string reader for string input, added the possibility of not following links, prepared for aggregation of all uris parsed Index: CssParser.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/css/CssParser.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- CssParser.java 14 Sep 2005 15:14:17 -0000 1.6 +++ CssParser.java 9 Feb 2012 17:36:26 -0000 1.7 @@ -7,131 +7,151 @@ package org.w3c.css.css; +import org.w3c.css.util.ApplContext; + import java.io.IOException; import java.io.InputStream; +import java.io.Reader; import java.net.URL; -import org.w3c.css.util.ApplContext; - /** * This class describes how to implements your cascading * style sheet parser. - * + * <p/> * You must implements this interfaces if you want to have * a backward compatibilitie with other CSS parser. - * <p> + * <p/> * Typically, it is used like this : - * <p> + * <p/> * <code> - * YourParser parser = new YourParser();<br> - * parser.parseURL(yourURLDocument, StyleSheetOrigin.USER);<br> - * StyleSheet style = parser.getStyleSheet();<br> - * // here, i want an HTML document to output<br> - * StyleSheetGenerator.setDocumentBase("html.properties");<br> - * StyleSheetGenerator generator = new StyleSheetGenerator("foo", - * style, - * "foo.css", - * 2);<br> - * generator.print(new PrintStream(System.out));<br> + * YourParser parser = new YourParser();<br> + * parser.parseURL(yourURLDocument, StyleSheetOrigin.USER);<br> + * StyleSheet style = parser.getStyleSheet();<br> + * // here, i want an HTML document to output<br> + * StyleSheetGenerator.setDocumentBase("html.properties");<br> + * StyleSheetGenerator generator = new StyleSheetGenerator("foo", + * style, + * "foo.css", + * 2);<br> + * generator.print(new PrintStream(System.out));<br> * </code> * - * @see org.w3c.css.css.StyleSheetParser * @version $Revision$ + * @see org.w3c.css.css.StyleSheetParser */ public interface CssParser { - /** - * Reinitialize this parser - */ - public abstract void reInit(); + /** + * Reinitialize this parser + */ + public abstract void reInit(); - /** - * Get the style sheet after a parse. - * - * @return The resulted style sheet - */ - public abstract StyleSheet getStyleSheet(); + /** + * Get the style sheet after a parse. + * + * @return The resulted style sheet + */ + public abstract StyleSheet getStyleSheet(); /** - * @param url the URL containing the style sheet - * @param title the title of the stylesheet - * @param kind may be a stylesheet or an alternate stylesheet - * @param media the media to apply this + * @param url the URL containing the style sheet + * @param title the title of the stylesheet + * @param kind may be a stylesheet or an alternate stylesheet + * @param media the media to apply this * @param origin the origin of the style sheet - * @exception IOException an IO error + * @throws IOException an IO error */ public void parseURL(ApplContext ac, URL url, String title, String kind, - String media, int origin); + String media, int origin); - /** - * Parse a STYLE element. - * The real difference between this method and the precedent - * is that this method can take a string. The URL is used - * to resolve import statement and URL statement in the style - * sheet. - * <p> - * For a backward compatibility, <code>parseStyleElement</code> and - * <code>parseStyleAttribute</code> use a string for the input. - * - * @param input the input string. - * @param url the URL where the input stream comes from. - * @param lineno The number line in the source document. - * It is used for error message - * @deprecated Replaced by parseStyleElement - * @see #parseStyleElement(InputStream, URL, int) - */ - public abstract void parseStyleElement(ApplContext ac, String input, - URL url, int lineno); + /** + * Parse a STYLE element. + * The real difference between this method and the precedent + * is that this method can take a string. The URL is used + * to resolve import statement and URL statement in the style + * sheet. + * <p/> + * For a backward compatibility, <code>parseStyleElement</code> and + * <code>parseStyleAttribute</code> use a string for the input. + * + * @param input the input string. + * @param url the URL where the input stream comes from. + * @param lineno The number line in the source document. + * It is used for error message + * @see #parseStyleElement(InputStream, URL, int) + * @deprecated Replaced by parseStyleElement + */ + public abstract void parseStyleElement(ApplContext ac, String input, + URL url, int lineno); - /** - * Parse a STYLE element. - * The real difference between this method and the precedent - * is that this method can take an InputStream. The URL is used - * to resolve import statement and URL statement in the style - * sheet. - * - * @param input the input stream. - * @param title the title of the style element - * @param media the media of the style element - * @param url the URL where the input stream comes from. - * @param lineno The number line in the source document. It is used for error message - */ - public abstract void parseStyleElement(ApplContext ac, InputStream input, - String title, String media, URL url, - int lineno); + /** + * Parse a STYLE element. + * The real difference between this method and the precedent + * is that this method can take an InputStream. The URL is used + * to resolve import statement and URL statement in the style + * sheet. + * + * @param input the input stream. + * @param title the title of the style element + * @param media the media of the style element + * @param url the URL where the input stream comes from. + * @param lineno The number line in the source document. It is used for error message + */ + public abstract void parseStyleElement(ApplContext ac, InputStream input, + String title, String media, URL url, + int lineno); - /** - * Parser a STYLE attribute. - * Here, you must generate your own uniq id for the context. - * After, you can reference this style attribute by the id. - * <p> - * <strong>Be careful, the id must be uniq !</strong> - * <p> - * For a backward compatibility, <code>parseStyleElement</code> and - * <code>parseStyleAttribute</code> use a string for the input. - * - * @param input the input string. - * @param id your uniq id to reference this style attribute. - * @param url the URL where the input stream comes from. - * @param lineno The number line in the source document. It is used for error message. - * @deprecated Replaced by parseStyleAttribute - * @see #parseStyleAttribute(InputStream, String, URL, int) - */ - public abstract void parseStyleAttribute(ApplContext ac, String input, String id, URL url, int lineno); + /** + * Parse a STYLE element. + * The real difference between this method and the precedent + * is that this method can take an InputStream. The URL is used + * to resolve import statement and URL statement in the style + * sheet. + * + * @param reader the input reader. + * @param title the title of the style element + * @param media the media of the style element + * @param url the URL where the input stream comes from. + * @param lineno The number line in the source document. It is used for error message + */ + public abstract void parseStyleElement(ApplContext ac, Reader reader, + String title, String media, URL url, + int lineno); - /** - * Parser a STYLE attribute. - * Here, you must generate your own uniq id for the context. - * After, you can reference this style attribute by the id. - * <p> - * <strong>Be careful, the id must be uniq !</strong> - * - * @param input the input stream. - * @param id your uniq id to reference this style attribute. - * @param url the URL where the input stream comes from. - * @param lineno The number line in the source document. It is used for error message. - */ - public abstract void parseStyleAttribute(ApplContext ac, InputStream input, - String id, URL url, int lineno); + + /** + * Parser a STYLE attribute. + * Here, you must generate your own uniq id for the context. + * After, you can reference this style attribute by the id. + * <p/> + * <strong>Be careful, the id must be uniq !</strong> + * <p/> + * For a backward compatibility, <code>parseStyleElement</code> and + * <code>parseStyleAttribute</code> use a string for the input. + * + * @param ac the validation context + * @param input the input string. + * @param id your uniq id to reference this style attribute. + * @param url the URL where the input stream comes from. + * @param lineno The number line in the source document. It is used for error message. + * @see #parseStyleAttribute(ApplContext, InputStream, String, URL, int) + * @deprecated Replaced by parseStyleAttribute + */ + public abstract void parseStyleAttribute(ApplContext ac, String input, String id, URL url, int lineno); + + /** + * Parser a STYLE attribute. + * Here, you must generate your own uniq id for the context. + * After, you can reference this style attribute by the id. + * <p/> + * <strong>Be careful, the id must be uniq !</strong> + * + * @param input the input stream. + * @param id your uniq id to reference this style attribute. + * @param url the URL where the input stream comes from. + * @param lineno The number line in the source document. It is used for error message. + */ + public abstract void parseStyleAttribute(ApplContext ac, InputStream input, + String id, URL url, int lineno); } Index: StyleSheetParser.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/css/StyleSheetParser.java,v retrieving revision 1.24 retrieving revision 1.25 diff -u -d -r1.24 -r1.25 --- StyleSheetParser.java 3 Nov 2011 16:00:39 -0000 1.24 +++ StyleSheetParser.java 9 Feb 2012 17:36:26 -0000 1.25 @@ -30,7 +30,10 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; import java.io.StringReader; +import java.io.UnsupportedEncodingException; import java.lang.reflect.Constructor; import java.net.URL; import java.util.ArrayList; @@ -263,11 +266,11 @@ /** * Parse a style element. The Style element always comes from the user * - * @param input the inputStream containing the style data - * @param url the name of the file the style element was read in. + * @param reader the reader containing the style data + * @param url the name of the file the style element was read in. * @throws IOException an IO error */ - public void parseStyleElement(ApplContext ac, InputStream input, + public void parseStyleElement(ApplContext ac, Reader reader, String title, String media, URL url, int lineno) { boolean doneref = false; @@ -282,7 +285,7 @@ // if (cssFouffa == null) { String charset = ac.getCharsetForURL(url); - cssFouffa = new CssFouffa(ac, input, charset, url, lineno); + cssFouffa = new CssFouffa(ac, reader, url, lineno); cssFouffa.addListener(this); // } else { // cssFouffa.ReInit(ac, input, url, lineno); @@ -358,8 +361,33 @@ * @deprecated Replaced by parseStyleElement */ public void parseStyleElement(ApplContext ac, String input, URL url, int lineno) { - parseStyleElement(ac, new ByteArrayInputStream(input.getBytes()), - null, null, url, lineno); + parseStyleElement(ac, new StringReader(input), null, null, url, lineno); + } + + /** + * Parse a style element. The Style element always comes from the user + * + * @param input the input stream containing the style data + * @param url the name of the file the style element was read in. + * @throws IOException an IO error + */ + public void parseStyleElement(ApplContext ac, InputStream input, + String title, String media, + URL url, int lineno) { + InputStreamReader reader = null; + String charset = ac.getCharsetForURL(url); + try { + reader = new InputStreamReader(input, (charset == null) ? + "iso-8859-1" : charset); + } catch (UnsupportedEncodingException uex) { + Errors er = new Errors(); + er.addError(new org.w3c.css.parser.CssError(url.toString(), + -1, uex)); + notifyErrors(er); + } + if (reader != null) { + parseStyleElement(ac, reader, title, media, url, lineno); + } } /** Index: XMLStyleSheetHandler.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/css/XMLStyleSheetHandler.java,v retrieving revision 1.34 retrieving revision 1.35 diff -u -d -r1.34 -r1.35 --- XMLStyleSheetHandler.java 3 Nov 2011 16:00:39 -0000 1.34 +++ XMLStyleSheetHandler.java 9 Feb 2012 17:36:26 -0000 1.35 @@ -38,7 +38,7 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; -import java.io.StringBufferInputStream; +import java.io.StringReader; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; @@ -377,7 +377,7 @@ + "]"); } styleSheetParser.parseStyleElement(ac, - new StringBufferInputStream(text.toString()), + new StringReader(text.toString()), title, media, documentURI, line); } } Index: HTMLParserStyleSheetHandler.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/css/HTMLParserStyleSheetHandler.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- HTMLParserStyleSheetHandler.java 3 Nov 2011 16:00:39 -0000 1.3 +++ HTMLParserStyleSheetHandler.java 9 Feb 2012 17:36:26 -0000 1.4 @@ -39,7 +39,7 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; -import java.io.StringBufferInputStream; +import java.io.StringReader; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; @@ -412,7 +412,7 @@ } styleSheetParser .parseStyleElement(ac, - new StringBufferInputStream(text.toString()), + new StringReader(text.toString()), title, media, documentURI, line); } Index: TagSoupStyleSheetHandler.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/css/TagSoupStyleSheetHandler.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- TagSoupStyleSheetHandler.java 3 Nov 2011 16:00:39 -0000 1.11 +++ TagSoupStyleSheetHandler.java 9 Feb 2012 17:36:26 -0000 1.12 @@ -39,7 +39,7 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; -import java.io.StringBufferInputStream; +import java.io.StringReader; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; @@ -406,7 +406,7 @@ } styleSheetParser .parseStyleElement(ac, - new StringBufferInputStream(text.toString()), + new StringReader(text.toString()), title, media, documentURI, line); }
Received on Thursday, 9 February 2012 17:37:07 UTC