W3C home > Mailing lists > Public > www-validator-cvs@w3.org > February 2009

2002/css-validator/org/w3c/css/util ApplContext.java,1.16,1.17

From: Yves Lafon via cvs-syncmail <cvsmail@w3.org>
Date: Mon, 16 Feb 2009 16:42:16 +0000
To: www-validator-cvs@w3.org
Message-Id: <E1LZ6Xw-0005w1-6B@lionel-hutz.w3.org>
Update of /sources/public/2002/css-validator/org/w3c/css/util
In directory hutz:/tmp/cvs-serv22742/org/w3c/css/util

Modified Files:
	ApplContext.java 
Log Message:
last round for uploaded files with BOM

Index: ApplContext.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/util/ApplContext.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- ApplContext.java	16 Feb 2009 12:16:34 -0000	1.16
+++ ApplContext.java	16 Feb 2009 16:42:14 -0000	1.17
@@ -24,6 +24,8 @@
 import org.w3c.www.http.HttpAcceptCharsetList;
 import org.w3c.www.http.HttpFactory;
 
+import org.apache.velocity.io.UnicodeInputStream;
+
 /**
  * @version $Revision$
  * @author Philippe Le Hegaret
@@ -32,13 +34,16 @@
 
     // the charset of the first source (url/uploaded/text)
     public static Charset defaultCharset;  
+    public static Charset utf8Charset;
 
     static {
 	try {
 	    defaultCharset = Charset.forName("iso-8859-1");
+	    utf8Charset = Charset.forName("utf-8");
 	} catch (Exception ex) {
 	    // we are in deep trouble here
 	    defaultCharset = null;
+	    utf8Charset    = null;
 	}
     }
 
@@ -353,14 +358,33 @@
 	this.faketext = faketext;
     }
 
-    public InputStream getFakeInputStream() throws IOException {
+    public InputStream getFakeInputStream(URL source) 
+	throws IOException 
+    {
+	InputStream is = null;
 	if (fakefile != null) {
-	    return fakefile.getInputStream();
+	    is = fakefile.getInputStream();
 	}
 	if (faketext != null) {
-	    return new ByteArrayInputStream(faketext.getBytes());
+	    is = new ByteArrayInputStream(faketext.getBytes());
 	}
-	return null;
+	if (is == null) {
+	    return null;
+	}
+	Charset c = getCharsetObjForURL(source);
+	if (c == null) {
+	    UnicodeInputStream uis = new UnicodeInputStream(is);
+	    String guessedCharset = uis.getEncodingFromStream();
+	    if (guessedCharset != null) {
+		setCharsetForURL(source, guessedCharset);
+	    }
+	    return uis;
+	} else {
+	    if (utf8Charset.compareTo(c) == 0) {
+		return new UnicodeInputStream(is);
+	    }
+	}
+	return is;
     }
     
     public boolean isInputFake() {
Received on Monday, 16 February 2009 16:42:26 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Thursday, 26 April 2012 12:55:08 GMT