| 500 | 
           aurelien | 
           1 | 
           package org.tela_botanica.del.client.utils;
  | 
        
        
           | 386 | 
           aurelien | 
           2 | 
              | 
        
        
            | 
            | 
           3 | 
           import com.google.gwt.http.client.Response;
  | 
        
        
            | 
            | 
           4 | 
           import com.google.gwt.json.client.JSONArray;
  | 
        
        
           | 938 | 
           gduche | 
           5 | 
           import com.google.gwt.json.client.JSONObject;
  | 
        
        
           | 386 | 
           aurelien | 
           6 | 
           import com.google.gwt.json.client.JSONParser;
  | 
        
        
            | 
            | 
           7 | 
           import com.google.gwt.json.client.JSONValue;
  | 
        
        
            | 
            | 
           8 | 
              | 
        
        
            | 
            | 
           9 | 
           public class UtilitairesAutoCompletionService {
  | 
        
        
            | 
            | 
           10 | 
              | 
        
        
            | 
            | 
           11 | 
           	public static String effectuerPreTraitementChaineRequeteGenreEspeceSlash(String requete) {
  | 
        
        
            | 
            | 
           12 | 
           		String chaineTraitee = requete;
  | 
        
        
            | 
            | 
           13 | 
           		String[] parties = requete.split(" ", 2);
  | 
        
        
            | 
            | 
           14 | 
              | 
        
        
            | 
            | 
           15 | 
           		if(parties.length == 2) {
  | 
        
        
            | 
            | 
           16 | 
           			if(parties[1].trim().isEmpty()) {
  | 
        
        
            | 
            | 
           17 | 
           				parties[1] = "*";
  | 
        
        
            | 
            | 
           18 | 
           			}
  | 
        
        
            | 
            | 
           19 | 
           			chaineTraitee = parties[0]+"/"+parties[1];
  | 
        
        
            | 
            | 
           20 | 
           		}
  | 
        
        
            | 
            | 
           21 | 
              | 
        
        
            | 
            | 
           22 | 
           		return chaineTraitee;
  | 
        
        
            | 
            | 
           23 | 
           	}
  | 
        
        
            | 
            | 
           24 | 
              | 
        
        
            | 
            | 
           25 | 
           	public static String effectuerPreTraitementChaineRequeteGenreEspeceEflore(String requete) {
  | 
        
        
            | 
            | 
           26 | 
              | 
        
        
            | 
            | 
           27 | 
           		String chaineTraitee = "?recherche=etendue&ns.structure=au&retour.format=oss&masque="+requete;
  | 
        
        
            | 
            | 
           28 | 
           		return chaineTraitee;
  | 
        
        
            | 
            | 
           29 | 
           	}
  | 
        
        
            | 
            | 
           30 | 
              | 
        
        
           | 938 | 
           gduche | 
           31 | 
           	public static String[] parserResultatRetourSimple(Response response) {
  | 
        
        
            | 
            | 
           32 | 
           		JSONObject responseValue = JSONParser.parseStrict(response.getText()).isObject();
  | 
        
        
            | 
            | 
           33 | 
           		JSONArray noms = responseValue.get("resultats").isArray();
  | 
        
        
            | 
            | 
           34 | 
              | 
        
        
            | 
            | 
           35 | 
           		String[] valeurs = new String[0];
  | 
        
        
            | 
            | 
           36 | 
           		final int taillemax = noms.size();
  | 
        
        
            | 
            | 
           37 | 
           		valeurs = new String[taillemax];
  | 
        
        
            | 
            | 
           38 | 
           		for (int i = 0; i < taillemax; i++) {
  | 
        
        
            | 
            | 
           39 | 
           			valeurs[i] = (noms.get(i).isArray().get(0).isString().stringValue());
  | 
        
        
            | 
            | 
           40 | 
           		}
  | 
        
        
            | 
            | 
           41 | 
           		return valeurs;
  | 
        
        
            | 
            | 
           42 | 
           	}
  | 
        
        
            | 
            | 
           43 | 
              | 
        
        
           | 386 | 
           aurelien | 
           44 | 
           	public static String[] parserRetourSimple(Response response) {
  | 
        
        
            | 
            | 
           45 | 
           		final JSONValue responseValue = JSONParser.parseStrict(response.getText());
  | 
        
        
            | 
            | 
           46 | 
           		JSONArray noms;
  | 
        
        
            | 
            | 
           47 | 
           		String[] valeurs = new String[0];
  | 
        
        
            | 
            | 
           48 | 
              | 
        
        
            | 
            | 
           49 | 
           		if ((noms=responseValue.isArray()) != null) {
  | 
        
        
            | 
            | 
           50 | 
              | 
        
        
            | 
            | 
           51 | 
           			final int taillemax = noms.size();
  | 
        
        
            | 
            | 
           52 | 
           			valeurs = new String[taillemax];
  | 
        
        
            | 
            | 
           53 | 
           			for (int i = 0; i < taillemax; i++) {
  | 
        
        
            | 
            | 
           54 | 
           				valeurs[i] = (noms.get(i).isArray().get(0).isString().stringValue());
  | 
        
        
            | 
            | 
           55 | 
           			}
  | 
        
        
            | 
            | 
           56 | 
           		}
  | 
        
        
            | 
            | 
           57 | 
           		return valeurs;
  | 
        
        
            | 
            | 
           58 | 
           	}
  | 
        
        
            | 
            | 
           59 | 
              | 
        
        
            | 
            | 
           60 | 
           	public static String[] parserRetourOss(Response response) {
  | 
        
        
            | 
            | 
           61 | 
           		JSONValue retourJson = JSONParser.parseStrict(response.getText());
  | 
        
        
            | 
            | 
           62 | 
           		JSONArray tableauResultat = retourJson.isArray().get(1).isArray();
  | 
        
        
            | 
            | 
           63 | 
              | 
        
        
            | 
            | 
           64 | 
           		String[] suggestions = new String[tableauResultat.size()];
  | 
        
        
            | 
            | 
           65 | 
           		for (int i = 0; i < tableauResultat.size(); i++) {
  | 
        
        
            | 
            | 
           66 | 
           			suggestions[i] = tableauResultat.get(i).isString().stringValue();
  | 
        
        
            | 
            | 
           67 | 
           		}
  | 
        
        
            | 
            | 
           68 | 
              | 
        
        
            | 
            | 
           69 | 
           		return suggestions;
  | 
        
        
            | 
            | 
           70 | 
           	}
  | 
        
        
            | 
            | 
           71 | 
           }
  |