Subversion Repositories eFlore/Applications.cel

Rev

Rev 2657 | 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) {
183
		return chaineLocaliteComplete.replaceAll(" \\([a-zA-Z0-9]*\\)", "");
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
 
1572 aurelien 300
	public static String formaterNombre(String s) {
301
		s = s.indexOf(".") < 0 ? s : s.replaceAll("0*$", "").replaceAll("\\.$", "");
302
		return s;
303
	}
2276 mathias 304
 
305
	// Prend un nombre décimal avec le spéparateur spécifié et le tronque à n décimales
306
	public static String tronquerNombrePourAffichage(String nombre, int decimales, char separateur) {
307
		String retour = nombre;
308
		int posSep = nombre.indexOf(separateur);
309
		if (posSep >= 0) {
310
			int taille = posSep + decimales + 1;
311
			if (nombre.length() < taille) {
312
				taille = nombre.length();
313
			}
314
			retour = nombre.substring(0, taille);
315
		}
316
		return retour;
317
	}
318
 
319
	public static String tronquerNombrePourAffichage(String nombre, int decimales) {
320
		return tronquerNombrePourAffichage(nombre, decimales, '.');
321
	}
2392 aurelien 322
 
323
	// Adapté de http://www.programcreek.com/2011/03/java-method-for-spliting-a-camelcase-string/
324
	public static String formaterCleChampsEtenduPourAffichage(String s) {
325
		char[] cArray = s.toCharArray();
326
 
327
		Vector<Integer> al = new Vector<Integer>();
328
		al.add(0);
329
 
330
		// get all upper case letter index positions
331
		for (int i = 1; i < cArray.length; i++) {
332
			char c = cArray[i];
333
			//add more interested index beyond upper case letter
334
			if (c >= 65 && c <= 90) {
335
				al.add(i);
336
			}
337
		}
338
 
339
		Vector<String> strl = new Vector<String>();
340
 
341
		// this handles the all lower letter case
342
		if (al.size() == 1) {
343
			strl.add(s);
344
			return depilerChaineListee(strl, " ");
345
		}
346
 
347
 
348
		int prev = 0;
349
		int curr = 0;
350
		int begin = 0;
351
		for (int k = 1; k < al.size(); k++) {
352
 
353
			curr = al.get(k);
354
 
355
			if(curr == s.length() - 1){
356
 
357
			}
358
 
359
			if (curr == prev + 1 && curr != s.length() - 1) {
360
				prev = curr;
361
			} else if(curr == prev + 1 &&  curr == s.length() - 1){
362
				strl.add(s.substring(begin, curr+1));
363
			}else {
364
 
365
				strl.add(s.substring(prev, curr));
366
				prev = curr;
367
				begin = curr;
368
				if (k == al.size() - 1) {
369
					strl.add(s.substring(curr, s.length()));
370
				}
371
			}
372
		}
373
 
374
		return depilerChaineListee(strl, " ");
375
	}
376
 
377
	private static String depilerChaineListee(Vector<String> strl, String separateur) {
378
		String s = "";
379
		for(int i = 0; i < strl.size(); i++) {
380
			s += strl.get(i);
381
			if(i != strl.size() - 1) {
382
				s += separateur;
383
			}
384
		}
385
		return s;
386
	}
387
 
388
	public static Map<String, ChampEtendu> trierListeChampsEtendus(Map<String, ChampEtendu> listeChampsEtendus) {
389
		List<String> tmp = new ArrayList<String>(listeChampsEtendus.keySet());
390
		Collections.sort(tmp, new Comparator<String>() {
391
 
392
		    @Override
393
		    public int compare(String arg0, String arg1) {
394
		        return arg0.compareTo(arg1);
395
		    }
396
 
397
		});
398
		return listeChampsEtendus;
399
	}
2401 aurelien 400
 
401
	/**
402
	 * Solution issue de stackoverflow :
403
	 * http://stackoverflow.com/questions/1143951/what-is-the-simplest-way-to-convert-a-java-string-from-all-caps-words-separated
404
	 */
405
	public static String convertirEnChaMot(String s) {
406
		s = s.replaceAll("_", " ");
407
		s = s.replaceAll("-", " ");
408
		String[] parties = s.split(" ");
409
		String chaineChaMot = "";
410
		for (String partie : parties){
411
			chaineChaMot = chaineChaMot + convertirMotEnChaMot(partie);
412
		}
413
		return chaineChaMot;
414
	}
415
 
416
	protected static String convertirMotEnChaMot(String s) {
417
		return s.substring(0, 1).toUpperCase() +
418
	               s.substring(1).toLowerCase();
419
	}
2553 mathias 420
 
421
	public static void curseurAttente() {
422
	    RootPanel.getBodyElement().getStyle().setProperty("cursor", "wait");
423
	}
424
 
425
	public static void curseurParDefaut() {
426
		RootPanel.getBodyElement().getStyle().setProperty("cursor", "default");
427
	}
2602 aurelien 428
 
429
	public static Map<String, String> parserRetourReferentielPerso(Response response) {
430
		final Map<String, String> referentielData = new HashMap<String, String>();
431
		final JSONValue responseValue = JSONParser.parse(response.getText());
432
 
433
		JSONArray reponse = null;
434
 
435
		// si c'est un tableau
436
		if ((reponse = responseValue.isArray()) != null) {
437
 
438
			JSONString elementsRef;
439
			final int taillemax = reponse.size();
440
 
441
			for (int i = 0; i < taillemax; i++) {
442
				if ((elementsRef = reponse.get(i).isString()) != null) {
443
 
444
					String valeur = elementsRef.stringValue();
445
					referentielData.put(i+"", valeur);
446
 
447
				}
448
			}
449
		}
450
		return referentielData;
451
	}
2606 aurelien 452
 
453
	public static Map<String, ReferentielNom> parserRetourReferentielNomIndexeParNom(Response response) {
454
 
455
		final Map<String, ReferentielNom> referentielNomData ;
456
		final JSONValue responseValue = JSONParser.parse(response.getText());
457
		JSONArray reponse=null;
458
 
459
		// si c'est un tableau
460
		if ((reponse=responseValue.isArray()) != null) {
461
 
462
			JSONArray noms;
463
			final int taillemax = reponse.size();
464
 
465
			referentielNomData = new HashMap<String, ReferentielNom>(taillemax);
466
			for (int i = 0; i < taillemax; i++) {
467
				if ((noms=reponse.get(i).isArray()) != null) {
468
					String nom = ((JSONString) noms.get(0)).stringValue();
469
					String numeroNom = ((JSONString) noms.get(1)).stringValue();
470
					String statut= ((JSONString) noms.get(2)).stringValue();
471
					ReferentielNom nomScientifique = new ReferentielNom(nom, numeroNom, statut);
472
					// FIXME : et si le numero de nom n'est pas unique ? (cas de multirefrentiel....)
473
					referentielNomData.put(nomScientifique.getNom(),nomScientifique);
474
				}
475
			}
476
		} else {
477
			referentielNomData = new HashMap<String, ReferentielNom>(0);
478
		}
479
		return referentielNomData;
480
	}
481
 
482
	public static Map<String, String> convertirListeReferentielNomVersMap(Map<String, ReferentielNom> referentielNom) {
483
		Map<String, String> nomMap = new HashMap<String, String>();
484
		for (Iterator<String> it  = referentielNom.keySet().iterator(); it.hasNext();) {
485
			String cle = it.next();
486
			nomMap.put(cle, referentielNom.get(cle).getNom());
487
		}
488
		return nomMap;
489
	}
490
 
491
	public static Map<String, ReferentielLocalite> parserRetourReferentielLocaliteIndexeParNom(Response response) {
492
 
493
		final Map<String, ReferentielLocalite> referentielLocaliteData;
494
		final JSONValue responseValue = JSONParser.parse(response.getText());
495
		JSONArray reponse = null;
496
 
497
		// si c'est un tableau
498
		if ((reponse = responseValue.isArray()) != null) {
499
 
500
			JSONArray localites;
501
			final int taillemax = reponse.size();
502
 
503
			referentielLocaliteData = new HashMap<String, ReferentielLocalite>(taillemax);
504
 
505
			for (int i = 0; i < taillemax; i++) {
506
				if ((localites = reponse.get(i).isArray()) != null) {
507
					String localite = ((JSONString) localites.get(0)).stringValue();
508
					String codeLocalite  = ((JSONString) localites.get(1)).stringValue();
509
					ReferentielLocalite com = new ReferentielLocalite(localite, codeLocalite);
510
					referentielLocaliteData.put(com.getLocalite() + com.getCodeLocalite(), com);
511
				}
512
			}
513
		} else {
514
			referentielLocaliteData = new HashMap<String, ReferentielLocalite>(0);
515
		}
516
		return referentielLocaliteData;
517
	}
518
 
519
	public static Map<String, String> convertirListeReferentielLocaliteVersMap(Map<String, ReferentielLocalite> referentielLocalite) {
520
		Map<String, String> locMap = new HashMap<String, String>();
521
		for (Iterator<String> it  = referentielLocalite.keySet().iterator(); it.hasNext();) {
522
			String cle = it.next();
523
			locMap.put(cle, referentielLocalite.get(cle).getLocalite());
524
		}
525
		return locMap;
526
	}
2657 aurelien 527
 
528
	public static Map<String, String> parserRetourImportObs(String json) {
529
		final JSONValue responseValue = JSONParser.parse(json);
530
		JSONObject reponse = null;
531
 
532
		Map<String, String> retourImport = new HashMap<String,String>();
533
		// si c'est un objet
534
		if ((reponse = responseValue.isObject()) != null) {
535
			Iterator<String> it = reponse.keySet().iterator();
536
 
537
			while(it.hasNext()) {
538
				String cle = it.next();
539
				String valeur = reponse.get(cle).isString().stringValue();
540
				retourImport.put(cle, valeur);
541
			}
542
		}
543
 
544
		return retourImport;
545
	}
2668 aurelien 546
 
547
	public static void envoyerRequeteStatsUpload(final Callback<String, String> cb) {
548
		RequestBuilderWithCredentials rb = new RequestBuilderWithCredentials(RequestBuilderWithCredentials.GET,Configuration.getServiceBaseUrl()
549
				+"/ImportXLS") ;
550
		try {
551
			rb.sendRequest(null, new RequestCallback() {
2650 aurelien 552
 
2668 aurelien 553
				@Override
554
				public void onError(Request request, Throwable exception) {
555
					// TODO Auto-generated method stub
556
				}
557
 
558
				@Override
559
				public void onResponseReceived(Request request,
560
						Response response) {
561
					cb.onSuccess(response.getText());
562
				}
563
			}) ;
564
 
565
		} catch (RequestException e) {
566
			// TODO Auto-generated catch block
567
			e.printStackTrace();
568
		}
569
	}
570
 
2650 aurelien 571
	public static native void  LogVersFirebug(Object o) /*-{
572
		if (!!($wnd.console && $wnd.console.log)) {
573
			console.log(o);
574
		}
575
	}-*/;
576
 
577
	public static String buildStackTrace(Throwable t, String log) {
578
	    if (t != null) {
579
		     log += t.getClass().toString();
580
		     log += t.getMessage();
581
		     //
582
		     StackTraceElement[] stackTrace = t.getStackTrace();
583
		     if (stackTrace != null) {
584
		    	 StringBuffer trace = new StringBuffer();
585
 
586
			     for (int i = 0; i < stackTrace.length; i++) {
587
			    	 trace.append(stackTrace[i].getClassName() + "." + stackTrace[i].getMethodName() + "("
588
			    			 + stackTrace[i].getFileName() + ":" + stackTrace[i].getLineNumber());
589
			     }
590
 
591
			     log += trace.toString();
592
		     }
593
		     //
594
		     Throwable cause = t.getCause();
595
		     if (cause != null && cause != t) {
596
		    	 log += buildStackTrace(cause, "CausedBy:\n");
597
		     }
598
	    }
599
	    return log;
600
	}
2653 aurelien 601
 
602
	public static String obtenirCodeLangueSysteme() {
603
		String langueSystemeBrute = obtenirLangueSysteme();
604
		// le navigateur peut éventuellement renvoyer une chaine de la forme
605
		// en-us ou fr-fr par exemple
606
		String[] lngTab = langueSystemeBrute.split("-");
607
		return (lngTab.length > 0) ? lngTab[0] : null;
608
	}
609
 
610
	public static native String obtenirLangueSysteme()  /*-{
611
		lang = "";
612
		if (!!($wnd.navigator && $wnd.navigator.language)) {
613
			lang = window.navigator.language;
614
		}
615
		return lang;
616
	}-*/;
2 aperonnet 617
}