Subversion Repositories eFlore/Applications.cel

Rev

Rev 2392 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2392 Rev 2401
1
package org.tela_botanica.client.util;
1
package org.tela_botanica.client.util;
2
 
2
 
3
import java.util.ArrayList;
3
import java.util.ArrayList;
4
import java.util.Collections;
4
import java.util.Collections;
5
import java.util.Comparator;
5
import java.util.Comparator;
6
import java.util.HashMap;
6
import java.util.HashMap;
7
import java.util.List;
7
import java.util.List;
8
import java.util.Map;
8
import java.util.Map;
9
import java.util.Vector;
9
import java.util.Vector;
10
 
10
 
11
import org.tela_botanica.client.modeles.objets.ChampEtendu;
11
import org.tela_botanica.client.modeles.objets.ChampEtendu;
12
import org.tela_botanica.client.modeles.objets.Observation;
12
import org.tela_botanica.client.modeles.objets.Observation;
13
 
13
 
14
import com.google.gwt.json.client.JSONArray;
14
import com.google.gwt.json.client.JSONArray;
15
import com.google.gwt.json.client.JSONObject;
15
import com.google.gwt.json.client.JSONObject;
16
import com.google.gwt.json.client.JSONString;
16
import com.google.gwt.json.client.JSONString;
17
 
17
 
