Subversion Repositories eFlore/Applications.del

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

package org.tela_botanica.del.client.services;

import com.google.gwt.http.client.Response;
import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONParser;
import com.google.gwt.json.client.JSONValue;

public class UtilitairesAutoCompletionService {
        
        // Attention à n'utiliser que si eflore est installé
        public static String urlServiceCompletionNomEflore = "http://localhost/service:eflore:0.1/bdtfx/noms";  
        public static String urlServiceCompletionNomLocale = "../jrest/NomsTaxons/";    
        
        public static String effectuerPreTraitementChaineRequeteGenreEspeceSlash(String requete) {
                String chaineTraitee = requete;
                String[] parties = requete.split(" ", 2);
                
                if(parties.length == 2) {
                        if(parties[1].trim().isEmpty()) {
                                parties[1] = "*";
                        }
                        chaineTraitee = parties[0]+"/"+parties[1];
                }
                
                return chaineTraitee;
        }
        
        public static String effectuerPreTraitementChaineRequeteGenreEspeceEflore(String requete) {
                
                String chaineTraitee = "?recherche=etendue&ns.structure=au&retour.format=oss&masque="+requete;
                return chaineTraitee;
        }
        
        public static String[] parserRetourSimple(Response response) {
                final JSONValue responseValue = JSONParser.parseStrict(response.getText());
                JSONArray noms;
                String[] valeurs = new String[0];
        
                if ((noms=responseValue.isArray()) != null) {
                                
                        final int taillemax = noms.size();      
                        valeurs = new String[taillemax];
                        for (int i = 0; i < taillemax; i++) {
                                valeurs[i] = (noms.get(i).isArray().get(0).isString().stringValue());
                        }
                }
                
                return valeurs;
        }
        
        public static String[] parserRetourOss(Response response) {
                JSONValue retourJson = JSONParser.parseStrict(response.getText());
                JSONArray tableauResultat = retourJson.isArray().get(1).isArray();
                
                String[] suggestions = new String[tableauResultat.size()];
                for (int i = 0; i < tableauResultat.size(); i++) {
                        suggestions[i] = tableauResultat.get(i).isString().stringValue();
                }
                
                return suggestions;
        }
}