Subversion Repositories eFlore/Applications.del

Rev

Rev 2067 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1062 benjamin 1
package org.tela_botanica.del.client.utils;
2
 
2050 aurelien 3
import org.tela_botanica.del.client.i18n.I18n;
4
 
1833 aurelien 5
import com.google.gwt.i18n.client.NumberFormat;
2067 aurelien 6
import com.google.gwt.user.client.Window;
1833 aurelien 7
 
1062 benjamin 8
public class StringUtils {
9
 
10
	public static boolean checkStringNotNull(String s){
11
		if(s!=null&&!s.equals("")){
12
			return true;
13
		}
14
		return false;
15
	}
1165 aurelien 16
 
17
	public static String normaliser(String mot) {
18
 
19
		mot = mot.toLowerCase().trim().replace(" ", "");
20
 
21
		// Le manque de support des librairies standard java
22
		// nous oblige à utiliser cette méthode un peu batarde
23
		char[] accents = {'à','á','â','ã','ä','ç','è','é','ê','ë','ì','í','î','ï','ñ','ò','ó','ô','õ','ö','ù','ú','û','ü','ý','ÿ','À','Á','Â','Ã','Ä','Ç','È','É','Ê','Ë', 'Ì','Í','Î','Ï','Ñ','Ò','Ó','Ô','Õ','Ö','Ù','Ú','Û','Ü','Ý'};
24
		char[] sansAccents = {'a','a','a','a','a','c', 'e','e','e','e','i','i','i','i','n','o','o','o','o','o','u','u','u','u', 'y','y','A','A','A','A','A','C','E','E','E','E','I','I','I','I','N','O','O','O','O','O','U','U','U','U','Y'};
25
 
26
		for (int i = 0; i < accents.length; i++) {
27
			mot = mot.replace(accents[i], sansAccents[i]);
28
		}
29
 
30
		return mot;
31
	}
1517 aurelien 32
 
1953 aurelien 33
	public static native void logVersConsole(Object o) /*-{
1517 aurelien 34
		if(!!($wnd.console && $wnd.console.log)) {
1953 aurelien 35
			$wnd.console.log(o);
1517 aurelien 36
		}
37
	}-*/;
1833 aurelien 38
 
39
	public static String formaterNombre(double valeur, int decimales) {
40
	    StringBuilder patternNb = new StringBuilder(
41
	            (decimales <= 0) ? "" : ".");
42
	    for (int i = 0; i < decimales; i++) {
43
	    	patternNb.append('0');
44
	    }
45
 
46
	    if(valeur == 0) {
47
	    	patternNb.insert(0, 0);
48
	    }
49
 
50
	    return NumberFormat.getFormat(patternNb.toString()).format(valeur);
51
	}
2050 aurelien 52
 
2067 aurelien 53
	public static String getCorrespondanceChaineEvenementObs(String evenement) {
2050 aurelien 54
		String trad = "";
55
 
56
		// Arghhhh pourquoi on ne peut pas faire de switch sur une string !!!!!!
57
		// arggh arrrghghhhhhh
58
		if(evenement.equals("nouveau_vote")) {
2067 aurelien 59
			trad = I18n.getVocabulary().nouveauVote();
2050 aurelien 60
		}
61
 
62
		if(evenement.equals("nouveau_commentaire")) {
2067 aurelien 63
			trad = I18n.getVocabulary().nouveauCommentaire();
2050 aurelien 64
		}
65
 
66
		if(evenement.equals("nouvelle_observation")) {
67
			trad = I18n.getVocabulary().nouvelleObservation();
68
		}
69
 
70
		if(evenement.equals("nouveau_commentaire_vous_a_obs_autre")) {
71
			trad = I18n.getVocabulary().nouveauCommentaireVousAObsAutre();
72
		}
73
 
74
		if(evenement.equals("nouveau_commentaire_autre_sur_obs_vous")) {
75
			trad = I18n.getVocabulary().nouveauCommentaireAutreSurObsVous();
76
		}
77
 
78
		if(evenement.equals("nouvelle_proposition_vous_a_obs_autre")) {
79
			trad = I18n.getVocabulary().nouvellePropositionVousAObsAutre();
80
		}
81
 
82
		if(evenement.equals("nouvelle_proposition_autre_sur_obs_vous")) {
83
			trad = I18n.getVocabulary().nouvellePropositionAutreSurObsVous();
84
		}
85
 
86
		if(evenement.equals("nouveau_vote_vous_a_com_autre")) {
87
			trad = I18n.getVocabulary().nouveauVoteVousAComAutre();
88
		}
89
 
90
		if(evenement.equals("nouveau_vote_autre_sur_com_vous")) {
91
			trad = I18n.getVocabulary().nouveauVoteAutreSurComVous();
92
		}
93
 
94
		if(evenement.equals("nouvelle_validation_vous_a_prop_autre")) {
95
			trad = I18n.getVocabulary().nouvelleValidationVousAPropAutre();
96
		}
97
 
98
		if(evenement.equals("nouvelle_validation_autre_sur_prop_vous")) {
99
			trad = I18n.getVocabulary().nouvelleValidationAutreAPropVous();
100
		}
101
 
2056 aurelien 102
		if(evenement.equals("nouveau_vote_autre_sur_com_autre_obs_vous")) {
103
			trad = I18n.getVocabulary().nouveauVoteAutreSurComAutreObsVous();
104
		}
105
 
2064 aurelien 106
		if(evenement.equals("nouvelle_reponse_autre_sur_commentaire_vous")) {
107
			trad = I18n.getVocabulary().nouvelleReponseAutreSurCommentaireVous();
108
		}
109
 
110
		if(evenement.equals("nouvelle_reponse_autre_sur_proposition_vous")) {
111
			trad = I18n.getVocabulary().nouvelleReponseAutreSurPropositionVous();
112
		}
113
 
2050 aurelien 114
		return trad;
115
	}
2067 aurelien 116
 
117
	public static String getClasseEvenementObs(String evenement) {
118
		String classeEvt = "";
119
		if(evenement.equals("nouveau_commentaire_vous_a_obs_autre") ||
120
		evenement.equals("nouveau_commentaire_autre_sur_obs_vous") ||
121
		evenement.equals("nouvelle_reponse_autre_sur_commentaire_vous") ||
122
		evenement.equals("nouvelle_reponse_autre_sur_proposition_vous")) {
123
			classeEvt = "evtObsCitation";
124
		} else {
125
			classeEvt = "evtObsAction";
126
		}
127
		return classeEvt;
128
	}
129
 
130
	/**
131
	 * Puts ellipses in input strings that are longer than than maxCharacters. Shorter strings or
132
	 * null is returned unchanged.
133
	 * @param input the input string that may be subjected to shortening
134
	 * @param maxCharacters the maximum characters that are acceptable for the unshortended string. Must be at least 3, otherwise a string with ellipses is too long already.
135
	 * @param the number of characters that should appear after the ellipsis (0 or larger)
136
	 */
137
	public static String ellipsize(String input, int maxCharacters, int charactersAfterEllipsis) {
138
	  if (input == null || input.length() < maxCharacters) {
139
	    return input;
140
	  }
141
	  return input.substring(0, maxCharacters - 3 - charactersAfterEllipsis) + "..." + input.substring(input.length() - charactersAfterEllipsis);
142
	}
1062 benjamin 143
}