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;
|
|
|
5 |
import com.google.gwt.json.client.JSONParser;
|
|
|
6 |
import com.google.gwt.json.client.JSONValue;
|
|
|
7 |
|
|
|
8 |
public class UtilitairesAutoCompletionService {
|
|
|
9 |
|
|
|
10 |
public static String effectuerPreTraitementChaineRequeteGenreEspeceSlash(String requete) {
|
|
|
11 |
String chaineTraitee = requete;
|
|
|
12 |
String[] parties = requete.split(" ", 2);
|
|
|
13 |
|
|
|
14 |
if(parties.length == 2) {
|
|
|
15 |
if(parties[1].trim().isEmpty()) {
|
|
|
16 |
parties[1] = "*";
|
|
|
17 |
}
|
|
|
18 |
chaineTraitee = parties[0]+"/"+parties[1];
|
|
|
19 |
}
|
|
|
20 |
|
|
|
21 |
return chaineTraitee;
|
|
|
22 |
}
|
|
|
23 |
|
|
|
24 |
public static String effectuerPreTraitementChaineRequeteGenreEspeceEflore(String requete) {
|
|
|
25 |
|
|
|
26 |
String chaineTraitee = "?recherche=etendue&ns.structure=au&retour.format=oss&masque="+requete;
|
|
|
27 |
return chaineTraitee;
|
|
|
28 |
}
|
|
|
29 |
|
|
|
30 |
public static String[] parserRetourSimple(Response response) {
|
|
|
31 |
final JSONValue responseValue = JSONParser.parseStrict(response.getText());
|
|
|
32 |
JSONArray noms;
|
|
|
33 |
String[] valeurs = new String[0];
|
|
|
34 |
|
|
|
35 |
if ((noms=responseValue.isArray()) != null) {
|
|
|
36 |
|
|
|
37 |
final int taillemax = noms.size();
|
|
|
38 |
valeurs = new String[taillemax];
|
|
|
39 |
for (int i = 0; i < taillemax; i++) {
|
|
|
40 |
valeurs[i] = (noms.get(i).isArray().get(0).isString().stringValue());
|
|
|
41 |
}
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
return valeurs;
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
public static String[] parserRetourOss(Response response) {
|
|
|
48 |
JSONValue retourJson = JSONParser.parseStrict(response.getText());
|
|
|
49 |
JSONArray tableauResultat = retourJson.isArray().get(1).isArray();
|
|
|
50 |
|
|
|
51 |
String[] suggestions = new String[tableauResultat.size()];
|
|
|
52 |
for (int i = 0; i < tableauResultat.size(); i++) {
|
|
|
53 |
suggestions[i] = tableauResultat.get(i).isString().stringValue();
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
return suggestions;
|
|
|
57 |
}
|
|
|
58 |
}
|