- From: Yves Lafon via cvs-syncmail <cvsmail@w3.org>
- Date: Fri, 13 Feb 2009 21:50:17 +0000
- To: www-validator-cvs@w3.org
Update of /sources/public/2002/css-validator/org/w3c/css/parser In directory hutz:/tmp/cvs-serv11022/org/w3c/css/parser Modified Files: CssFouffa.java Log Message: multi-byte handling, more comprehensive use of charsets, while trying to preserve BOM support Index: CssFouffa.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/parser/CssFouffa.java,v retrieving revision 1.46 retrieving revision 1.47 diff -u -d -r1.46 -r1.47 --- CssFouffa.java 13 Feb 2009 14:03:36 -0000 1.46 +++ CssFouffa.java 13 Feb 2009 21:50:15 -0000 1.47 @@ -13,6 +13,7 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; +import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLConnection; @@ -33,8 +34,6 @@ import org.w3c.css.util.Util; import org.w3c.css.values.CssExpression; -import org.apache.velocity.io.UnicodeInputStream; - /** * This class is a front end of the CSS1 parser. * @@ -101,8 +100,10 @@ * @exception IOException * if an I/O error occurs. */ - public CssFouffa(ApplContext ac, InputStream input, URL file, int beginLine) throws IOException { - super(new UnicodeInputStream(input)); + public CssFouffa(ApplContext ac, InputStream input, String charset, URL file, int beginLine) + throws IOException + { + super(new InputStreamReader(input, (charset == null) ? "iso-8859-1" : charset)); if (ac.getOrigin() == -1) { setOrigin(StyleSheetOrigin.AUTHOR); // default is user } else { @@ -162,7 +163,7 @@ * if an I/O error occurs. */ public CssFouffa(ApplContext ac, InputStream input, URL file) throws IOException { - this(ac, input, file, 0); + this(ac, input, "iso-8859-1", file, 0); } /** @@ -185,7 +186,8 @@ */ private CssFouffa(ApplContext ac, URLConnection uco) throws IOException { - this(ac, HTTPURL.getInputStream(uco), uco.getURL(), 0); + this(ac, HTTPURL.getInputStream(ac, uco), + HTTPURL.getCharacterEncoding(ac,uco), uco.getURL(), 0); String httpCL = uco.getHeaderField("Content-Location"); if (httpCL != null) { setURL(HTTPURL.getURL(getURL(), httpCL)); @@ -203,9 +205,11 @@ * @exception IOException * if an I/O error occurs. */ - private CssFouffa(ApplContext ac, InputStream in, URL url, Vector<CssValidatorListener> listeners, Vector<String> 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(ac, in, ac.getCharsetForURL(url), url, 0); this.visited = urlvisited; setURL(url); ac.setFrame(new Frame(this, url.toString(), ac.getWarningLevel())); @@ -218,7 +222,7 @@ private void ReInit(ApplContext ac, InputStream input, URL file, Frame frame) { // reinitialize the parser with a new data input // and a new frame for errors and warnings - super.ReInitWithAc(input, ac); + super.ReInitWithAc(input, ac, ac.getCharsetForURL(file)); // @@this is a default media ... // AtRuleMedia media; // if ("css1".equals(ac.getCssVersion())) { @@ -277,7 +281,9 @@ * @exception IOException * if an I/O error occurs. */ - public void ReInit(ApplContext ac, InputStream input, URL file, int beginLine) throws IOException { + public void ReInit(ApplContext ac, InputStream input, URL file, int beginLine) + throws IOException + { Frame f = new Frame(this, file.toString(), beginLine, ac.getWarningLevel()); ac.setFrame(f); ReInit(ac, input, file, f); @@ -312,7 +318,7 @@ Frame f = new Frame(this, file.toString(), ac.getWarningLevel()); ac.setFrame(f); URLConnection urlC = HTTPURL.getConnection(file, ac); - ReInit(ac, urlC.getInputStream(), urlC.getURL(), f); + ReInit(ac, HTTPURL.getInputStream(ac, urlC), urlC.getURL(), f); } /** @@ -458,6 +464,7 @@ } URLConnection importURL = HTTPURL.getConnection(importedURL, ac); + String charset = HTTPURL.getCharacterEncoding(ac, importURL); if (importURL instanceof HttpURLConnection) { HttpURLConnection httpURL = (HttpURLConnection) importURL; @@ -470,13 +477,16 @@ throw new FileNotFoundException(importURL.getURL() + "No Media Type defined"); } else { if (mtype.toLowerCase().indexOf("text/html") != -1) { - throw new FileNotFoundException(importURL.getURL() + ": You can't import" + " an HTML document"); + throw new FileNotFoundException(importURL.getURL() + + ": You can't import" + + " an HTML document"); } } } Frame f = ac.getFrame(); try { - CssFouffa cssFouffa = new CssFouffa(ac, importURL.getInputStream(), importedURL, listeners, newVisited, + CssFouffa cssFouffa = new CssFouffa(ac, HTTPURL.getInputStream(ac, importURL), + importedURL, listeners, newVisited, properties, mode); cssFouffa.setOrigin(getOrigin()); if (!media.isEmpty()) {
Received on Friday, 13 February 2009 21:50:32 UTC