W3C home > Mailing lists > Public > www-validator-cvs@w3.org > September 2007

2002/css-validator/org/w3c/css/util Codecs.java,1.4,1.5

From: Julien Grand-Mourcel via cvs-syncmail <cvsmail@w3.org>
Date: Thu, 13 Sep 2007 10:17:42 +0000
To: www-validator-cvs@w3.org
Message-Id: <E1IVllW-0007MV-Uu@lionel-hutz.w3.org>

Update of /sources/public/2002/css-validator/org/w3c/css/util
In directory hutz:/tmp/cvs-serv28260/org/w3c/css/util

Modified Files:
	Codecs.java 
Log Message:
* Read the content type from uploaded file and add it to the new FakeFile parameter
* Factorise the printData method so there is less duplicate code here

Index: Codecs.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/util/Codecs.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- Codecs.java	14 Sep 2005 15:15:32 -0000	1.4
+++ Codecs.java	13 Sep 2007 10:17:40 -0000	1.5
@@ -198,7 +198,7 @@
 
 	    // parse header(s)
 
-	    String hdr, lchdr, name=null, filename=null, cont_disp = null;
+	    String hdr, lchdr, name=null, filename=null, cont_disp = null, mimeType=null;
 	    Object value;
 
 	    while (true) {
@@ -231,7 +231,9 @@
 
 		lchdr = hdr.toLowerCase();
 
-		if (!lchdr.startsWith("content-disposition")) continue;
+		if (lchdr.startsWith("content-type"))
+			mimeType = lchdr.substring("content-type: ".length());
+		else if (!lchdr.startsWith("content-disposition")) continue;
 
 		int off = lchdr.indexOf("form-data", 20);
 
@@ -305,6 +307,7 @@
 		FakeFile file = new FakeFile(filename);
 
 		file.write(data, start, end-start);
+		file.setContentType(mimeType);
 
 		value = file;
 	    } else {					// It's simple data
@@ -339,7 +342,6 @@
      * @return the value for this parameter, or null if not found.
      */
     public final static String getParameter(String param, String hdr) {
-	char ch;
 	int  pbeg,	// parameter name begin
 	    pend,	// parameter name end
 	    vbeg,	// parameter value begin
@@ -394,14 +396,7 @@
 
 
     private static void printData(byte[] data) {
-	for (int i = 0; i < data.length; i++) {
-	    if (data[i] == '\n' || data[i] == '\r') {
-		System.err.print( "&" + ((int) data[i]) );
-		System.err.println();
-	    } else {
-		System.err.print( (char) data[i] );
-	    }
-	}
+    	printData(data, 0);
     }
 
     private static void printData(byte[] data, int offset) {
Received on Thursday, 13 September 2007 10:17:52 GMT

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