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

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 UTC