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

2002/css-validator/org/w3c/css/servlet CssValidator.java,1.36,1.37

From: Julien Grand-Mourcel via cvs-syncmail <cvsmail@w3.org>
Date: Thu, 13 Sep 2007 10:15:35 +0000
To: www-validator-cvs@w3.org
Message-Id: <E1IVljT-0006z4-La@lionel-hutz.w3.org>

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

Modified Files:
	CssValidator.java 
Log Message:
This new version deals with content-type of uploaded files and with "none" profile

Index: CssValidator.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/servlet/CssValidator.java,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -d -r1.36 -r1.37
--- CssValidator.java	10 Aug 2007 15:17:31 -0000	1.36
+++ CssValidator.java	13 Sep 2007 10:15:33 -0000	1.37
@@ -33,6 +33,7 @@
 import org.w3c.css.error.ErrorReport;
 import org.w3c.css.error.ErrorReportFactory;
 import org.w3c.css.index.IndexGenerator;
+import org.w3c.css.properties.PropertiesLoader;
 import org.w3c.css.util.ApplContext;
 import org.w3c.css.util.Codecs;
 import org.w3c.css.util.FakeFile;
@@ -55,6 +56,8 @@
     final static String applxhtml   = "application/xhtml+xml";
     
     final static String textplain   = "text/plain";
+    
+    final static String textcss   = "text/css";
 
     final static String textunknwon = "text/unknown";
 
@@ -249,6 +252,9 @@
 	String error = req.getParameter("error");
 	String profile = req.getParameter("profile");
 	String usermedium = req.getParameter("usermedium");
+	String type = req.getParameter("type");
+	if (type == null)
+		type = "none";
 
 	String credential = req.getHeader("Authorization");
 	if ((credential != null) && (credential.length() > 1)) {
@@ -281,18 +287,19 @@
 	}
 
 	// CSS version
-	if (profile != null && !"none".equals(profile)) {
+	if (profile != null && (!"none".equals(profile) || "".equals(profile))) {
 	    if ("css1".equals(profile) || "css2".equals(profile)
 		|| "css21".equals(profile)
 		|| "css3".equals(profile) || "svg".equals(profile)
 		|| "svgbasic".equals(profile) || "svgtiny".equals(profile)) {
-		ac.setCssVersion(profile);
+	    	ac.setCssVersion(profile);
 	    } else {
-		ac.setProfile(profile);
-		ac.setCssVersion("css21");
+			ac.setProfile(profile);
+			ac.setCssVersion(PropertiesLoader.config.getProperty("defaultProfile"));
 	    }
 	} else {
-	    ac.setCssVersion("css21");
+		ac.setProfile("none");
+	    ac.setCssVersion(PropertiesLoader.config.getProperty("defaultProfile"));
 	}
 	if (Util.onDebug) {
 	    System.err.println("[DEBUG]  profile is : " + ac.getCssVersion()
@@ -370,7 +377,8 @@
 		
 		try {
 		
-			if (isCSS(text)) {
+			if ("css".equals(type) || ( "none".equals(type) && isCSS(text))) {
+				// if CSS:
 				parser = new StyleSheetParser();
 		  	    parser.parseStyleElement(ac, is, null, usermedium,
 		  			new URL(fileName), 0);
@@ -378,7 +386,7 @@
 		  	    handleRequest(ac, res, fileName, parser
 		  			  .getStyleSheet(), output, warningLevel, errorReport);
 			} else {
-				// try HTML
+				// else, trying HTML
 				TagSoupStyleSheetHandler handler = new TagSoupStyleSheetHandler(null, ac);
 				handler.parse(is, fileName);
 	
@@ -477,10 +485,11 @@
 	//boolean XMLinput = false;
 	String warning = null;
 	String error = null;
-	String profile = null;
+	String profile = "none";
 	String usermedium = "all";
 
 	ServletInputStream in = req.getInputStream();
+
 	byte[] buf = new byte[2048];
 	byte[] general = new byte[65536];
 	int count = 0;
@@ -604,18 +613,19 @@
 	}
 
 	// CSS version
-	if (profile != null && !"none".equals(profile)) {
+	if (profile != null && (!"none".equals(profile) || "".equals(profile))) {
 	    if ("css1".equals(profile) || "css2".equals(profile)
 		|| "css21".equals(profile)
 		|| "css3".equals(profile) || "svg".equals(profile)
 		|| "svgbasic".equals(profile) || "svgtiny".equals(profile)) {
-		ac.setCssVersion(profile);
+	    	ac.setCssVersion(profile);
 	    } else {
-		ac.setProfile(profile);
-		ac.setCssVersion("css21");
+			ac.setProfile(profile);
+			ac.setCssVersion(PropertiesLoader.config.getProperty("defaultProfile"));
 	    }
 	} else {
-	    ac.setCssVersion("css21");
+		ac.setProfile("none");
+	    ac.setCssVersion(PropertiesLoader.config.getProperty("defaultProfile"));
 	}
 	String fileName = "";
 	InputStream is = null;
@@ -625,8 +635,8 @@
 		fileName = file.getName();
 		Util.verbose("File : " + fileName);
 		is = file.getInputStream();
-		if (fileName.endsWith(".css"))
-			isCSS = true;
+		// another way to get file type...
+		isCSS = file.getContentType().equals(textcss);
 	} else if (text != null ) {
 		fileName = "TextArea";
 		Util.verbose("- " + fileName + " Data -");
@@ -637,12 +647,10 @@
 		isCSS = isCSS(text);
 	}
 	fileName = "file://localhost/" + fileName;
-	//TODO: define the content-type
   	try {
-		//if CSS:
 		
 		if (isCSS) {
-			System.err.println("css");
+			//if CSS:
 			parser = new StyleSheetParser();
 	  	    parser.parseStyleElement(ac, is, null, usermedium,
 	  			new URL(fileName), 0);
@@ -650,8 +658,7 @@
 	  	    handleRequest(ac, res, fileName, parser
 	  			  .getStyleSheet(), output, warningLevel, errorReport);
 		} else {
-			System.err.println("html");
-			// try HTML
+			// else, trying HTML
 			TagSoupStyleSheetHandler handler = new TagSoupStyleSheetHandler(null, ac);
 			handler.parse(is, fileName);
 
Received on Thursday, 13 September 2007 10:15:37 GMT

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