Subversion Repositories eFlore/Applications.coel

Rev

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

Rev 965 Rev 975
1
package org.tela_botanica.client.util;
1
package org.tela_botanica.client.util;
2
 
2
 
3
import java.util.Date;
3
import java.util.Date;
4
 
4
 
5
import com.google.gwt.i18n.client.DateTimeFormat;
5
import com.google.gwt.i18n.client.DateTimeFormat;
6
 
6
 
7
public class UtilString {
7
public class UtilString {
8
	
8
	
9
	/**
9
	/**
10
	 *  Mets la première lettre d'une chaine en majuscule
10
	 *  Mets la première lettre d'une chaine en majuscule
11
	 *  
11
	 *  
12
	 *  @param chaineDeCaractere
12
	 *  @param chaineDeCaractere
13
	 *  @result ChaineDeCaractere
13
	 *  @result ChaineDeCaractere
14
	 */
14
	 */
15
	
-
 
16
	public static String ucFirst(String inputStr)	{
15
	public static String ucFirst(String inputStr)	{
17
		if (isEmpty(inputStr))	{
16
		if (isEmpty(inputStr))	{
18
			return "";
17
			return "";
19
		}
18
		}
20
		return inputStr.substring(0,1).toUpperCase() + inputStr.substring(1, inputStr.length());
19
		return inputStr.substring(0,1).toUpperCase() + inputStr.substring(1, inputStr.length());
21
	}
20
	}
22
	
21
	
23
	public static boolean isEmpty(String chaine)	{
22
	public static boolean isEmpty(String chaine)	{
24
		boolean etreVide = false;
23
		boolean etreVide = false;
25
		if (chaine == null || chaine.equals("") || chaine.equals("0000-00-00") || chaine.equals("0000-00-00 00:00:00")) {
24
		if (chaine == null || chaine.equals("") || chaine.equals("0000-00-00") || chaine.equals("0000-00-00 00:00:00")) {
26
			etreVide = true;
25
			etreVide = true;
27
		}
26
		}
28
		return etreVide;
27
		return etreVide;
29
	}
28
	}
30
	
29
	
31
	public static double formaterEnDouble(String nombre)	{
30
	public static double formaterEnDouble(String nombre)	{
32
		if (!isEmpty(nombre)) {
31
		if (!isEmpty(nombre)) {
33
			return Double.parseDouble(nombre);
32
			return Double.parseDouble(nombre);
34
		}
33
		}
35
		return new Double(0);
34
		return new Double(0);
36
	}
35
	}
37
	
36
	
38
	public static int formaterEnEntier(String nombre)	{
37
	public static int formaterEnEntier(String nombre)	{
39
		if (!isEmpty(nombre)) {
38
		if (!isEmpty(nombre)) {
40
			return Integer.parseInt(nombre);
39
			return Integer.parseInt(nombre);
41
		}
40
		}
42
		return new Integer(0);
41
		return new Integer(0);
43
	}
42
	}
44
	
43
	
45
	public static Date formaterEnDate(String dateChaine)	{
44
	public static Date formaterEnDate(String dateChaine)	{
46
		Date date = null;
45
		Date date = null;
-
 
46
		if (!isEmpty(dateChaine)) {
47
		if (!isEmpty(dateChaine) && !dateChaine.equals("0000-00-00")) {
47
			if (dateChaine.matches("^[0-9]{4}-00-00$")) {
-
 
48
				dateChaine = dateChaine.replaceFirst("^([0-9]{4})-00-00$", "$1-01-01");
-
 
49
			} else if (dateChaine.matches("^[0-9]{4}-[0-9]{2}-00$")) {
-
 
50
				dateChaine = dateChaine.replaceFirst("^([0-9]{4})-([0-9]{2})-00$", "$1-$2-01");
-
 
51
			}
48
			date = DateTimeFormat.getFormat("yyyy-MM-dd").parseStrict(dateChaine);
52
			date = UtilDate.formatDateMysql.parseStrict(dateChaine);
49
		}
53
		}
50
		return date;
54
		return date;
51
	}
55
	}
52
}
56
}