import java.net.*; import java.io.*; import java.util.regex.*; //adapted from Sun's KnockKnockProtocol example from the Java Tutorial public class TransProtocol { public String processInput(String theInput) { if (theInput==null || theInput.length()==0) { return ""; } String encoding = "en|fr"; String url="http://translate.google.com/translate_t?langpair="+URLEncoder.encode(encoding) + "&text=" + URLEncoder.encode(theInput); try { URL server = new URL(url); URLConnection connection = (HttpURLConnection)server.openConnection(); connection.setRequestProperty("User-Agent","Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8.0.8) Gecko/20061025 Firefox/1.5.0.8"); connection.connect(); InputStream sin = connection.getInputStream(); BufferedReader in = new BufferedReader(new InputStreamReader(sin)); StringBuffer s = new StringBuffer(); String line; while ((line = in.readLine()) != null) { s.append(line + " "); } Pattern p = Pattern.compile("