// TODO Auto-generated catch block
e2.printStackTrace();
}
//////////////////////////////////////////////////////////////////
Clan clan = null;
//int offset = 0 ;
int limit = 100;
// Verify that the input is valid.
if (!FieldVerifier.isValidName(input)) {
// If the input is not valid, throw an IllegalArgumentException back to
// the client.
log.info("arg not good : " + input);
throw new IllegalArgumentException("Name must be at least 1 characters long");
}
String serverInfo = getServletContext().getServerInfo();
String userAgent = getThreadLocalRequest().getHeader("User-Agent");
// Escape data from the client to avoid cross-site script vulnerabilities.
input = escapeHtml(input);
userAgent = escapeHtml(userAgent);
String resultAchievement = "";
try {
long maxAchievement = 0;
String maxAchievementuserName = "";
//recup id clan avec son son nom
/**
* {
"status": "ok",
"status_code": "NO_ERROR",
"data": {
"items": [
{
"abbreviation": "NVS",
"created_at": 1328978449.00,
"name": "NOVA SNAIL",
"member_count": 57,
"owner": "hentz44",
"motto": "Un escargot qui avale un obus a confiance en sa coquille.",
"clan_emblem_url": "http://cw.worldoftanks.eu/media/clans/emblems/clans_5/500006074/emblem_64x64.png",
"id": 500006074,
"clan_color": "#4a426c"
}
],
"offset": 0,
"filtered_count": 2
}
}
////////////////// NEW /////////////////////
* {
"status": "ok",
"count": 48,
"data": [
{
"members_count": 48,
"name": "\"�‘�µ�»�°Ñ� �³�²�°Ñ€�´�¸Ñ�\"",
"created_at": 1335298122,
"abbreviation": "WG1",
"clan_id": 24810,
"owner_id": 5095539
},
{
"members_count": 1,
"name": "Cheerful coffin",
"created_at": 1345383267,
"abbreviation": "WGWWR",
"clan_id": 35231,
"owner_id": 5266248
}
]
}
*
*/
URL urlClan = null ;
input = input.replace(" ", "%20");
if(lieu.equalsIgnoreCase("boulot")){ //on passe par 1 proxy
urlClan = new URL("https://pedro-proxy.appspot.com/api.worldoftanks.eu/2.0/clan/list/?application_id=d0a293dc77667c9328783d489c8cef73&search=" + input + "&offset="+ offset+ "&limit=" + limit);
}
else {
//NVS : 500006074
//urlClan = new URL("http://api.worldoftanks.eu/community/clans/500006074/api/1.0/?source_token=WG-WoT_Assistant-1.3.2");
//http://api.worldoftanks.eu/2.0/clan/list/?application_id=d0a293dc77667c9328783d489c8cef73&search=
urlClan = new URL("http://api.worldoftanks.eu/2.0/clan/list/?application_id=d0a293dc77667c9328783d489c8cef73&search=" + input );
}
//lecture de la réponse recherche du clan
HttpURLConnection conn = (HttpURLConnection)urlClan.openConnection();
conn.setReadTimeout(60000);
conn.setConnectTimeout(60000);
//conn.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
//BufferedReader reader = new BufferedReader(new InputStreamReader(urlClan.openStream(), "UTF-8"));
String line = "";
String AllLines = "";
while ((line = reader.readLine()) != null) {
AllLines = AllLines + line;
}
log.info(AllLines);
reader.close();
Gson gson = new Gson();
//System.out.println("before " + AllLines);
//parsing gson
clan = gson.fromJson(AllLines, Clan.class );
//ItemsDataClan myItemsDataClan = null ;
//translate the motto
//https://www.googleapis.com/language/translate/v2/detect?{parameters}
URL urlTranslate = null ;
String key = "AIzaSyBVwNDYZ1d3ERToxoZSFhW7jQrOeEvJVMM";
// Set your Windows Azure Marketplace client info - See http://msdn.microsoft.com/en-us/library/hh454950.aspx
String translatedText = "";
//String idClient = "a41ecfea-8da4-41a9-8f66-be116476de4b";
//String secretClient = "LgIs7oBcmBUSZ0964xZxdqkZDMWSSSzvGHUZf1sUEMs";
String idClient = "wotachievement";
String secretClient = "/upbsAfsZzh82dNC1ehpW8u8CVNR9afujtIko9ZW22E=";
//Translate.setClientId(idClient/* Enter your Windows Azure Client Id here */);
//Translate.setClientSecret(secretClient/* Enter your Windows Azure Client Secret here */);
//Detect.setClientId(idClient);
//Detect.setClientSecret(secretClient);
int nbTrad = 0;
// for (ItemsDataClan myItemsDataClan : clan.getItems()) {
// translatedText = "Pas de traduction, Seules les 5 premieres lignes sont traduites";
// String motto = myItemsDataClan.getMotto();
// //detect lang motto
// try {
// Language detectedLanguage = null;
//
// detectedLanguage = Detect.execute(motto);
//
// if (detectedLanguage != null && !detectedLanguage.getName(Language.FRENCH).equalsIgnoreCase("Français") && nbTrad < 6 ) {
// translatedText = Translate.execute(motto, detectedLanguage, Language.FRENCH);
// myItemsDataClan.setMotto(motto + " (" + detectedLanguage.name() +") " + "--> traduction : " + translatedText);
// nbTrad++;
// }
//
// } catch (Exception e) {
// // TODO Auto-generated catch block
// System.out.println(e.getMessage());
// }
// }
} catch (MalformedURLException e) {
// ...
e.printStackTrace();
} catch (IOException e) {
// ...
e.printStackTrace();
}
//return resultAchievement;
clan.setWiki(wiki);
return clan;
}