Subversion Repositories eFlore/Applications.cel

Rev

Rev 1549 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1549 Rev 1572
Line 2... Line 2...
2
 
2
 
3
import java.util.HashMap;
3
import java.util.HashMap;
4
import java.util.Iterator;
4
import java.util.Iterator;
Line -... Line 5...
-
 
5
import java.util.Map;
5
import java.util.Map;
6
 
Line 6... Line 7...
6
 
7
import org.tela_botanica.client.modeles.objets.ChampEtendu;
-
 
8
import org.tela_botanica.client.modeles.objets.Observation;
7
import org.tela_botanica.client.modeles.objets.Observation;
9
 
8
 
10
import com.google.gwt.http.client.URL;
Line 9... Line 11...
9
import com.google.gwt.http.client.URL;
11
import com.google.gwt.json.client.JSONArray;
Line 17... Line 19...
17
	
19
	
18
	public static String getValeurJsonOuVide(JSONObject jo, String index) {
20
	public static String getValeurJsonOuVide(JSONObject jo, String index) {
19
		return jsonNonNull(jo, index) ? ((JSONString)jo.get(index)).stringValue() : "";
21
		return jsonNonNull(jo, index) ? ((JSONString)jo.get(index)).stringValue() : "";
Line 20... Line 22...
20
	}
22
	}
21
	
23
	
22
	public static Map<String, String> getMapValeursOuVide(JSONObject jo, String index) {
24
	public static Map<String, ChampEtendu> getMapValeursOuVide(JSONObject jo, String index) {
23
		Map<String, String> mapValeurs = new HashMap<String, String>();
25
		Map<String, ChampEtendu> mapValeurs = new HashMap<String, ChampEtendu>();
24
		if(jo.get(index) != null && jo.get(index).isObject() != null) {	
26
		if(jo.get(index) != null && jo.get(index).isArray() != null) {	
25
			JSONObject mapJo = jo.get(index).isObject();
27
			JSONArray tabJo = jo.get(index).isArray();
26
			for (Iterator<String> it = mapJo.keySet().iterator(); it.hasNext();) {
28
			for (int i = 0; i < tabJo.size(); i++) {
-
 
29
				JSONObject champJson = tabJo.get(i).isObject();
-
 
30
				String cle = champJson.get("cle").isString().stringValue();
-
 
31
				String label = champJson.get("label").isString().stringValue();
-
 
32
				String valeur = champJson.get("valeur").isString().stringValue();
27
				String cle = it.next();
33
				ChampEtendu champ = new ChampEtendu(cle, label, valeur);
-
 
34
				mapValeurs.put(cle, champ);
28
				mapValeurs.put(cle, mapJo.get(cle).isString().stringValue());
35
			}
29
			}
36
 
30
		}
37
		}
Line 31... Line 38...
31
		return mapValeurs;
38
		return mapValeurs;
32
	}
39
	}
33
	
40
	
-
 
41
	public static String convertirChampsEtendusEnChaineRequete(Map<String, ChampEtendu> map) {
34
	public static String convertirMapEnChaineRequete(Map<String, String> map, String cleUrl) {
42
		String json = "";
35
		String chaineChamps = "";
43
	    if (map != null && !map.isEmpty()) {
36
		for (Iterator<String> it = map.keySet().iterator(); it.hasNext();) {
44
	    	JSONArray jsonArr = new JSONArray();
-
 
45
	    	int i = 0;
-
 
46
	        for (Map.Entry<String, ChampEtendu> entry: map.entrySet()) {
-
 
47
	        	jsonArr.set(i, convertirChampEtenduEnJson(entry.getValue()));
-
 
48
	        	i++;
-
 
49
	        }
37
			String cle = it.next();
50
	        json = jsonArr.toString();
-
 
51
	    }
-
 
52
	    return json;
-
 
53
	}
-
 
54
	
-
 
55
	public static JSONObject convertirChampEtenduEnJson(ChampEtendu champEtendu) {
-
 
56
		JSONObject jsonObj = new JSONObject();
38
			String valeur = map.get(cle);
57
		jsonObj.put("cle", new JSONString(champEtendu.getCle()));
39
			chaineChamps += URL.encode(cleUrl+"["+cle+"]")+"="+URL.encode(valeur)+"&";
58
		jsonObj.put("label", new JSONString(champEtendu.getLabel()));
Line 40... Line 59...
40
		}
59
		jsonObj.put("valeur", new JSONString(champEtendu.getValeur()));
41
		return chaineChamps;
60
        return jsonObj;
42
	}
61
	}
Line 262... Line 281...
262
		
281
		
Line 263... Line 282...
263
		String dateRemplacee = date.replaceAll("-", "/");
282
		String dateRemplacee = date.replaceAll("-", "/");
264
	    
283
	    
-
 
284
	    return dateRemplacee;
-
 
285
	}
-
 
286
	
-
 
287
	public static boolean estZero(String s) {
-
 
288
		boolean estZero = false;
-
 
289
	    try { 
-
 
290
	    	Double dou = Double.parseDouble(s); 
-
 
291
	    	estZero = (dou == 0);
-
 
292
	    } catch(NumberFormatException e) { 
-
 
293
 
-
 
294
	    }
-
 
295
	    return estZero;
-
 
296
	}
-
 
297
	
-
 
298
	public static String formaterNombre(String s) {
-
 
299
		s = s.indexOf(".") < 0 ? s : s.replaceAll("0*$", "").replaceAll("\\.$", "");
265
	    return dateRemplacee;
300
		return s;