Subversion Repositories eFlore/Applications.del

Rev

Rev 491 | Rev 553 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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
	// Attention à n'utiliser que si eflore est installé
11
	public static String urlServiceCompletionNomEflore = "http://localhost/service:eflore:0.1/bdtfx/noms";
500 aurelien 12
	public static String urlServiceCompletionNomLocale = "/del/jrest/NomsTaxons/";
386 aurelien 13
 
500 aurelien 14
	public static String urlServiceCompletionCommunes = "/del/jrest/Communes/";
465 aurelien 15
 
386 aurelien 16
	public static String effectuerPreTraitementChaineRequeteGenreEspeceSlash(String requete) {
17
		String chaineTraitee = requete;
18
		String[] parties = requete.split(" ", 2);
19
 
20
		if(parties.length == 2) {
21
			if(parties[1].trim().isEmpty()) {
22
				parties[1] = "*";
23
			}
24
			chaineTraitee = parties[0]+"/"+parties[1];
25
		}
26
 
27
		return chaineTraitee;
28
	}
29
 
30
	public static String effectuerPreTraitementChaineRequeteGenreEspeceEflore(String requete) {
31
 
32
		String chaineTraitee = "?recherche=etendue&ns.structure=au&retour.format=oss&masque="+requete;
33
		return chaineTraitee;
34
	}
35
 
36
	public static String[] parserRetourSimple(Response response) {
37
		final JSONValue responseValue = JSONParser.parseStrict(response.getText());
38
		JSONArray noms;
39
		String[] valeurs = new String[0];
40
 
41
		if ((noms=responseValue.isArray()) != null) {
42
 
43
			final int taillemax = noms.size();
44
			valeurs = new String[taillemax];
45
			for (int i = 0; i < taillemax; i++) {
46
				valeurs[i] = (noms.get(i).isArray().get(0).isString().stringValue());
47
			}
48
		}
49
 
50
		return valeurs;
51
	}
52
 
53
	public static String[] parserRetourOss(Response response) {
54
		JSONValue retourJson = JSONParser.parseStrict(response.getText());
55
		JSONArray tableauResultat = retourJson.isArray().get(1).isArray();
56
 
57
		String[] suggestions = new String[tableauResultat.size()];
58
		for (int i = 0; i < tableauResultat.size(); i++) {
59
			suggestions[i] = tableauResultat.get(i).isString().stringValue();
60
		}
61
 
62
		return suggestions;
63
	}
64
}