2002/css-validator/org/w3c/css/util ApplContext.java,1.5,1.6 Messages.java,1.5,1.6

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

Modified Files:
	ApplContext.java Messages.java 
Log Message:
accept-language is now done the right way, with quality value checks
also a new parameter, lang, is used (prepended).
Also the output encoding is biased with the one present in the
property file of the relevant language.



Index: ApplContext.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/util/ApplContext.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- ApplContext.java	8 Aug 2005 13:19:46 -0000	1.5
+++ ApplContext.java	8 Sep 2005 14:24:29 -0000	1.6
@@ -178,6 +178,8 @@
 	    String encoding = null;
 	    double quality = 0.0;
 	    
+	    String biasedcharset = getMsg().getString("output-encoding-name");
+	    
 	    for(int i = 0; i < charsets.length && quality < 1.0 ; i++) {
 		HttpAcceptCharset charset = charsets[i];
 		
@@ -189,6 +191,12 @@
 		if(isCharsetSupported(currentCharset)) {
 		    double currentQuality = charset.getQuality();
 		    
+		    // we prefer utf-8 
+		    // FIXME (the bias value and the biased charset
+		    //        should be dependant on the language)
+		    if ((biasedcharset != null) && !biasedcharset.equalsIgnoreCase(currentCharset)) {
+			currentQuality = currentQuality * 0.5;
+		    }
 		    if(currentQuality > quality) {
 			quality = currentQuality;
 			encoding = charset.getCharset();

Index: Messages.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/util/Messages.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- Messages.java	8 Sep 2005 12:24:10 -0000	1.5
+++ Messages.java	8 Sep 2005 14:24:29 -0000	1.6
@@ -19,7 +19,7 @@
     /**
      * Message properties
      */  
-	public Utf8Properties properties;
+    public Utf8Properties properties;
 
     private static Hashtable languages = new Hashtable();
     
@@ -29,10 +29,41 @@
     public Messages(String lang) {
 	if (lang != null) {
 	    StringTokenizer lanTok = new StringTokenizer(lang, ",");
-	    
+	    int maxTok = lanTok.countTokens();
+   
+	    String slang[] = new String[maxTok];
+	    float  qlang[] = new float[maxTok];
+
+	    // quick and dirty, it would be better to use Jigsaw's classes
 	    while (lanTok.hasMoreTokens()) {
 		String l = lanTok.nextToken().trim().toLowerCase();
-				properties = (Utf8Properties) languages.get(l);
+		int qualsep = l.indexOf(';');
+		float qval = 1;
+		if (qualsep != -1) {
+		    String p = l.substring(qualsep+1);
+		    l = l.substring(0, qualsep);
+		    if (p.startsWith("q=")) {
+			qval = Float.parseFloat(p.substring(2));
+		    }
+		}
+		for (int i=0 ; i<maxTok; i++) {
+		    if (slang[i] == null) {
+			slang[i] = l;
+			qlang[i] = qval;
+			break;
+		    } else if (qval > qlang[i]) {
+			System.arraycopy(slang, i, slang, i+1, (maxTok-i-1));
+			System.arraycopy(qlang, i, qlang, i+1, (maxTok-i-1));
+			slang[i] = l;
+			qlang[i] = qval;
+			break;
+		    }
+		    
+		}
+	    }
+	    for (int i=0 ; i< maxTok; i++) {
+		String l = slang[i];
+		properties = (Utf8Properties) languages.get(l);
 		if (properties != null) {
 		    break;
 		}
@@ -40,7 +71,7 @@
 		if (minusIndex != -1) {
 		    // suppressed -cn in zh-cn (example)
 		    l = l.substring(0, minusIndex);
-					properties = (Utf8Properties) languages.get(l);
+		    properties = (Utf8Properties) languages.get(l);
 		}
 		if (properties != null) {
 		    break;
@@ -48,7 +79,7 @@
 	    }
 	}
 	if (properties == null) {
-			properties = (Utf8Properties) languages.get("en");
+	    properties = (Utf8Properties) languages.get("en");
 	}
     }
     
@@ -62,60 +93,61 @@
     /**
      * Get a warning property.
      * 
-	 * @param message
-	 *            the warning property.
+     * @param message
+     *            the warning property.
      */  
     public String getWarningString(String message) {
-		return getString(new StringBuffer("warning.").append(message)
-				.toString());
+	return getString(new StringBuffer("warning.").append(message)
+			                                          .toString());
     }
     
     /**
      * Get a warning level property.
      * 
-	 * @param message
-	 *            the warning property.
+     * @param message
+     *            the warning property.
      */  
     public String getWarningLevelString(String message) {
-		return getString(new StringBuffer("warning.").append(message).append(
-				".level").toString());
+	return getString(new StringBuffer("warning.").append(message).append(
+	                                                 ".level").toString());
     }
     
     /**
      * Get an error property.
      *
-	 * @param message
-	 *            the error property.
+     * @param message
+     *            the error property.
      */  
     public String getErrorString(String message) {
-	return getString(new StringBuffer("error.").append(message).toString());
+	return getString(new StringBuffer("error.").
+			                           append(message).toString());
     }
     
     /**
      * Get an generator property.
      *
-	 * @param message
-	 *            the generator property.
+     * @param message
+     *            the generator property.
      */  
     public String getGeneratorString(String message) {
-		return getString(new StringBuffer("generator.").append(message)
-				.toString());
+	return getString(new StringBuffer("generator.").append(message)
+			 .toString());
     }
     
     /**
      * Get an generator property.
      *
-	 * @param message
-	 *            the generator property.
+     * @param message
+     *            the generator property.
      */  
     public String getGeneratorString(String message, String param) {
-		String str = getString(new StringBuffer("generator.").append(message)
-				.toString());
+	String str = getString(new StringBuffer("generator.").append(message)
+			       .toString());
 	
 	// replace all parameters
 	int i = str.indexOf("%s");
 	if (i >= 0) {
-			str = str.substring(0, i) + param + str.substring(i + 2);
+	    str = str.substring(0, i) + param + str.substring(i + 2);
 	}
 	return str;
     }
@@ -123,69 +155,69 @@
     /**
      * Get an generator property.
      *
-	 * @param message
-	 *            the generator property.
+     * @param message
+     *            the generator property.
      */  
     public String getServletString(String message) {
-		return getString(new StringBuffer("servlet.").append(message)
-				.toString());
+	return getString(new StringBuffer("servlet.").append(message)
+			 .toString());
     }
     
     static {
-		Utf8Properties tmp;
+	Utf8Properties tmp;
 	try {
 	    URL url = Messages.class.getResource("Messages.properties.en");
 	    java.io.InputStream f = url.openStream();
 	    try {
-				tmp = new Utf8Properties();
+		tmp = new Utf8Properties();
 		tmp.load(f);
 		languages.put("en", tmp);
 	    } finally {
 		f.close();
 	    }
 	} catch (Exception e) {
-			System.err
-					.println("org.w3c.css.util.Messages: couldn't load properties en");
-			System.err.println("  " + e.toString());
+	    System.err.println("org.w3c.css.util.Messages: "+
+			       "couldn't load properties en");
+	    System.err.println("  " + e.toString());
 	}
 
 	try {
 	    URL url = Messages.class.getResource("Messages.properties.zh-cn");
 	    java.io.InputStream f = url.openStream();
 	    try {
-				tmp = new Utf8Properties();
+		tmp = new Utf8Properties();
 		tmp.load(f);
 		languages.put("zh-cn", tmp);
 	    } finally {
 		f.close();
 	    }
 	} catch (Exception e) {
-			System.err
-					.println("org.w3c.css.util.Messages: couldn't load properties cn");
-			System.err.println("  " + e.toString());
+	    System.err.println("org.w3c.css.util.Messages: "+
+			       "couldn't load properties cn");
+	    System.err.println("  " + e.toString());
 	}
 
 	try {
 	    URL url = Messages.class.getResource("Messages.properties.ja");
 	    java.io.InputStream f = url.openStream();
 	    try {
-				tmp = new Utf8Properties();
+		tmp = new Utf8Properties();
 		tmp.load(f);
 		languages.put("ja", tmp);
 	    } finally {
 		f.close();
 	    }
 	} catch (Exception e) {
-			System.err
-					.println("org.w3c.css.util.Messages: couldn't load properties ja");
-			System.err.println("  " + e.toString());
+	    System.err.println("org.w3c.css.util.Messages:"+
+			       " couldn't load properties ja");
+	    System.err.println("  " + e.toString());
 	}
 
         try {
             URL url = Messages.class.getResource("Messages.properties.fr");
             java.io.InputStream f = url.openStream();
             try {
-				tmp = new Utf8Properties();
+		tmp = new Utf8Properties();
                 tmp.load(f);
                 languages.put("fr", tmp);
 		languages.put("fr_FR", tmp);
@@ -193,18 +225,18 @@
                 f.close();
             }
         } catch (Exception e) {
-			System.err
-					.println("org.w3c.css.util.Messages: couldn't load properties fr");
-			System.err.println("  " + e.toString());
+	    System.err.println("org.w3c.css.util.Messages: "+
+			       "couldn't load properties fr");
+	    System.err.println("  " + e.toString());
         }
 
-		// -----------------------
+	// -----------------------
 
         try {
             URL url = Messages.class.getResource("Messages.properties.de");
             java.io.InputStream f = url.openStream();
             try {
-				tmp = new Utf8Properties();
+		tmp = new Utf8Properties();
                 tmp.load(f);
                 languages.put("de", tmp);
                 languages.put("de_DE", tmp);
@@ -214,9 +246,9 @@
                 f.close();
             }
 	} catch (Exception e) {
-			System.err
-					.println("org.w3c.css.util.Messages: couldn't load properties de");
-			System.err.println("  " + e.toString());
+	    System.err.println("org.w3c.css.util.Messages: "+
+			       "couldn't load properties de");
+	    System.err.println("  " + e.toString());
         }
 
 	// ------------------------------------------------
@@ -225,16 +257,16 @@
 	    URL url = Messages.class.getResource("Messages.properties.nl");
 	    java.io.InputStream f = url.openStream();
 	    try {
-				tmp = new Utf8Properties();
+		tmp = new Utf8Properties();
 		tmp.load(f);
 		languages.put("nl", tmp);
 	    } finally {
 		f.close();
 	    }
 	} catch (Exception e) {
-			System.err
-					.println("org.w3c.css.util.Messages: couldn't load properties nl");
-			System.err.println("  " + e.toString());
+	    System.err.println("org.w3c.css.util.Messages: "+
+			       "couldn't load properties nl");
+	    System.err.println("  " + e.toString());
 	}
 
 	// ------------------------------------------------
@@ -243,7 +275,7 @@
 	    URL url = Messages.class.getResource("Messages.properties.es");
 	    java.io.InputStream f = url.openStream();
 	    try {
-				tmp = new Utf8Properties();
+		tmp = new Utf8Properties();
 		tmp.load(f);
 		languages.put("es", tmp);
 		languages.put("es_ES", tmp);
@@ -251,10 +283,9 @@
 		f.close();
 	    }
 	} catch (Exception e) {
-			System.err
-					.println("org.w3c.css.util.Messages: couldn't load properties es");
-			System.err.println("  " + e.toString());
+	    System.err.println("org.w3c.css.util.Messages: "+
+			       "couldn't load properties es");
+	    System.err.println("  " + e.toString());
 	}
-
     }
 }

Received on Thursday, 8 September 2005 14:24:52 UTC