Subversion Repositories eFlore/Applications.cel

Rev

Rev 235 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
54 david 1
package org.tela_botanica.client.modeles;
2
 
3
import org.tela_botanica.client.interfaces.Rafraichissable;
4
import org.tela_botanica.client.observation.ObservationModele;
5
 
6
import com.google.gwt.http.client.Request;
7
import com.google.gwt.http.client.RequestBuilder;
8
import com.google.gwt.http.client.RequestCallback;
9
import com.google.gwt.http.client.RequestException;
10
import com.google.gwt.http.client.Response;
11
import com.google.gwt.json.client.JSONArray;
12
import com.google.gwt.json.client.JSONParser;
13
import com.google.gwt.json.client.JSONString;
14
import com.google.gwt.json.client.JSONValue;
15
 
16
/**
17
 * DAO d'accès a une observation
18
 *
19
 * @author aurelien
20
 *
21
 */
22
public class ImageGeneriqueVueAsynchroneDAO {
23
 
24
	/**
25
	 * Le modele associé au DAO
26
	 */
27
	private ObservationModele observationModele = null;
28
 
29
	public ImageGeneriqueVueAsynchroneDAO(ObservationModele obs) {
30
		observationModele = obs;
31
	}
32
 
33
 
34
 
35
	/**
36
	 * Recherche Image repartition associee a un nom
37
	 * @param r
38
	 * @param identifiant
39
	 * @param numeroNomenclaturalSaisiObservation
40
	 */
41
 
42
	public void obtenirURLImage(final Rafraichissable r, String numeroNomenclaturalSaisiObservation) {
43
 
44
 
45
 
46
		// on envoie le get asynchrone
47
		RequestBuilder rb = new RequestBuilder(RequestBuilder.GET,observationModele.getConfig().getServiceBaseUrl()
48
				+"/NameImage/"+numeroNomenclaturalSaisiObservation) ;
49
 
50
		try {
51
			rb.sendRequest(null, new RequestCallback() {
52
 
53
				public void onError(Request request, Throwable exception) {
54
					// TODO Auto-generated method stub
55
 
56
				}
57
 
58
				public void onResponseReceived(Request request,
59
						Response response) {
60
 
61
					JSONValue responseValue = JSONParser.parse(response.getText());
62
					JSONArray reponse;
63
					String urlImage=null;
64
 
65
					if ((reponse = responseValue.isArray()) != null) {
66
						// Url Image
67
						urlImage= ((JSONString)reponse.get(0)).stringValue();
68
					}
69
					else {
70
						urlImage="";
71
					}
72
 
73
					r.rafraichir(urlImage,true);
74
				}
75
			}) ;
76
 
77
		} catch (RequestException e) {
78
			// TODO Auto-generated catch block
79
			e.printStackTrace();
80
		}
81
	}
82
 
83
 
84
 
85
}