- From: Yves Lafon via cvs-syncmail <cvsmail@w3.org>
- Date: Sun, 15 Feb 2009 18:23:50 +0000
- To: www-validator-cvs@w3.org
Update of /sources/public/2002/css-validator/org/w3c/css/util In directory hutz:/tmp/cvs-serv17481/org/w3c/css/util Modified Files: ApplContext.java FakeFile.java HTTPURL.java Log Message: fix for charset support of fake URIs (upload and text input) Index: ApplContext.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/util/ApplContext.java,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- ApplContext.java 13 Feb 2009 21:50:16 -0000 1.14 +++ ApplContext.java 15 Feb 2009 18:23:48 -0000 1.15 @@ -8,9 +8,16 @@ */ package org.w3c.css.util; -import java.nio.charset.Charset; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.io.IOException; + import java.util.HashMap; import java.net.URL; +import java.nio.charset.Charset; +import java.nio.charset.IllegalCharsetNameException; +import java.nio.charset.UnsupportedCharsetException; import org.w3c.css.parser.Frame; import org.w3c.www.http.HttpAcceptCharset; @@ -23,6 +30,8 @@ */ public class ApplContext { + public static Charset defaultCharset; + String credential = null; String lang; Messages msgs; @@ -36,7 +45,20 @@ private String link; int warningLevel = 0; - private HashMap<URL,String> uricharsets = null; + FakeFile fakefile = null; + String faketext = null; + URL fakeurl = null; + + private HashMap<URL,Charset> uricharsets = null; + + static { + try { + defaultCharset = Charset.forName("iso-8859-1"); + } catch (Exception ex) { + // we are in deep trouble here + defaultCharset = null; + } + } /** * Creates a new ApplContext @@ -211,7 +233,8 @@ // we prefer utf-8 // FIXME (the bias value and the biased charset // should be dependant on the language) - if ((biasedcharset != null) && !biasedcharset.equalsIgnoreCase(currentCharset)) { + if ((biasedcharset != null) && + !biasedcharset.equalsIgnoreCase(currentCharset)) { currentQuality = currentQuality * 0.5; } if (currentQuality > quality) { @@ -243,18 +266,107 @@ } } + /** + * used for storing the charset of the document in use + * and its update by a @charset statement, or through + * automatic discovery + */ public void setCharsetForURL(URL url, String charset) { if (uricharsets == null) { - uricharsets = new HashMap<URL,String>(); + uricharsets = new HashMap<URL,Charset>(); + } + Charset c = null; + try { + c = Charset.forName(charset); + } catch (IllegalCharsetNameException icex) { + // FIXME add a warning in the CSS + } catch (UnsupportedCharsetException ucex) { + // FIXME inform about lack of support + } + if (c != null) { + uricharsets.put(url, c); + } + } + + /** + * used for storing the charset of the document in use + * and its update by a @charset statement, or through + * automatic discovery + */ + public void setCharsetForURL(URL url, Charset charset) { + if (uricharsets == null) { + uricharsets = new HashMap<URL,Charset>(); } uricharsets.put(url, charset); } - + + /** + * used for storing the charset of the document in use + * and its update by a @charset statement, or through + * automatic discovery + */ public String getCharsetForURL(URL url) { + Charset c; + if (uricharsets == null) { + return null; + } + c = uricharsets.get(url); + if (c != null) { + return c.toString(); + } + return null; + } + + /** + * used for storing the charset of the document in use + * and its update by a @charset statement, or through + * automatic discovery + */ + public Charset getCharsetObjForURL(URL url) { + Charset c; if (uricharsets == null) { return null; } return uricharsets.get(url); } + + /** + * store content of uploaded file + */ + public void setFakeFile(FakeFile fakefile) { + this.fakefile = fakefile; + } + + /** + * store content of entered text + */ + public void setFakeText(String faketext) { + this.faketext = faketext; + } + + public InputStream getFakeInputStream() throws IOException { + if (fakefile != null) { + return fakefile.getInputStream(); + } + if (faketext != null) { + return new ByteArrayInputStream(faketext.getBytes()); + } + return null; + } + public boolean isInputFake() { + return ((faketext != null) || (fakefile != null)); + } + + public void setFakeURL(String fakeurl) { + try { + this.fakeurl = new URL(fakeurl); + } catch (Exception ex) { + } + } + + public URL getFakeURL() { + return fakeurl; + } + } Index: HTTPURL.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/util/HTTPURL.java,v retrieving revision 1.21 retrieving revision 1.22 diff -u -d -r1.21 -r1.22 --- HTTPURL.java 13 Feb 2009 21:50:16 -0000 1.21 +++ HTTPURL.java 15 Feb 2009 18:23:48 -0000 1.22 @@ -298,7 +298,9 @@ return orig_stream; } - public static String getCharacterEncoding(ApplContext ac, URLConnection uco) { + public static String getCharacterEncoding(ApplContext ac, + URLConnection uco) + { String charset = ac.getCharsetForURL(uco.getURL()); if (charset != null) { return charset; Index: FakeFile.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/util/FakeFile.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- FakeFile.java 13 Sep 2007 10:18:49 -0000 1.6 +++ FakeFile.java 15 Feb 2009 18:23:48 -0000 1.7 @@ -121,12 +121,12 @@ count += len; } - public void setContentType(String mimeType) { - contentType = mimeType; - } - - public String getContentType() { - return contentType; - } + public void setContentType(String mimeType) { + contentType = mimeType; + } + + public String getContentType() { + return contentType; + } }
Received on Sunday, 15 February 2009 18:23:59 UTC