Subversion Repositories eFlore/Applications.coel

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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