Subversion Repositories eFlore/Applications.cel

Rev

Rev 2737 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
734 aurelien 1
package org.tela_botanica.client.util;
2 aperonnet 2
 
2558 aurelien 3
import java.text.NumberFormat;
4
import java.text.ParsePosition;
2392 aurelien 5
import java.util.ArrayList;
6
import java.util.Collections;
7
import java.util.Comparator;
1542 aurelien 8
import java.util.HashMap;
2606 aurelien 9
import java.util.Iterator;
2392 aurelien 10
import java.util.List;
1542 aurelien 11
import java.util.Map;
2392 aurelien 12
import java.util.Vector;
1542 aurelien 13
 
2626 aurelien 14
import org.tela_botanica.client.i18n.Msg;
1572 aurelien 15
import org.tela_botanica.client.modeles.objets.ChampEtendu;
2668 aurelien 16
import org.tela_botanica.client.modeles.objets.Configuration;
989 aurelien 17
import org.tela_botanica.client.modeles.objets.Observation;
2606 aurelien 18
import org.tela_botanica.client.modeles.objets.ReferentielLocalite;
19
import org.tela_botanica.client.modeles.objets.ReferentielNom;
642 aurelien 20
 
2668 aurelien 21
import com.google.gwt.core.client.Callback;
22
import com.google.gwt.http.client.Request;
23
import com.google.gwt.http.client.RequestCallback;
24
import com.google.gwt.http.client.RequestException;
2602 aurelien 25
import com.google.gwt.http.client.Response;
1572 aurelien 26
import com.google.gwt.json.client.JSONArray;
1282 aurelien 27
import com.google.gwt.json.client.JSONObject;
2602 aurelien 28
import com.google.gwt.json.client.JSONParser;
1282 aurelien 29
import com.google.gwt.json.client.JSONString;
2602 aurelien 30
import com.google.gwt.json.client.JSONValue;
2553 mathias 31
import com.google.gwt.user.client.ui.RootPanel;
1282 aurelien 32
 
