Hi Jitesh, Have you looked at the Google Language API for GWT? It wraps up the Google JavaScript translation and transliteration APIs and makes it eaiser to use with GWT. See:
http://code.google.com/p/gwt-google-apis Thereis be sample code and documentation you can take a look at. If you need help with using that API, please post to the GWT-Google-Apis google group. Regards, -Eric. On Tue, Sep 1, 2009 at 3:29 AM, jitesh dundas<[email protected]> wrote: > > Hi Friends, > > > I need your help. > > I have written this code to get the transliteration in Java. BUt it > gives me incorrect output for > 4 words... > > > <%@ page language = "java" %> > <%@ page import = "java.sql.*" %> > <%@ page import = "java.util.*" %> > <%@ page import = "java.io.*" %> > <%@ page import="java.lang.*" %> > <%@ page import="java.net.*" %> > <%@ page import="java.nio.*" %> > > <%@ page contentType="text/html; charset=utf-8" pageEncoding="UTF-8" > %> > > <% > > try > { > out.println("Hello"); > > Properties systemSettings = System.getProperties(); > systemSettings.put("*********", "****************"); > systemSettings.put("http.proxyPort", "****"); > systemSettings.put("sun.net.client.defaultConnectTimeout", "10000"); > systemSettings.put("sun.net.client.defaultReadTimeout", > "10000"); > out.println("Properties Set"); > Authenticator.setDefault(new Authenticator() > { > protected PasswordAuthentication > getPasswordAuthentication() > { > return new PasswordAuthentication > ("*", "****".toCharArray()); // specify ur user name password of iitb > login > } > }); > System.setProperties(systemSettings); > out.println("After Authentication & Properties Settings"); > > //the input to google api > //String str = "tlqt=1&langpair=en|hi&text=sdffdgdf sdfsd qwewq > adfasw qeqewq asdfqw3eeeeww adas adasdasd adasds &&tl_app=1"; > //http://www.google.com/transliterate/indic?tlqt=1&langpair=en| > hi&text=sdfsd%20qwewq%20adfasw%20qeqewq%20asdfqw3eeeeww%20adas > %20adasdasd&&tl_app=1 > String str = "tlqt=1&langpair=en|hi&text=sdfsd%20qwewq%20adfasw > %20qeqewq%20asdfqw3eeeeww%20adas%20adasdasd&&tl_app=1"; > > String stringToReverse = ""; > try > { > stringToReverse = "http://www.google.com/transliterate/indic?" > + > URLEncoder.encode(str, "UTF-8"); > } > catch(Exception ex) > {} > > out.println(stringToReverse); > > URL url = new URL(stringToReverse); > URLConnection connection = url.openConnection(); > //connection.setDoOutput(false); > > BufferedReader in = new BufferedReader( new InputStreamReader > ( connection.getInputStream())); > > String decodedString; > String tempstr = ""; > out.println("Decoded String Like->"+ URLDecoder.decode("\u0905\u092E > \u093F\u0924\u093E\u092C\u091A\u0928","UTF-8") + "<br>") ; > > while ((decodedString = in.readLine()) != null) > { > tempstr = tempstr + decodedString; > } > out.println(tempstr); > > > //code ends. > String[] strval = tempstr.split("ew"); > out.println("Length="+strval.length + "<br>"); > > //loop through all the values of the string array. > for ( int j=0; j < strval.length; j++ ) > { > String val = strval[j]; > > out.println("<br>j=" + j + " & Array Val="+val+ "<br>"); > > //next check for ":" sign. > if ( val.contains(":") ) > { > out.println(" It has colon"); > //check for first comma in this string. > /*int commapos = val.indexOf(","); > out.println(" Pos of comma is "+ commapos + "<br>"); > */ > String[] strval2 = val.split(","); > String strval3 = ""; > > for (int k=0; k < strval2.length; k++ ) > { > out.println("<br>k=" + k + " & Comma Array > Val="+ strval2[k] + > "<br>"); > //now replace all " and ":" characters. > > strval3 = strval2[k]; > strval3 = strval3.replaceAll("\"",""); > strval3 = strval3.replaceAll(":",""); > > out.println("<br>k=" + k + " & New Comma Array > Val="+ strval3 + > "<br>"); > > out.println("Final value of > ew="+strval3);//value of ew > obtained. > } > //code to get values of > > > //next get the substring till first "," > } > } > > > > in.close(); > } > catch(Exception ex) > { > out.println("Exception->"+ex); > PrintWriter pw = response.getWriter(); > ex.printStackTrace(pw); > } > > > %> > ---------------------------------------------------------------------------------------- > > This code just stores value in string variable which I can parse for > my output.. > > IS there anything that I have missed or is incorrect. > > Please help... > > I am not using Eclipse..Can I use GWT toolkit to get this done > correctly. > > Regards, > Jitesh Dundas > > > > > -- Google Code Jam 2009 http://code.google.com/codejam --~--~---------~--~----~------------~-------~--~----~ http://groups.google.com/group/Google-Web-Toolkit-Contributors -~----------~----~----~----~------~----~------~--~---