18
public class Util {
18
public class Util {
19
 
19
 
20
	public Util() {
20
	public Util() {
21
	}
21
	}
22
	
22
	
23
	public static String getValeurJsonOuVide(JSONObject jo, String index) {
23
	public static String getValeurJsonOuVide(JSONObject jo, String index) {
24
		return jsonNonNull(jo, index) ? ((JSONString)jo.get(index)).stringValue() : "";
24
		return jsonNonNull(jo, index) ? ((JSONString)jo.get(index)).stringValue() : "";
25
	}
25
	}
26
	
26
	
27
	public static Map<String, ChampEtendu> getMapValeursOuVide(JSONObject jo, String index) {
27
	public static Map<String, ChampEtendu> getMapValeursOuVide(JSONObject jo, String index) {
28
		Map<String, ChampEtendu> mapValeurs = new HashMap<String, ChampEtendu>();
28
		Map<String, ChampEtendu> mapValeurs = new HashMap<String, ChampEtendu>();
29
		if(jo.get(index) != null && jo.get(index).isArray() != null) {	
29
		if(jo.get(index) != null && jo.get(index).isArray() != null) {	
30
			JSONArray tabJo = jo.get(index).isArray();
30
			JSONArray tabJo = jo.get(index).isArray();
31
			for (int i = 0; i < tabJo.size(); i++) {
31
			for (int i = 0; i < tabJo.size(); i++) {
32
				JSONObject champJson = tabJo.get(i).isObject();
32
				JSONObject champJson = tabJo.get(i).isObject();
33
				String cle = champJson.get("cle").isString().stringValue();
33
				String cle = champJson.get("cle").isString().stringValue();
34
				String label = cle;
34
				String label = cle;
35
				String valeur = champJson.get("valeur").isString().stringValue();
35
				String valeur = champJson.get("valeur").isString().stringValue();
36
				ChampEtendu champ = new ChampEtendu(cle, label, valeur);
36
				ChampEtendu champ = new ChampEtendu(cle, label, valeur);
37
				mapValeurs.put(cle, champ);
37
				mapValeurs.put(cle, champ);
38
			}
38
			}
39
 
39
 
40
		}
40
		}
41
		return mapValeurs;
41
		return mapValeurs;
42
	}
42
	}
43
	
43
	
44
	public static String convertirChampsEtendusEnChaineRequete(Map<String, ChampEtendu> map) {
44
	public static String convertirChampsEtendusEnChaineRequete(Map<String, ChampEtendu> map) {
45
		String json = "";
45
		String json = "";
46
	    if (map != null && !map.isEmpty()) {
46
	    if (map != null && !map.isEmpty()) {
47
	    	JSONArray jsonArr = new JSONArray();
47
	    	JSONArray jsonArr = new JSONArray();
48
	    	int i = 0;
48
	    	int i = 0;
49
	        for (Map.Entry<String, ChampEtendu> entry: map.entrySet()) {
49
	        for (Map.Entry<String, ChampEtendu> entry: map.entrySet()) {
50
	        	jsonArr.set(i, convertirChampEtenduEnJson(entry.getValue()));
50
	        	jsonArr.set(i, convertirChampEtenduEnJson(entry.getValue()));
51
	        	i++;
51
	        	i++;
52
	        }
52
	        }
53
	        json = jsonArr.toString();
53
	        json = jsonArr.toString();
54
	    }
54
	    }
55
	    return json;
55
	    return json;
56
	}
56
	}
57
	
57
	
58
	public static JSONObject convertirChampEtenduEnJson(ChampEtendu champEtendu) {
58
	public static JSONObject convertirChampEtenduEnJson(ChampEtendu champEtendu) {
59
		JSONObject jsonObj = new JSONObject();
59
		JSONObject jsonObj = new JSONObject();
60
		jsonObj.put("cle", new JSONString(champEtendu.getCle()));
60
		jsonObj.put("cle", new JSONString(champEtendu.getCle()));
61
		jsonObj.put("label", new JSONString(champEtendu.getLabel()));
61
		jsonObj.put("label", new JSONString(champEtendu.getLabel()));
62
		jsonObj.put("valeur", new JSONString(champEtendu.getValeur()));
62
		jsonObj.put("valeur", new JSONString(champEtendu.getValeur()));
63
        return jsonObj;
63
        return jsonObj;
64
	}
64
	}
65
	
65
	
66
	public static boolean jsonNonNull(JSONObject jo, String index) {
66
	public static boolean jsonNonNull(JSONObject jo, String index) {
67
		return (jo != null && 
67
		return (jo != null && 
68
				jo.get(index) != null && 
68
				jo.get(index) != null && 
69
				jo.get(index).isNull() == null
69
				jo.get(index).isNull() == null
70
			   );			
70
			   );			
71
	}
71
	}
72
	
72
	
73
	public static String formaterLieu(Observation obs, String modeleLieu) {
73
	public static String formaterLieu(Observation obs, String modeleLieu) {
74
		
74
		
75
		String lieuModele = modeleLieu;
75
		String lieuModele = modeleLieu;
76
		
76
		
77
		String commune = obs.getLocalite(); 
77
		String commune = obs.getLocalite(); 
78
		String lieuDit = obs.getLieudit();
78
		String lieuDit = obs.getLieudit();
79
		String station = obs.getStation();
79
		String station = obs.getStation();
80
		
80
		
81
		String lieuCommuneFormate = "";
81
		String lieuCommuneFormate = "";
82
		String lieuDitFormate = "";
82
		String lieuDitFormate = "";
83
		String stationFormatee = "";
83
		String stationFormatee = "";
84
		
84
		
85
		if(commune != null && !commune.contains("000null") && !commune.trim().equals("")) {
85
		if(commune != null && !commune.contains("000null") && !commune.trim().equals("")) {
86
			String	idLoc =obs.getIdentifiantLocalite().replaceAll(" ","/");
86
			String	idLoc =obs.getIdentifiantLocalite().replaceAll(" ","/");
87
			if(idLoc != null && !idLoc.contains("000null") && !idLoc.trim().equals("")) {
87
			if(idLoc != null && !idLoc.contains("000null") && !idLoc.trim().equals("")) {
88
 
88
 
89
				idLoc = idLoc.replaceAll("%","");
89
				idLoc = idLoc.replaceAll("%","");
90
				idLoc = idLoc.replaceAll("\"","");
90
				idLoc = idLoc.replaceAll("\"","");
91
				idLoc = idLoc.replace('\\',' ');
91
				idLoc = idLoc.replace('\\',' ');
92
				idLoc = idLoc.trim();
92
				idLoc = idLoc.trim();
93
				if(idLoc.length() > 2) {
93
				if(idLoc.length() > 2) {
94
					idLoc = idLoc.substring(0,2);
94
					idLoc = idLoc.substring(0,2);
95
				}
95
				}
96
				lieuCommuneFormate += idLoc+" - ";
96
				lieuCommuneFormate += idLoc+" - ";
97
			}
97
			}
98
			lieuCommuneFormate += commune;
98
			lieuCommuneFormate += commune;
99
			lieuModele = lieuModele.replaceAll("IDLOCCOMMUNE", lieuCommuneFormate);
99
			lieuModele = lieuModele.replaceAll("IDLOCCOMMUNE", lieuCommuneFormate);
100
		} else {
100
		} else {
101
			
101
			
102
			lieuModele = lieuModele.replaceAll("IDLOCCOMMUNE,", lieuCommuneFormate);
102
			lieuModele = lieuModele.replaceAll("IDLOCCOMMUNE,", lieuCommuneFormate);
103
		}
103
		}
104
		
104
		
105
		if(lieuDit != null && !lieuDit.contains("000null") && !lieuDit.trim().equals("")) {
105
		if(lieuDit != null && !lieuDit.contains("000null") && !lieuDit.trim().equals("")) {
106
			lieuDitFormate += lieuDit;
106
			lieuDitFormate += lieuDit;
107
			lieuModele = lieuModele.replaceAll("LIEUDIT", lieuDitFormate);
107
			lieuModele = lieuModele.replaceAll("LIEUDIT", lieuDitFormate);
108
		} else {
108
		} else {
109
			lieuModele = lieuModele.replaceAll("LIEUDIT,", lieuDitFormate);
109
			lieuModele = lieuModele.replaceAll("LIEUDIT,", lieuDitFormate);
110
		}
110
		}
111
		
111
		
112
		if(station != null && !station.contains("000null") && !station.trim().equals("")) {
112
		if(station != null && !station.contains("000null") && !station.trim().equals("")) {
113
			stationFormatee += station;
113
			stationFormatee += station;
114
			lieuModele = lieuModele.replaceAll("STATION", stationFormatee);
114
			lieuModele = lieuModele.replaceAll("STATION", stationFormatee);
115
		} else {
115
		} else {
116
			lieuModele = lieuModele.replaceAll("STATION", stationFormatee);
116
			lieuModele = lieuModele.replaceAll("STATION", stationFormatee);
117
		}
117
		}
118
		
118
		
119
		lieuModele = lieuModele.trim();
119
		lieuModele = lieuModele.trim();
120
		lieuModele = lieuModele.replaceAll(",$","");
120
		lieuModele = lieuModele.replaceAll(",$","");
121
		lieuModele = lieuModele.replaceAll(",^$",", ");
121
		lieuModele = lieuModele.replaceAll(",^$",", ");
122
		
122
		
123
		return lieuModele;
123
		return lieuModele;
124
	}
124
	}
125
	
125
	
126
	public static String obtenirDepartementAPartirChaineCommune(String departement, String commune) {
126
	public static String obtenirDepartementAPartirChaineCommune(String departement, String commune) {
127
		
127
		
128
		String dep = "";
128
		String dep = "";
129
		
129
		
130
		if(departement == null) {
130
		if(departement == null) {
131
			departement = "";
131
			departement = "";
132
		}
132
		}
133
		
133
		
134
		if(departement.equals("000null") || departement.equals("")) {
134
		if(departement.equals("000null") || departement.equals("")) {
135
					
135
					
136
			String[] depCom = commune.split(" ");
136
			String[] depCom = commune.split(" ");
137
			if(depCom.length > 1) {
137
			if(depCom.length > 1) {
138
				dep = depCom[1].replace('(', ' ');
138
				dep = depCom[1].replace('(', ' ');
139
			} else {
139
			} else {
140
				dep = "";
140
				dep = "";
141
			}
141
			}
142
		} else {
142
		} else {
143
			dep = departement;
143
			dep = departement;
144
		}
144
		}
145
		
145
		
146
		dep = dep.replace(')', ' ');
146
		dep = dep.replace(')', ' ');
147
		dep = dep.trim();
147
		dep = dep.trim();
148
		dep = dep.replace('\\',' ');
148
		dep = dep.replace('\\',' ');
149
		dep = dep.trim();
149
		dep = dep.trim();
150
		
150
		
151
		try
151
		try
152
		{
152
		{
153
			int nDep = Integer.parseInt(dep);
153
			int nDep = Integer.parseInt(dep);
154
			if(nDep > 0 && nDep < 110) {
154
			if(nDep > 0 && nDep < 110) {
155
				departement = dep ;
155
				departement = dep ;
156
			}
156
			}
157
			
157
			
158
			if(departement.length() == 4) {
158
			if(departement.length() == 4) {
159
				departement = "0"+departement;
159
				departement = "0"+departement;
160
			}
160
			}
161
			
161
			
162
			departement = departement.substring(0,2);
162
			departement = departement.substring(0,2);
163
		}
163
		}
164
		catch(NumberFormatException e)
164
		catch(NumberFormatException e)
165
		{
165
		{
166
			departement = "" ;
166
			departement = "" ;
167
		}
167
		}
168
		
168
		
169
		return departement;
169
		return departement;
170
	}
170
	}
171
	
171
	
172
	public static String supprimerNumDepartementChaineLocalite(String chaineLocaliteComplete) {
172
	public static String supprimerNumDepartementChaineLocalite(String chaineLocaliteComplete) {
173
		return chaineLocaliteComplete.replaceAll(" \\([0-9]*\\)", "");
173
		return chaineLocaliteComplete.replaceAll(" \\([0-9]*\\)", "");
174
	}
174
	}
175
	
175
	
176
	public static String convertirChaineZoneGeoVersDepartement(String chaineZoneGeo) {
176
	public static String convertirChaineZoneGeoVersDepartement(String chaineZoneGeo) {
177
		return (!chaineZoneGeo.equals("000null") && !chaineZoneGeo.equals("") && chaineZoneGeo.replaceAll("INSEE-C:", "").length() >= 2) ? 
177
		return (!chaineZoneGeo.equals("000null") && !chaineZoneGeo.equals("") && chaineZoneGeo.replaceAll("INSEE-C:", "").length() >= 2) ? 
178
						chaineZoneGeo.replaceAll("INSEE-C:", "").substring(0, 2) : 
178
						chaineZoneGeo.replaceAll("INSEE-C:", "").substring(0, 2) : 
179
						chaineZoneGeo;
179
						chaineZoneGeo;
180
	}
180
	}
181
	
181
	
182
	public static String convertirChaineZoneGeoVersCodeInsee(String chaineZoneGeo) {
182
	public static String convertirChaineZoneGeoVersCodeInsee(String chaineZoneGeo) {
183
		return (!chaineZoneGeo.equals("000null") && !chaineZoneGeo.equals("")) ? chaineZoneGeo.replaceAll("INSEE-C:", ""): chaineZoneGeo;
183
		return (!chaineZoneGeo.equals("000null") && !chaineZoneGeo.equals("")) ? chaineZoneGeo.replaceAll("INSEE-C:", ""): chaineZoneGeo;
184
	}
184
	}
185
	
185
	
186
	/***
186
	/***
187
	 * Fusionne les éléments d'un tableau en une chaîne
187
	 * Fusionne les éléments d'un tableau en une chaîne
188
	 * @param delim : la chaîne de séparation
188
	 * @param delim : la chaîne de séparation
189
	 * @param args : la tableau
189
	 * @param args : la tableau
190
	 * @return la chaîne fusionnée
190
	 * @return la chaîne fusionnée
191
	 */
191
	 */
192
	public static String implode(String delim, String[] args){
192
	public static String implode(String delim, String[] args){
193
		StringBuffer sb = new StringBuffer();
193
		StringBuffer sb = new StringBuffer();
194
		
194
		
195
		int lgArgs = args.length;
195
		int lgArgs = args.length;
196
		
196
		
197
		for(int i = 0; i < lgArgs; i++){
197
		for(int i = 0; i < lgArgs; i++){
198
			if (i > 0) {
198
			if (i > 0) {
199
				sb.append(delim);
199
				sb.append(delim);
200
			}
200
			}
201
			
201
			
202
			sb.append(args[i]);
202
			sb.append(args[i]);
203
		}
203
		}
204
		
204
		
205
		return sb.toString();
205
		return sb.toString();
206
	}
206
	}
207
	
207
	
208
	public static boolean filtreValide(String[] filtre) {
208
	public static boolean filtreValide(String[] filtre) {
209
		
209
		
210
		return (filtre.length == 2 && 
210
		return (filtre.length == 2 && 
211
		filtre[0] != null &&
211
		filtre[0] != null &&
212
		!filtre[0].equals("") &&
212
		!filtre[0].equals("") &&
213
		filtre[1] != null &&
213
		filtre[1] != null &&
214
		!filtre[1].equals(""));
214
		!filtre[1].equals(""));
215
	}
215
	}
216
	
216
	
217
	public static String renvoyerMois(int numMois) {
217
	public static String renvoyerMois(int numMois) {
218
			
218
			
219
		switch (numMois) {
219
		switch (numMois) {
220
		case 1:
220
		case 1:
221
			return "janvier" ;
221
			return "janvier" ;
222
		case 2:
222
		case 2:
223
			return "fevrier" ;
223
			return "fevrier" ;
224
		case 3:
224
		case 3:
225
			return "mars" ;
225
			return "mars" ;
226
		case 4:
226
		case 4:
227
			return "avril" ;
227
			return "avril" ;
228
		case 5:
228
		case 5:
229
			return "mai" ;
229
			return "mai" ;
230
		case 6:
230
		case 6:
231
			return "juin" ;
231
			return "juin" ;
232
		case 7:
232
		case 7:
233
			return "juillet" ;
233
			return "juillet" ;
234
		case 8:
234
		case 8:
235
			return "août" ;
235
			return "août" ;
236
		case 9:
236
		case 9:
237
			return "septembre" ;
237
			return "septembre" ;
238
		case 10:
238
		case 10:
239
			return "octobre" ;
239
			return "octobre" ;
240
		case 11:
240
		case 11:
241
			return "novembre" ;
241
			return "novembre" ;
242
		case 12:
242
		case 12:
243
			return "décembre" ;
243
			return "décembre" ;
244
		default:
244
		default:
245
			return "Inconnu" ;
245
			return "Inconnu" ;
246
		}
246
		}
247
	}
247
	}
248
	
248
	
249
	public static String remplacerSautsDeligneMalEncodes(String chaineAvecSautsDeLignesMalEncodes) {
249
	public static String remplacerSautsDeligneMalEncodes(String chaineAvecSautsDeLignesMalEncodes) {
250
		
250
		
251
		String chaineAvecSautsDeLignesBienEncodes = chaineAvecSautsDeLignesMalEncodes.replace('\\','%');
251
		String chaineAvecSautsDeLignesBienEncodes = chaineAvecSautsDeLignesMalEncodes.replace('\\','%');
252
		chaineAvecSautsDeLignesBienEncodes = chaineAvecSautsDeLignesBienEncodes.replaceAll("%n","%");
252
		chaineAvecSautsDeLignesBienEncodes = chaineAvecSautsDeLignesBienEncodes.replaceAll("%n","%");
253
		chaineAvecSautsDeLignesBienEncodes = chaineAvecSautsDeLignesBienEncodes.replace('%','\n');
253
		chaineAvecSautsDeLignesBienEncodes = chaineAvecSautsDeLignesBienEncodes.replace('%','\n');
254
		
254
		
255
		return chaineAvecSautsDeLignesBienEncodes;
255
		return chaineAvecSautsDeLignesBienEncodes;
256
	}
256
	}
257
	
257
	
258
	public static boolean verifierDateFormatCel(String dateAVerifier) {
258
	public static boolean verifierDateFormatCel(String dateAVerifier) {
259
		
259
		
260
		String dateRemplacee = remplacerSeparateursDateFormatCel(dateAVerifier);	
260
		String dateRemplacee = remplacerSeparateursDateFormatCel(dateAVerifier);	
261
		String[] tabDate = dateRemplacee.split("/");
261
		String[] tabDate = dateRemplacee.split("/");
262
		
262
		
263
		boolean retour = false;
263
		boolean retour = false;
264
		
264
		
265
		if(tabDate.length == 3) {
265
		if(tabDate.length == 3) {
266
			//TODO: faire un parsing de date qui fonctionne mieux car 
266
			//TODO: faire un parsing de date qui fonctionne mieux car 
267
			// on peut saisir un 31 novembre par exemple
267
			// on peut saisir un 31 novembre par exemple
268
			// mais l'api date de java est mal gérée par gwt
268
			// mais l'api date de java est mal gérée par gwt
269
			try {
269
			try {
270
				int jour = Integer.parseInt(tabDate[0]);
270
				int jour = Integer.parseInt(tabDate[0]);
271
				int mois = Integer.parseInt(tabDate[1]);
271
				int mois = Integer.parseInt(tabDate[1]);
272
				int annee = Integer.parseInt(tabDate[2]);
272
				int annee = Integer.parseInt(tabDate[2]);
273
				
273
				
274
				if(jour <= 31 && mois <= 12 && tabDate[2].length() == 4) {
274
				if(jour <= 31 && mois <= 12 && tabDate[2].length() == 4) {
275
					retour = true;
275
					retour = true;
276
				}
276
				}
277
			} catch (Exception e) {
277
			} catch (Exception e) {
278
 
278
 
279
			}
279
			}
280
		}
280
		}
281
		    
281
		    
282
		return retour;
282
		return retour;
283
	}
283
	}
284
	
284
	
285
	public static String remplacerSeparateursDateFormatCel(String date) {
285
	public static String remplacerSeparateursDateFormatCel(String date) {
286
		
286
		
287
		String dateRemplacee = date.replaceAll("-", "/");
287
		String dateRemplacee = date.replaceAll("-", "/");
288
	    
288
	    
289
	    return dateRemplacee;
289
	    return dateRemplacee;
290
	}
290
	}
291
	
291
	
292
	public static boolean estZero(String s) {
292
	public static boolean estZero(String s) {
293
		boolean estZero = false;
293
		boolean estZero = false;
294
	    try { 
294
	    try { 
295
	    	Double dou = Double.parseDouble(s); 
295
	    	Double dou = Double.parseDouble(s); 
296
	    	estZero = (dou == 0);
296
	    	estZero = (dou == 0);
297
	    } catch(NumberFormatException e) { 
297
	    } catch(NumberFormatException e) { 
298
 
298
 
299
	    }
299
	    }
300
	    return estZero;
300
	    return estZero;
301
	}
301
	}
302
	
302
	
303
	public static String formaterNombre(String s) {
303
	public static String formaterNombre(String s) {
304
		s = s.indexOf(".") < 0 ? s : s.replaceAll("0*$", "").replaceAll("\\.$", "");
304
		s = s.indexOf(".") < 0 ? s : s.replaceAll("0*$", "").replaceAll("\\.$", "");
305
		return s;
305
		return s;
306
	}
306
	}
307
 
307
 
308
	// Prend un nombre décimal avec le spéparateur spécifié et le tronque à n décimales
308
	// Prend un nombre décimal avec le spéparateur spécifié et le tronque à n décimales
309
	public static String tronquerNombrePourAffichage(String nombre, int decimales, char separateur) {
309
	public static String tronquerNombrePourAffichage(String nombre, int decimales, char separateur) {
310
		String retour = nombre;
310
		String retour = nombre;
311
		int posSep = nombre.indexOf(separateur);
311
		int posSep = nombre.indexOf(separateur);
312
		if (posSep >= 0) {
312
		if (posSep >= 0) {
313
			int taille = posSep + decimales + 1;
313
			int taille = posSep + decimales + 1;
314
			if (nombre.length() < taille) {
314
			if (nombre.length() < taille) {
315
				taille = nombre.length();
315
				taille = nombre.length();
316
			}
316
			}
317
			retour = nombre.substring(0, taille);
317
			retour = nombre.substring(0, taille);
318
		}
318
		}
319
		return retour;
319
		return retour;
320
	}
320
	}
321
 
321
 
322
	public static String tronquerNombrePourAffichage(String nombre, int decimales) {
322
	public static String tronquerNombrePourAffichage(String nombre, int decimales) {
323
		return tronquerNombrePourAffichage(nombre, decimales, '.');
323
		return tronquerNombrePourAffichage(nombre, decimales, '.');
324
	}
324
	}
325
	
325
	
326
	// Adapté de http://www.programcreek.com/2011/03/java-method-for-spliting-a-camelcase-string/
326
	// Adapté de http://www.programcreek.com/2011/03/java-method-for-spliting-a-camelcase-string/
327
	public static String formaterCleChampsEtenduPourAffichage(String s) {
327
	public static String formaterCleChampsEtenduPourAffichage(String s) {
328
		char[] cArray = s.toCharArray();
328
		char[] cArray = s.toCharArray();
329
		 
329
		 
330
		Vector<Integer> al = new Vector<Integer>();
330
		Vector<Integer> al = new Vector<Integer>();
331
		al.add(0);
331
		al.add(0);
332
	 
332
	 
333
		// get all upper case letter index positions
333
		// get all upper case letter index positions
334
		for (int i = 1; i < cArray.length; i++) {
334
		for (int i = 1; i < cArray.length; i++) {
335
			char c = cArray[i];
335
			char c = cArray[i];
336
			//add more interested index beyond upper case letter
336
			//add more interested index beyond upper case letter
337
			if (c >= 65 && c <= 90) {
337
			if (c >= 65 && c <= 90) {
338
				al.add(i);
338
				al.add(i);
339
			}
339
			}
340
		}
340
		}
341
	 
341
	 
342
		Vector<String> strl = new Vector<String>();
342
		Vector<String> strl = new Vector<String>();
343
	 
343
	 
344
		// this handles the all lower letter case
344
		// this handles the all lower letter case
345
		if (al.size() == 1) {
345
		if (al.size() == 1) {
346
			strl.add(s);
346
			strl.add(s);
347
			return depilerChaineListee(strl, " ");
347
			return depilerChaineListee(strl, " ");
348
		}
348
		}
349
	 
349
	 
350
	 
350
	 
351
		int prev = 0;
351
		int prev = 0;
352
		int curr = 0;
352
		int curr = 0;
353
		int begin = 0;
353
		int begin = 0;
354
		for (int k = 1; k < al.size(); k++) {
354
		for (int k = 1; k < al.size(); k++) {
355
	 
355
	 
356
			curr = al.get(k);
356
			curr = al.get(k);
357
	 
357
	 
358
			if(curr == s.length() - 1){
358
			if(curr == s.length() - 1){
359
	 
359
	 
360
			}
360
			}
361
	 
361
	 
362
			if (curr == prev + 1 && curr != s.length() - 1) {
362
			if (curr == prev + 1 && curr != s.length() - 1) {
363
				prev = curr;
363
				prev = curr;
364
			} else if(curr == prev + 1 &&  curr == s.length() - 1){
364
			} else if(curr == prev + 1 &&  curr == s.length() - 1){
365
				strl.add(s.substring(begin, curr+1));
365
				strl.add(s.substring(begin, curr+1));
366
			}else {
366
			}else {
367
	 
367
	 
368
				strl.add(s.substring(prev, curr));
368
				strl.add(s.substring(prev, curr));
369
				prev = curr;
369
				prev = curr;
370
				begin = curr;
370
				begin = curr;
371
				if (k == al.size() - 1) {
371
				if (k == al.size() - 1) {
372
					strl.add(s.substring(curr, s.length()));
372
					strl.add(s.substring(curr, s.length()));
373
				}
373
				}
374
			}
374
			}
375
		}
375
		}
376
	 
376
	 
377
		return depilerChaineListee(strl, " ");
377
		return depilerChaineListee(strl, " ");
378
	}
378
	}
379
	
379
	
380
	private static String depilerChaineListee(Vector<String> strl, String separateur) {
380
	private static String depilerChaineListee(Vector<String> strl, String separateur) {
381
		String s = "";
381
		String s = "";
382
		for(int i = 0; i < strl.size(); i++) {
382
		for(int i = 0; i < strl.size(); i++) {
383
			s += strl.get(i);
383
			s += strl.get(i);
384
			if(i != strl.size() - 1) {
384
			if(i != strl.size() - 1) {
385
				s += separateur;
385
				s += separateur;
386
			}
386
			}
387
		}
387
		}
388
		return s;
388
		return s;
389
	}
389
	}
390
	
390
	
391
	public static Map<String, ChampEtendu> trierListeChampsEtendus(Map<String, ChampEtendu> listeChampsEtendus) {
391
	public static Map<String, ChampEtendu> trierListeChampsEtendus(Map<String, ChampEtendu> listeChampsEtendus) {
392
		List<String> tmp = new ArrayList<String>(listeChampsEtendus.keySet());
392
		List<String> tmp = new ArrayList<String>(listeChampsEtendus.keySet());
393
		Collections.sort(tmp, new Comparator<String>() {
393
		Collections.sort(tmp, new Comparator<String>() {
394
			 
394
			 
395
		    @Override
395
		    @Override
396
		    public int compare(String arg0, String arg1) {
396
		    public int compare(String arg0, String arg1) {
397
		        return arg0.compareTo(arg1);
397
		        return arg0.compareTo(arg1);
398
		    }
398
		    }
399
		 
399
		 
400
		});
400
		});
401
		return listeChampsEtendus;
401
		return listeChampsEtendus;
402
	}
402
	}
-
 
403
	
-
 
404
	/**
-
 
405
	 * Solution issue de stackoverflow : 
-
 
406
	 * http://stackoverflow.com/questions/1143951/what-is-the-simplest-way-to-convert-a-java-string-from-all-caps-words-separated
-
 
407
	 */
-
 
408
	public static String convertirEnChaMot(String s) {	
-
 
409
		s = s.replaceAll("_", " ");
-
 
410
		s = s.replaceAll("-", " ");
-
 
411
		String[] parties = s.split(" ");
-
 
412
		String chaineChaMot = "";
-
 
413
		for (String partie : parties){
-
 
414
			chaineChaMot = chaineChaMot + convertirMotEnChaMot(partie);
-
 
415
		}
-
 
416
		return chaineChaMot;
-
 
417
	}
-
 
418
 
-
 
419
	protected static String convertirMotEnChaMot(String s) {
-
 
420
		return s.substring(0, 1).toUpperCase() +
-
 
421
	               s.substring(1).toLowerCase();
-
 
422
	}
403
}
423
}