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

2002/css-validator/org/w3c/css/util Messages.java,1.26,1.27

From: Yves Lafon via cvs-syncmail <cvsmail@w3.org>
Date: Tue, 24 Feb 2009 21:53:07 +0000
To: www-validator-cvs@w3.org
Message-Id: <E1Lc5D9-0007aV-Hw@lionel-hutz.w3.org>
Update of /sources/public/2002/css-validator/org/w3c/css/util
In directory hutz:/tmp/cvs-serv29153

Modified Files:
	Messages.java 
Log Message:
added a function to replace %s in localized strings


Index: Messages.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/util/Messages.java,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- Messages.java	22 Feb 2009 15:16:18 -0000	1.26
+++ Messages.java	24 Feb 2009 21:53:05 -0000	1.27
@@ -10,8 +10,10 @@
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.Hashtable;
 import java.util.StringTokenizer;
+import java.util.Vector;
 
 /**
  * @version $Revision$
@@ -160,6 +162,22 @@
 	return getString("servlet."+message);
     }
 
+    public String getString(String message, Vector<String> params) {
+	if ((params == null) || params.size() == 0) {
+	    return getString(message);
+	}
+	String[] msg_parts = getString(message).split("%s");
+	Iterator<String> param_it = params.iterator();
+	StringBuilder sb = new StringBuilder(message.length());
+	for (int i=0; i<msg_parts.length; i++) {
+	    sb.append(msg_parts[i]);
+	    if (param_it.hasNext()) {
+		sb.append(param_it.next());
+	    }
+	}
+	return sb.toString();
+    }
+
     static {
 	Utf8Properties tmp;
 	try {
Received on Tuesday, 24 February 2009 21:53:17 GMT

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