2 aperonnet 33
public class Util {
34
 
35
	public Util() {
36
	}
642 aurelien 37
 
1282 aurelien 38
	public static String getValeurJsonOuVide(JSONObject jo, String index) {
39
		return jsonNonNull(jo, index) ? ((JSONString)jo.get(index)).stringValue() : "";
40
	}
41
 
1572 aurelien 42
	public static Map<String, ChampEtendu> getMapValeursOuVide(JSONObject jo, String index) {
43
		Map<String, ChampEtendu> mapValeurs = new HashMap<String, ChampEtendu>();
44
		if(jo.get(index) != null && jo.get(index).isArray() != null) {
45
			JSONArray tabJo = jo.get(index).isArray();
46
			for (int i = 0; i < tabJo.size(); i++) {
47
				JSONObject champJson = tabJo.get(i).isObject();
48
				String cle = champJson.get("cle").isString().stringValue();
2392 aurelien 49
				String label = cle;
1572 aurelien 50
				String valeur = champJson.get("valeur").isString().stringValue();
51
				ChampEtendu champ = new ChampEtendu(cle, label, valeur);
52
				mapValeurs.put(cle, champ);
1542 aurelien 53
			}
1572 aurelien 54
 
1542 aurelien 55
		}
56
		return mapValeurs;
57
	}
58
 
1572 aurelien 59
	public static String convertirChampsEtendusEnChaineRequete(Map<String, ChampEtendu> map) {
60
		String json = "";
61
	    if (map != null && !map.isEmpty()) {
62
	    	JSONArray jsonArr = new JSONArray();
63
	    	int i = 0;
64
	        for (Map.Entry<String, ChampEtendu> entry: map.entrySet()) {
65
	        	jsonArr.set(i, convertirChampEtenduEnJson(entry.getValue()));
66
	        	i++;
67
	        }
68
	        json = jsonArr.toString();
69
	    }
70
	    return json;
1549 aurelien 71
	}
72
 
1572 aurelien 73
	public static JSONObject convertirChampEtenduEnJson(ChampEtendu champEtendu) {
74
		JSONObject jsonObj = new JSONObject();
75
		jsonObj.put("cle", new JSONString(champEtendu.getCle()));
76
		jsonObj.put("label", new JSONString(champEtendu.getLabel()));
77
		jsonObj.put("valeur", new JSONString(champEtendu.getValeur()));
78
        return jsonObj;
79
	}
80
 
1282 aurelien 81
	public static boolean jsonNonNull(JSONObject jo, String index) {
82
		return (jo != null &&
83
				jo.get(index) != null &&
84
				jo.get(index).isNull() == null
85
			   );
86
	}
87
 
642 aurelien 88
	public static String formaterLieu(Observation obs, String modeleLieu) {
89
 
90
		String lieuModele = modeleLieu;
91
 
2568 aurelien 92
		String localite = obs.getLocalite();
642 aurelien 93
		String lieuDit = obs.getLieudit();
94
		String station = obs.getStation();
95
 
2568 aurelien 96
		String lieulocaliteFormate = "";
642 aurelien 97
		String lieuDitFormate = "";
98
		String stationFormatee = "";
99
 
2568 aurelien 100
		if(localite != null && !localite.contains("000null") && !localite.trim().equals("")) {
642 aurelien 101
			String	idLoc =obs.getIdentifiantLocalite().replaceAll(" ","/");
102
			if(idLoc != null && !idLoc.contains("000null") && !idLoc.trim().equals("")) {
103
 
104
				idLoc = idLoc.replaceAll("%","");
105
				idLoc = idLoc.replaceAll("\"","");
106
				idLoc = idLoc.replace('\\',' ');
107
				idLoc = idLoc.trim();
1332 aurelien 108
				if(idLoc.length() > 2) {
109
					idLoc = idLoc.substring(0,2);
110
				}
2568 aurelien 111
				lieulocaliteFormate += idLoc+" - ";
642 aurelien 112
			}
2568 aurelien 113
			lieulocaliteFormate += localite;
114
			lieuModele = lieuModele.replaceAll("IDLOCLOCALITE", lieulocaliteFormate);
642 aurelien 115
		} else {
116
 
2568 aurelien 117
			lieuModele = lieuModele.replaceAll("IDLOCLOCALITE,", lieulocaliteFormate);
642 aurelien 118
		}
119
 
120
		if(lieuDit != null && !lieuDit.contains("000null") && !lieuDit.trim().equals("")) {
121
			lieuDitFormate += lieuDit;
122
			lieuModele = lieuModele.replaceAll("LIEUDIT", lieuDitFormate);
123
		} else {
124
			lieuModele = lieuModele.replaceAll("LIEUDIT,", lieuDitFormate);
125
		}
126
 
127
		if(station != null && !station.contains("000null") && !station.trim().equals("")) {
128
			stationFormatee += station;
129
			lieuModele = lieuModele.replaceAll("STATION", stationFormatee);
130
		} else {
131
			lieuModele = lieuModele.replaceAll("STATION", stationFormatee);
132
		}
133
 
134
		lieuModele = lieuModele.trim();
135
		lieuModele = lieuModele.replaceAll(",$","");
136
		lieuModele = lieuModele.replaceAll(",^$",", ");
137
 
138
		return lieuModele;
139
	}
140
 
2568 aurelien 141
	public static String obtenirIdLocAPartirChaineLocalite(String localite) {
1542 aurelien 142
 
2558 aurelien 143
		String idLoc = "";
2568 aurelien 144
		String[] depCom = localite.split(" ");
2558 aurelien 145
		if(depCom.length > 1) {
146
			idLoc = depCom[1].replace('(', ' ');
1542 aurelien 147
		} else {
2558 aurelien 148
			idLoc = "";
1542 aurelien 149
		}
150
 
2558 aurelien 151
		idLoc = idLoc.replace(')', ' ');
152
		idLoc = idLoc.trim();
153
		idLoc = idLoc.replace('\\',' ');
154
		idLoc = idLoc.trim();
1542 aurelien 155
 
2558 aurelien 156
		return idLoc;
157
	}
158
 
159
	public static String formaterDepartement(String depAFormater) {
160
		String dep = "";
1542 aurelien 161
		try
162
		{
2558 aurelien 163
			int nDep = Integer.parseInt(depAFormater);
1542 aurelien 164
			if(nDep > 0 && nDep < 110) {
2558 aurelien 165
				dep = depAFormater ;
1542 aurelien 166
			}
167
 
2558 aurelien 168
			if(depAFormater.length() == 4) {
169
				dep = "0"+depAFormater;
1542 aurelien 170
			}
171
 
2558 aurelien 172
			dep = depAFormater.substring(0,2);
1542 aurelien 173
		}
174
		catch(NumberFormatException e)
175
		{
2558 aurelien 176
			// rien à faire
1542 aurelien 177
		}
178
 
2558 aurelien 179
		return dep;
1542 aurelien 180
	}
181
 
2558 aurelien 182
	public static String supprimerChaineIdLocalite(String chaineLocaliteComplete) {
2693 aurelien 183
		return chaineLocaliteComplete.replaceAll(" \\([a-zA-Z0-9]*\\)", "").trim();
642 aurelien 184
	}
673 aurelien 185
 
962 aurelien 186
	public static String convertirChaineZoneGeoVersDepartement(String chaineZoneGeo) {
1672 aurelien 187
		return (!chaineZoneGeo.equals("000null") && !chaineZoneGeo.equals("") && chaineZoneGeo.replaceAll("INSEE-C:", "").length() >= 2) ?
188
						chaineZoneGeo.replaceAll("INSEE-C:", "").substring(0, 2) :
189
						chaineZoneGeo;
962 aurelien 190
	}
191
 
192
	public static String convertirChaineZoneGeoVersCodeInsee(String chaineZoneGeo) {
193
		return (!chaineZoneGeo.equals("000null") && !chaineZoneGeo.equals("")) ? chaineZoneGeo.replaceAll("INSEE-C:", ""): chaineZoneGeo;
194
	}
195
 
673 aurelien 196
	/***
197
	 * Fusionne les éléments d'un tableau en une chaîne
198
	 * @param delim : la chaîne de séparation
199
	 * @param args : la tableau
200
	 * @return la chaîne fusionnée
201
	 */
202
	public static String implode(String delim, String[] args){
203
		StringBuffer sb = new StringBuffer();
204
 
205
		int lgArgs = args.length;
206
 
207
		for(int i = 0; i < lgArgs; i++){
208
			if (i > 0) {
209
				sb.append(delim);
210
			}
211
 
212
			sb.append(args[i]);
213
		}
214
 
215
		return sb.toString();
216
	}
217
 
218
	public static boolean filtreValide(String[] filtre) {
219
 
220
		return (filtre.length == 2 &&
221
		filtre[0] != null &&
222
		!filtre[0].equals("") &&
223
		filtre[1] != null &&
224
		!filtre[1].equals(""));
225
	}
226
 
227
	public static String renvoyerMois(int numMois) {
228
 
2626 aurelien 229
		if(numMois >= 1 && numMois <= 12) {
230
			return Msg.get("mois-"+numMois);
231
		} else {
232
			return Msg.get("mois-inconnu") ;
673 aurelien 233
		}
234
	}
235
 
236
	public static String remplacerSautsDeligneMalEncodes(String chaineAvecSautsDeLignesMalEncodes) {
237
 
238
		String chaineAvecSautsDeLignesBienEncodes = chaineAvecSautsDeLignesMalEncodes.replace('\\','%');
239
		chaineAvecSautsDeLignesBienEncodes = chaineAvecSautsDeLignesBienEncodes.replaceAll("%n","%");
240
		chaineAvecSautsDeLignesBienEncodes = chaineAvecSautsDeLignesBienEncodes.replace('%','\n');
241
 
242
		return chaineAvecSautsDeLignesBienEncodes;
243
	}
244
 
245
	public static boolean verifierDateFormatCel(String dateAVerifier) {
246
 
247
		String dateRemplacee = remplacerSeparateursDateFormatCel(dateAVerifier);
248
		String[] tabDate = dateRemplacee.split("/");
249
 
250
		boolean retour = false;
251
 
252
		if(tabDate.length == 3) {
1282 aurelien 253
			//TODO: faire un parsing de date qui fonctionne mieux car
254
			// on peut saisir un 31 novembre par exemple
255
			// mais l'api date de java est mal gérée par gwt
673 aurelien 256
			try {
257
				int jour = Integer.parseInt(tabDate[0]);
258
				int mois = Integer.parseInt(tabDate[1]);
259
				int annee = Integer.parseInt(tabDate[2]);
260
 
1010 aurelien 261
				if(jour <= 31 && mois <= 12 && tabDate[2].length() == 4) {
673 aurelien 262
					retour = true;
263
				}
264
			} catch (Exception e) {
265
 
266
			}
267
		}
268
 
269
		return retour;
270
	}
271
 
272
	public static String remplacerSeparateursDateFormatCel(String date) {
273
 
274
		String dateRemplacee = date.replaceAll("-", "/");
275
 
276
	    return dateRemplacee;
277
	}
1572 aurelien 278
 
279
	public static boolean estZero(String s) {
280
		boolean estZero = false;
281
	    try {
282
	    	Double dou = Double.parseDouble(s);
283
	    	estZero = (dou == 0);
284
	    } catch(NumberFormatException e) {
285
 
286
	    }
287
	    return estZero;
288
	}
289
 
2558 aurelien 290
	public static boolean estUnNombre(String s) {
291
		//http://stackoverflow.com/questions/1102891/how-to-check-if-a-string-is-a-numeric-type-in-java
292
		try {
293
			double d = Double.parseDouble(s);
294
		} catch(NumberFormatException nfe) {
295
			return false;
296
		}
297
		return true;
298
	}
299
 
2693 aurelien 300
	public static boolean estLaCorse(String s) {
301
		// Les générations futures d'informaticiens me jugeront
302
		// (et éventuellement géreront mieux le cas de la Corse que je ne l'ai fait)
303
		return s.toUpperCase().equals("2A") || s.toUpperCase().equals("2B");
304
	}
305
 
306
	public static boolean estUnDepartement(String s) {
307
		return estUnNombre(s) || estLaCorse(s);
308
	}
309
 
1572 aurelien 310
	public static String formaterNombre(String s) {
311
		s = s.indexOf(".") < 0 ? s : s.replaceAll("0*$", "").replaceAll("\\.$", "");
312
		return s;
313
	}
2276 mathias 314
 
315
	// Prend un nombre décimal avec le spéparateur spécifié et le tronque à n décimales
316
	public static String tronquerNombrePourAffichage(String nombre, int decimales, char separateur) {
317
		String retour = nombre;
318
		int posSep = nombre.indexOf(separateur);
319
		if (posSep >= 0) {
320
			int taille = posSep + decimales + 1;
321
			if (nombre.length() < taille) {
322
				taille = nombre.length();
323
			}
324
			retour = nombre.substring(0, taille);
325
		}
326
		return retour;
327
	}
328
 
329
	public static String tronquerNombrePourAffichage(String nombre, int decimales) {
330
		return tronquerNombrePourAffichage(nombre, decimales, '.');
331
	}
2392 aurelien 332
 
333
	// Adapté de http://www.programcreek.com/2011/03/java-method-for-spliting-a-camelcase-string/
334
	public static String formaterCleChampsEtenduPourAffichage(String s) {
335
		char[] cArray = s.toCharArray();
336
 
337
		Vector<Integer> al = new Vector<Integer>();
338
		al.add(0);
339
 
340
		// get all upper case letter index positions
341
		for (int i = 1; i < cArray.length; i++) {
342
			char c = cArray[i];
343
			//add more interested index beyond upper case letter
344
			if (c >= 65 && c <= 90) {
345
				al.add(i);
346
			}
347
		}
348
 
349
		Vector<String> strl = new Vector<String>();
350
 
351
		// this handles the all lower letter case
352
		if (al.size() == 1) {
353
			strl.add(s);
354
			return depilerChaineListee(strl, " ");
355
		}
356
 
357
 
358
		int prev = 0;
359
		int curr = 0;
360
		int begin = 0;
361
		for (int k = 1; k < al.size(); k++) {
362
 
363
			curr = al.get(k);
364
 
365
			if(curr == s.length() - 1){
366
 
367
			}
368
 
369
			if (curr == prev + 1 && curr != s.length() - 1) {
370
				prev = curr;
371
			} else if(curr == prev + 1 &&  curr == s.length() - 1){
372
				strl.add(s.substring(begin, curr+1));
373
			}else {
374
 
375
				strl.add(s.substring(prev, curr));
376
				prev = curr;
377
				begin = curr;
378
				if (k == al.size() - 1) {
379
					strl.add(s.substring(curr, s.length()));
380
				}
381
			}
382
		}
383
 
384
		return depilerChaineListee(strl, " ");
385
	}
386
 
387
	private static String depilerChaineListee(Vector<String> strl, String separateur) {
388
		String s = "";
389
		for(int i = 0; i < strl.size(); i++) {
390
			s += strl.get(i);
391
			if(i != strl.size() - 1) {
392
				s += separateur;
393
			}
394
		}
395
		return s;
396
	}
397
 
398
	public static Map<String, ChampEtendu> trierListeChampsEtendus(Map<String, ChampEtendu> listeChampsEtendus) {
399
		List<String> tmp = new ArrayList<String>(listeChampsEtendus.keySet());
400
		Collections.sort(tmp, new Comparator<String>() {
401
 
402
		    @Override
403
		    public int compare(String arg0, String arg1) {
404
		        return arg0.compareTo(arg1);
405
		    }
406
 
407
		});
408
		return listeChampsEtendus;
409
	}
2401 aurelien 410
 
411
	/**
412
	 * Solution issue de stackoverflow :
413
	 * http://stackoverflow.com/questions/1143951/what-is-the-simplest-way-to-convert-a-java-string-from-all-caps-words-separated
414
	 */
415
	public static String convertirEnChaMot(String s) {
416
		s = s.replaceAll("_", " ");
417
		s = s.replaceAll("-", " ");
418
		String[] parties = s.split(" ");
419
		String chaineChaMot = "";
420
		for (String partie : parties){
421
			chaineChaMot = chaineChaMot + convertirMotEnChaMot(partie);
422
		}
423
		return chaineChaMot;
424
	}
425
 
426
	protected static String convertirMotEnChaMot(String s) {
2693 aurelien 427
		// MiaOu
2401 aurelien 428
		return s.substring(0, 1).toUpperCase() +
429
	               s.substring(1).toLowerCase();
430
	}
2553 mathias 431
 
432
	public static void curseurAttente() {
433
	    RootPanel.getBodyElement().getStyle().setProperty("cursor", "wait");
434
	}
435
 
436
	public static void curseurParDefaut() {
437
		RootPanel.getBodyElement().getStyle().setProperty("cursor", "default");
438
	}
2602 aurelien 439
 
440
	public static Map<String, String> parserRetourReferentielPerso(Response response) {
441
		final Map<String, String> referentielData = new HashMap<String, String>();
442
		final JSONValue responseValue = JSONParser.parse(response.getText());
443
 
444
		JSONArray reponse = null;
445
 
446
		// si c'est un tableau
447
		if ((reponse = responseValue.isArray()) != null) {
448
 
449
			JSONString elementsRef;
450
			final int taillemax = reponse.size();
451
 
452
			for (int i = 0; i < taillemax; i++) {
453
				if ((elementsRef = reponse.get(i).isString()) != null) {
454
 
455
					String valeur = elementsRef.stringValue();
456
					referentielData.put(i+"", valeur);
457
 
458
				}
459
			}
460
		}
461
		return referentielData;
462
	}
2606 aurelien 463
 
464
	public static Map<String, ReferentielNom> parserRetourReferentielNomIndexeParNom(Response response) {
465
 
466
		final Map<String, ReferentielNom> referentielNomData ;
467
		final JSONValue responseValue = JSONParser.parse(response.getText());
468
		JSONArray reponse=null;
469
 
470
		// si c'est un tableau
471
		if ((reponse=responseValue.isArray()) != null) {
472
 
473
			JSONArray noms;
474
			final int taillemax = reponse.size();
475
 
476
			referentielNomData = new HashMap<String, ReferentielNom>(taillemax);
477
			for (int i = 0; i < taillemax; i++) {
478
				if ((noms=reponse.get(i).isArray()) != null) {
479
					String nom = ((JSONString) noms.get(0)).stringValue();
480
					String numeroNom = ((JSONString) noms.get(1)).stringValue();
481
					String statut= ((JSONString) noms.get(2)).stringValue();
482
					ReferentielNom nomScientifique = new ReferentielNom(nom, numeroNom, statut);
2737 aurelien 483
					// FIXME : et si le numero de nom n'est pas unique ? (cas de multirefrentiel....)
484
					referentielNomData.put(nomScientifique.getNom(),nomScientifique);
2606 aurelien 485
				}
486
			}
487
		} else {
488
			referentielNomData = new HashMap<String, ReferentielNom>(0);
489
		}
490
		return referentielNomData;
491
	}
492
 
493
	public static Map<String, String> convertirListeReferentielNomVersMap(Map<String, ReferentielNom> referentielNom) {
494
		Map<String, String> nomMap = new HashMap<String, String>();
495
		for (Iterator<String> it  = referentielNom.keySet().iterator(); it.hasNext();) {
496
			String cle = it.next();
497
			nomMap.put(cle, referentielNom.get(cle).getNom());
498
		}
499
		return nomMap;
500
	}
501
 
502
	public static Map<String, ReferentielLocalite> parserRetourReferentielLocaliteIndexeParNom(Response response) {
503
 
504
		final Map<String, ReferentielLocalite> referentielLocaliteData;
505
		final JSONValue responseValue = JSONParser.parse(response.getText());
506
		JSONArray reponse = null;
507
 
508
		// si c'est un tableau
509
		if ((reponse = responseValue.isArray()) != null) {
510
 
511
			JSONArray localites;
512
			final int taillemax = reponse.size();
513
 
514
			referentielLocaliteData = new HashMap<String, ReferentielLocalite>(taillemax);
515
 
516
			for (int i = 0; i < taillemax; i++) {
517
				if ((localites = reponse.get(i).isArray()) != null) {
518
					String localite = ((JSONString) localites.get(0)).stringValue();
519
					String codeLocalite  = ((JSONString) localites.get(1)).stringValue();
2693 aurelien 520
					ReferentielLocalite com = new ReferentielLocalite(localite, codeLocalite);
521
					referentielLocaliteData.put(com.getLocalite(), com);
2606 aurelien 522
				}
523
			}
524
		} else {
525
			referentielLocaliteData = new HashMap<String, ReferentielLocalite>(0);
526
		}
527
		return referentielLocaliteData;
528
	}
529
 
530
	public static Map<String, String> convertirListeReferentielLocaliteVersMap(Map<String, ReferentielLocalite> referentielLocalite) {
531
		Map<String, String> locMap = new HashMap<String, String>();
532
		for (Iterator<String> it  = referentielLocalite.keySet().iterator(); it.hasNext();) {
533
			String cle = it.next();
534
			locMap.put(cle, referentielLocalite.get(cle).getLocalite());
535
		}
536
		return locMap;
537
	}
2657 aurelien 538
 
539
	public static Map<String, String> parserRetourImportObs(String json) {
540
		final JSONValue responseValue = JSONParser.parse(json);
541
		JSONObject reponse = null;
542
 
543
		Map<String, String> retourImport = new HashMap<String,String>();
544
		// si c'est un objet
545
		if ((reponse = responseValue.isObject()) != null) {
546
			Iterator<String> it = reponse.keySet().iterator();
547
 
548
			while(it.hasNext()) {
549
				String cle = it.next();
550
				String valeur = reponse.get(cle).isString().stringValue();
551
				retourImport.put(cle, valeur);
552
			}
553
		}
554
 
555
		return retourImport;
556
	}
2668 aurelien 557
 
558
	public static void envoyerRequeteStatsUpload(final Callback<String, String> cb) {
559
		RequestBuilderWithCredentials rb = new RequestBuilderWithCredentials(RequestBuilderWithCredentials.GET,Configuration.getServiceBaseUrl()
560
				+"/ImportXLS") ;
561
		try {
562
			rb.sendRequest(null, new RequestCallback() {
2650 aurelien 563
 
2668 aurelien 564
				@Override
565
				public void onError(Request request, Throwable exception) {
566
					// TODO Auto-generated method stub
567
				}
568
 
569
				@Override
570
				public void onResponseReceived(Request request,
571
						Response response) {
572
					cb.onSuccess(response.getText());
573
				}
574
			}) ;
575
 
576
		} catch (RequestException e) {
577
			// TODO Auto-generated catch block
578
			e.printStackTrace();
579
		}
580
	}
581
 
2650 aurelien 582
	public static native void  LogVersFirebug(Object o) /*-{
583
		if (!!($wnd.console && $wnd.console.log)) {
584
			console.log(o);
585
		}
586
	}-*/;
587
 
588
	public static String buildStackTrace(Throwable t, String log) {
589
	    if (t != null) {
590
		     log += t.getClass().toString();
591
		     log += t.getMessage();
592
		     //
593
		     StackTraceElement[] stackTrace = t.getStackTrace();
594
		     if (stackTrace != null) {
595
		    	 StringBuffer trace = new StringBuffer();
596
 
597
			     for (int i = 0; i < stackTrace.length; i++) {
598
			    	 trace.append(stackTrace[i].getClassName() + "." + stackTrace[i].getMethodName() + "("
599
			    			 + stackTrace[i].getFileName() + ":" + stackTrace[i].getLineNumber());
600
			     }
601
 
602
			     log += trace.toString();
603
		     }
604
		     //
605
		     Throwable cause = t.getCause();
606
		     if (cause != null && cause != t) {
607
		    	 log += buildStackTrace(cause, "CausedBy:\n");
608
		     }
609
	    }
610
	    return log;
611
	}
2653 aurelien 612
 
613
	public static String obtenirCodeLangueSysteme() {
614
		String langueSystemeBrute = obtenirLangueSysteme();
615
		// le navigateur peut éventuellement renvoyer une chaine de la forme
616
		// en-us ou fr-fr par exemple
617
		String[] lngTab = langueSystemeBrute.split("-");
618
		return (lngTab.length > 0) ? lngTab[0] : null;
619
	}
620
 
621
	public static native String obtenirLangueSysteme()  /*-{
622
		lang = "";
623
		if (!!($wnd.navigator && $wnd.navigator.language)) {
624
			lang = window.navigator.language;
625
		}
626
		return lang;
627
	}-*/;
2806 aurelien 628
 
629
	public static native String utf8ToB64(String str) /*-{
630
		return window.btoa(unescape(encodeURIComponent( str )));
631
	}-*/;
632
 
633
	public static native String b64ToUtf8(String str) /*-{
634
		return decodeURIComponent(escape(window.atob( str )));
635
	}-*/;
2 aperonnet 636
}