Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 1332 Rev 1542
Line 1... Line 1...
1
package org.tela_botanica.client.util;
1
package org.tela_botanica.client.util;
Line -... Line 2...
-
 
2
 
-
 
3
import java.util.HashMap;
-
 
4
import java.util.Map;
-
 
5
 
2
 
6
import org.tela_botanica.client.modeles.objets.ListeObservation;
Line -... Line 7...
-
 
7
import org.tela_botanica.client.modeles.objets.Observation;
3
import org.tela_botanica.client.modeles.objets.Observation;
8
 
4
 
9
import com.google.gwt.json.client.JSONArray;
Line 5... Line 10...
5
import com.google.gwt.json.client.JSONObject;
10
import com.google.gwt.json.client.JSONObject;
Line 12... Line 17...
12
	
17
	
13
	public static String getValeurJsonOuVide(JSONObject jo, String index) {
18
	public static String getValeurJsonOuVide(JSONObject jo, String index) {
14
		return jsonNonNull(jo, index) ? ((JSONString)jo.get(index)).stringValue() : "";
19
		return jsonNonNull(jo, index) ? ((JSONString)jo.get(index)).stringValue() : "";
Line -... Line 20...
-
 
20
	}
-
 
21
	
-
 
22
	public static Map<String, String> getMapValeursOuVide(JSONArray jo, String index) {
-
 
23
		Map<String, String> mapValeurs = new HashMap<String, String>();
-
 
24
		final int taillemax = jo.size();	
-
 
25
		JSONObject temp = null;
-
 
26
		for (int i = 0; i < taillemax; i++) {
-
 
27
			if ((temp = jo.get(i).isObject()) != null) {
-
 
28
				mapValeurs.put(temp.get("cle").isString().stringValue(), temp.get("valeur").isString().stringValue());
-
 
29
			}
-
 
30
		}
-
 
31
		return mapValeurs;
15
	}
32
	}
16
	
33
	
17
	public static boolean jsonNonNull(JSONObject jo, String index) {
34
	public static boolean jsonNonNull(JSONObject jo, String index) {
18
		return (jo != null && 
35
		return (jo != null && 
19
				jo.get(index) != null && 
36
				jo.get(index) != null && 
Line 72... Line 89...
72
		lieuModele = lieuModele.replaceAll(",^$",", ");
89
		lieuModele = lieuModele.replaceAll(",^$",", ");
Line 73... Line 90...
73
		
90
		
74
		return lieuModele;
91
		return lieuModele;
Line -... Line 92...
-
 
92
	}
-
 
93
	
-
 
94
	public static String obtenirDepartementAPartirChaineCommune(String departement, String commune) {
-
 
95
		
-
 
96
		String dep = "";
-
 
97
		
-
 
98
		if(departement == null) {
-
 
99
			departement = "";
-
 
100
		}
-
 
101
		
-
 
102
		if(departement.equals("000null") || departement.equals("")) {
-
 
103
					
-
 
104
			String[] depCom = commune.split(" ");
-
 
105
			if(depCom.length > 1) {
-
 
106
				dep = depCom[1].replace('(', ' ');
-
 
107
			} else {
-
 
108
				dep = "";
-
 
109
			}
-
 
110
		} else {
-
 
111
			dep = departement;
-
 
112
		}
-
 
113
		
-
 
114
		dep = dep.replace(')', ' ');
-
 
115
		dep = dep.trim();
-
 
116
		dep = dep.replace('\\',' ');
-
 
117
		dep = dep.trim();
-
 
118
		
-
 
119
		try
-
 
120
		{
-
 
121
			int nDep = Integer.parseInt(dep);
-
 
122
			if(nDep > 0 && nDep < 110) {
-
 
123
				departement = dep ;
-
 
124
			}
-
 
125
			
-
 
126
			if(departement.length() == 4) {
-
 
127
				departement = "0"+departement;
-
 
128
			}
-
 
129
			
-
 
130
			departement = departement.substring(0,2);
-
 
131
		}
-
 
132
		catch(NumberFormatException e)
-
 
133
		{
-
 
134
			departement = "" ;
-
 
135
		}
-
 
136
		
-
 
137
		return departement;
75
	}
138
	}
76
	
139
	
77
	public static String supprimerNumDepartementChaineLocalite(String chaineLocaliteComplete) {
140
	public static String supprimerNumDepartementChaineLocalite(String chaineLocaliteComplete) {
Line 78... Line 141...
78
		return chaineLocaliteComplete.replaceAll(" \\([0-9]*\\)", "");
141
		return chaineLocaliteComplete.replaceAll(" \\([0-9]*\\)", "");