/branches/v1.8-narince/src/org/tela_botanica/client/util/UtilDate.java |
---|
New file |
0,0 → 1,27 |
package org.tela_botanica.client.util; |
import java.util.Date; |
import com.google.gwt.i18n.client.DateTimeFormat; |
public class UtilDate { |
public final static DateTimeFormat formatDateMysql = DateTimeFormat.getFormat("yyyy-MM-dd"); |
public final static DateTimeFormat formatDateFr = DateTimeFormat.getFormat("dd/MM/yyyy"); |
public static String formaterEnString(Date date) { |
String dateChaine = "0000-00-00"; |
if (date != null) { |
dateChaine = formatDateMysql.format(date); |
} |
return dateChaine; |
} |
public static String formaterEnStringFormatFr(Date date) { |
String dateChaine = "0000-00-00"; |
if (date != null) { |
dateChaine = formatDateFr.format(date); |
} |
return dateChaine; |
} |
} |
/branches/v1.8-narince/src/org/tela_botanica/client/util/Print.java |
---|
New file |
0,0 → 1,69 |
package org.tela_botanica.client.util; |
import com.google.gwt.user.client.Element; |
import com.google.gwt.user.client.ui.UIObject; |
/** |
* <pre> |
* Generic printing class |
* can be used to print the Window it self, DOM.Elements, UIObjects (Widgets) and plain HTML |
* |
* Usage: |
* You must insert this iframe in your host page: |
* <iframe id="__printingFrame" style="width:0;height:0;border:0"></iframe> |
* |
* Window: |
* Print.it(); |
* |
* Objects/HTML: |
* Print.it(RootPanel.get("myId")); |
* Print.it(DOM.getElementById("myId")); |
* Print.it("Just <b>Print.it()</b>!"); |
* |
* Objects/HTML using styles: |
* Print.it("<link rel='StyleSheet' type='text/css' media='paper' href='/paperStyle.css'>", RootPanel.get('myId')); |
* Print.it("<style type='text/css' media='paper'> .newPage {page-break-after: always; } </style>","Hi<p class='newPage'></p>By"); |
* </pre> |
*/ |
public class Print { |
public static native void it() /*-{ |
$wnd.print(); |
}-*/; |
public static native void it(String html) /*-{ |
var frame = $doc.getElementById('__printingFrame'); |
if (!frame) { |
$wnd.alert("Error: Can't find printing frame."); |
return; |
} |
frame = frame.contentWindow; |
var doc = frame.document; |
doc.open(); |
doc.write(html); |
doc.close(); |
frame.focus(); |
frame.print(); |
}-*/; |
public static void it(UIObject obj) { |
it("", obj.getElement().toString()); |
} |
public static void it(Element element) { |
it("", element.toString()); |
} |
public static void it(String style, String it) { |
it("<it><header>"+style+"</header><body>"+it+"</body></it>"); |
} |
public static void it(String style, UIObject obj) { |
it(style, obj.getElement().toString()); |
} |
public static void it(String style, Element element) { |
it(style, element.toString()); |
} |
} |
/branches/v1.8-narince/src/org/tela_botanica/client/util/UtilArray.java |
---|
New file |
0,0 → 1,20 |
package org.tela_botanica.client.util; |
public class UtilArray { |
/** |
* @see http://leghumped.com/blog/2007/12/20/in_array-and-implode-for-java/ |
* @param ary |
* @param delim |
* @return |
*/ |
public static String implode(String[] ary, String delim) { |
String out = ""; |
for (int i = 0; i < ary.length; i++) { |
if (i != 0) { out += delim; } |
out += ary[i]; |
} |
return out; |
} |
} |
/branches/v1.8-narince/src/org/tela_botanica/client/util/Pattern.java |
---|
New file |
0,0 → 1,46 |
package org.tela_botanica.client.util; |
public class Pattern { |
public static final String url = "^(?:(?:ht|f)tp(?:s?)\\:\\/\\/|~/|/)?"+ // Protocol |
"(?:\\w+:\\w+@)?"+ // Username:Password |
"(?:(?:[-\\w]+\\.)+"+ // Subdomains |
"(?:com|org|net|gov|mil|biz|info|mobi|name|aero|jobs|museum|travel|[a-z]{2}))"+ // TopLevel Domains |
"(?::[\\d]{1,5})?"+ // Port |
"(?:(?:(?:/(?:[-\\w~!$+|.,=]|%[a-f\\d]{2})+)+|/)+|\\?|#)?"+ // Directories |
"(?:(?:\\?(?:[-\\w~!$+|.,*:]|%[a-f\\d{2}])+=(?:[-\\w~!$+|.,*:=]|%[a-f\\d]{2})*)(?:&(?:[-\\w~!$+|.,*:]|%[a-f\\d{2}])+=(?:[-\\w~!$+|.,*:=]|%[a-f\\d]{2})*)*)*"+ // Query |
"(?:#(?:[-\\w~!$+|.,*:=]|%[a-f\\d]{2})*)?$"; // Anchor |
public static final String email = "[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*"+ // Identité |
"@"+ // At |
"(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?";// Domaine |
public static final String heureMinute = "^(?:[0-1][0-9]|2[0-4])"+ // Heure au format 24h |
":"+ // Séparateur d'heure et minute |
"(?:[0-5][0-9]|60)$"; // Minutes; |
public static final String latitude = "^-?"+ // Nombre positif ou négatif |
"([0-8]?[0-9]([.,][0-9]*)?|90)$"; // Nombre décimal allant de 0 à 89 ou nombre entier valant 90 avec pour séparateur des décimales "." ou "," |
public static final String longitude = "^-?"+ // Nombre positif ou négatif |
"((1[0-7][0-9]|[1-9]?[0-9])([.,][0-9]*)?|180)$"; // Nombre décimal allant de 0 à 179 ou nombre entier valant 180 avec pour séparateur des décimales "." ou "," |
/** |
* Méthode similaire à la méthode : java.util.Pattern.quote(). |
* java.util.Pattern n'est pas implémenté par GWT. |
* Nous protégeons les caractères spéciaux. |
* |
* @link http://java.developpez.com/faq/java/?page=langage_chaine |
* @param chaine |
* @return |
*/ |
public static String quote(String chaine) { |
chaine.replace("\\", "\\\\"); |
String[] caracteresSpeciaux = {".", "$", "[", "]", "(", ")", "{", "}", "^", "?", "*", "+", "-", "|"}; |
for (int i = 0; i < caracteresSpeciaux.length; i++) { |
chaine = chaine.replace(caracteresSpeciaux[i], "\\"+caracteresSpeciaux[i]); |
} |
return chaine; |
} |
} |
/branches/v1.8-narince/src/org/tela_botanica/client/util/UtilNombre.java |
---|
New file |
0,0 → 1,11 |
package org.tela_botanica.client.util; |
import com.google.gwt.i18n.client.NumberFormat; |
public class UtilNombre { |
public static String formaterEnEntier(double nombre) { |
NumberFormat formatNbreEntier = NumberFormat.getFormat("#"); |
return formatNbreEntier.format(nombre); |
} |
} |
/branches/v1.8-narince/src/org/tela_botanica/client/util/Log.java |
---|
New file |
0,0 → 1,103 |
package org.tela_botanica.client.util; |
import java.util.logging.Level; |
import java.util.logging.Logger; |
/** |
* Classe gérant les los et le deboguage. |
* Est une abstraction de la bibliothèque java.util.logging. |
* Niveau de log : |
* SEVERE (le plus haut) |
* WARNING |
* INFO |
* CONFIG |
* FINE |
* FINER |
* FINEST (le moins haut) |
*/ |
public class Log { |
/** |
* Modifie le niveau de sortie du déboguage. |
* @param message |
*/ |
public static void setNiveau(String niveau) { |
Logger.getLogger("").setLevel(Level.parse(niveau)); |
String message = "Nouveau niveau de Log : "+getNiveau(); |
Logger.getLogger("").log(Level.ALL , message); |
} |
/** |
* Modifie le niveau de sortie du déboguage. |
* @param message |
*/ |
public static String getNiveau() { |
return Logger.getLogger("").getLevel().toString(); |
} |
/** |
* À utiliser pour les messages d'erreur causant une erreur fatale. |
* @param message |
*/ |
public static void fatal(String message) { |
Logger.getLogger("").log(Level.SEVERE , message); |
} |
/** |
* À utiliser pour les messages d'erreur ne causant pas d'erreur fatale. |
* @param message |
*/ |
public static void error(String message) { |
Logger.getLogger("").log(Level.SEVERE , message); |
} |
/** |
* À utiliser pour les messages d'avertissement ne causant pas d'erreur fatale. |
* @param message |
*/ |
public static void warn(String message) { |
Logger.getLogger("").log(Level.WARNING , message); |
} |
/** |
* À utiliser pour les messages d'avertissement ne causant pas d'erreur fatale. |
* @param message |
* @param exception |
*/ |
public static void warn(String message, Throwable exception) { |
Logger.getLogger("").log(Level.WARNING , message, exception); |
} |
/** |
* À utiliser pour les messages d'information qui ne sont pas des erreurs. |
* @param message |
*/ |
public static void info(String message) { |
Logger.getLogger("").log(Level.INFO , message); |
} |
/** |
* À utiliser pour les messages de déboguage. |
* @param message |
*/ |
public static void debug(String message) { |
Logger.getLogger("").log(Level.FINE , message); |
} |
/** |
* À utiliser pour les messages de trace normale. |
* @param message |
*/ |
public static void trace(String message) { |
Logger.getLogger("").log(Level.FINER , message); |
} |
/** |
* À utiliser pour les messages de trace le plus complet. |
* @param message |
*/ |
public static void traceFine(String message) { |
Logger.getLogger("").log(Level.FINEST , message); |
} |
} |
/branches/v1.8-narince/src/org/tela_botanica/client/util/UtilDAO.java |
---|
New file |
0,0 → 1,103 |
package org.tela_botanica.client.util; |
import java.util.HashMap; |
import java.util.Iterator; |
import org.tela_botanica.client.RegistreId; |
import org.tela_botanica.client.configuration.Configuration; |
import org.tela_botanica.client.http.JsonRestRequestBuilder; |
import com.extjs.gxt.ui.client.Registry; |
import com.google.gwt.http.client.URL; |
/** |
* @author Gréguoire DUCHÉ <greguoire@tela-botanica.org> |
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org> |
* @description La classe utilDAO fournit des méthodes communes pour les outils DAO |
* */ |
public class UtilDAO { |
private static String baseUrl = ((Configuration) Registry.get(RegistreId.CONFIG)).getServiceBaseUrl(); |
public static final String GET = "GET"; |
public static final String POST = "POST"; |
public static final String DELETE = "DELETE"; |
public static final String PUT = "PUT"; |
private static final String SEPARATEUR_CHEMIN = "/"; |
private static final String SEPARATEUR_CLE_VALEUR = "="; |
private static final String SEPARATEUR_PARAMETRE = "&"; |
private static final String SEPARATEUR_CHEMIN_PARAMETRE = "?"; |
private static final String CONTENU_CHEMIN_VIDE = "*"; |
public static JsonRestRequestBuilder construireRequetePost(String nomService) { |
return construireRequete(nomService, null, null, POST); |
} |
public static JsonRestRequestBuilder construireRequetePost(String nomService, String[] parametres) { |
return construireRequete(nomService, parametres, null, POST); |
} |
public static JsonRestRequestBuilder construireRequete(String nomService) { |
return construireRequete(nomService, null, null, GET); |
} |
public static JsonRestRequestBuilder construireRequete(String nomService, String[] parametres) { |
return construireRequete(nomService, parametres, null, GET); |
} |
public static JsonRestRequestBuilder construireRequete(String nomService, HashMap<String, String> restrictions) { |
return construireRequete(nomService, null, restrictions, GET); |
} |
public static JsonRestRequestBuilder construireRequete(String nomService, String[] parametres, HashMap<String, String> restrictions) { |
return construireRequete(nomService, parametres, restrictions, GET); |
} |
private static JsonRestRequestBuilder construireRequete(String nomService, String[] parametres, HashMap<String, String> restrictions, String typeRequete) { |
String restrictionsUrl = construireUrlParametres(restrictions); |
String parametresUrl = construireUrlChemin(parametres); |
String urlComplete = baseUrl + nomService + parametresUrl + restrictionsUrl; |
String urlCompleteEncodee = URL.encode(urlComplete); |
JsonRestRequestBuilder jrrb; |
if (typeRequete.equals(GET)) { |
jrrb = new JsonRestRequestBuilder(JsonRestRequestBuilder.GET, urlCompleteEncodee); |
} else { |
jrrb = new JsonRestRequestBuilder(JsonRestRequestBuilder.POST, urlCompleteEncodee); |
} |
return jrrb; |
} |
private static String construireUrlParametres(HashMap<String, String> parametres) { |
String parametresUrl = ""; |
if (parametres != null && parametres.size() > 0) { |
parametresUrl = SEPARATEUR_CHEMIN_PARAMETRE; |
Iterator<String> iterateur = parametres.keySet().iterator(); |
while (iterateur.hasNext()) { |
String cle = iterateur.next(); |
parametresUrl += cle + SEPARATEUR_CLE_VALEUR + parametres.get(cle); |
if (iterateur.hasNext()) { |
parametresUrl = parametresUrl + SEPARATEUR_PARAMETRE; |
} |
} |
} |
return parametresUrl; |
} |
private static String construireUrlChemin(String[] morceauxDuChemin) { |
String cheminUrl = ""; |
if (morceauxDuChemin != null && morceauxDuChemin.length > 0) { |
cheminUrl = SEPARATEUR_CHEMIN; |
for (int i = 0; i < morceauxDuChemin.length; i++) { |
cheminUrl += (UtilString.isEmpty(morceauxDuChemin[i]) ? CONTENU_CHEMIN_VIDE : morceauxDuChemin[i]) + SEPARATEUR_CHEMIN; |
} |
} |
return cheminUrl; |
} |
public static String getUrlService(String nomService) { |
return baseUrl + nomService; |
} |
} |
/branches/v1.8-narince/src/org/tela_botanica/client/util/UtilTruk.java |
---|
New file |
0,0 → 1,34 |
package org.tela_botanica.client.util; |
import java.util.Iterator; |
import java.util.LinkedList; |
public class UtilTruk { |
/** |
* Traite une liste récupéré de truk et renvoie une chaîne de caractère formatée |
* |
* @param la liste truk |
* @param le séparateur pour chaque valeur |
* */ |
public static String traiterTrukListe(LinkedList<String> listTruk, String separateur) { |
String listeRetour = ""; |
Iterator<String> it = listTruk.iterator(); |
while (it.hasNext()) { |
String valeurCourante = it.next(); |
listeRetour += valeurCourante; |
if (it.hasNext()) { |
listeRetour += separateur; |
} |
} |
return listeRetour; |
} |
} |
/branches/v1.8-narince/src/org/tela_botanica/client/util/UtilString.java |
---|
New file |
0,0 → 1,66 |
package org.tela_botanica.client.util; |
import java.util.ArrayList; |
import java.util.Date; |
import com.google.gwt.i18n.client.DateTimeFormat; |
public class UtilString { |
/** |
* Mets la première lettre d'une chaine en majuscule |
* |
* @param chaineDeCaractere |
* @result ChaineDeCaractere |
*/ |
public static String ucFirst(String inputStr) { |
if (isEmpty(inputStr)) { |
return ""; |
} |
return inputStr.substring(0,1).toUpperCase() + inputStr.substring(1, inputStr.length()); |
} |
public static boolean isEmpty(String chaine) { |
boolean etreVide = false; |
if (chaine == null || chaine.equals("") || chaine.equals("0000-00-00") || chaine.equals("0000-00-00 00:00:00")) { |
etreVide = true; |
} |
return etreVide; |
} |
public static double formaterEnDouble(String nombre) { |
if (!isEmpty(nombre)) { |
return Double.parseDouble(nombre); |
} |
return new Double(0); |
} |
public static int formaterEnEntier(String nombre) { |
if (!isEmpty(nombre)) { |
return Integer.parseInt(nombre); |
} |
return new Integer(0); |
} |
public static Date formaterEnDate(String dateChaine) { |
Date date = null; |
if (!isEmpty(dateChaine)) { |
if (dateChaine.matches("^[0-9]{4}-00-00$")) { |
dateChaine = dateChaine.replaceFirst("^([0-9]{4})-00-00$", "$1-01-01"); |
} else if (dateChaine.matches("^[0-9]{4}-[0-9]{2}-00$")) { |
dateChaine = dateChaine.replaceFirst("^([0-9]{4})-([0-9]{2})-00$", "$1-$2-01"); |
} |
date = UtilDate.formatDateMysql.parseStrict(dateChaine); |
} |
return date; |
} |
public static boolean isEmpty(ArrayList<String> entree) { |
return !(entree!=null && !entree.toString().equals("[]")); |
} |
public static boolean isNumber(String str, boolean emptyIsTrue) { |
if (emptyIsTrue) return (str.matches("[0-9]*")); |
else return (str.matches("[0-9]+")); |
} |
} |
/branches/v1.8-narince/src/org/tela_botanica/client/util/Debug.java |
---|
New file |
0,0 → 1,28 |
package org.tela_botanica.client.util; |
import com.google.gwt.core.client.GWT; |
import com.google.gwt.user.client.Window; |
public class Debug { |
@Deprecated |
public static void log(String texte) { |
GWT.log(texte, null); |
} |
public static String getStackTraceAsString(int depth) { |
// a décommenter lors de l'utilisation car ne fonctionne qu'en mode |
// hosted et pas en mode compilé |
/*StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace(); |
String trace = ""; |
for (int i = 2; i < stackTraceElements.length && i < depth+2; i++) { |
if(i != 2) { |
trace += " < "; |
} |
trace += stackTraceElements[i].getClassName()+"."+stackTraceElements[i].getMethodName(); |
} |
return trace;*/ |
return ""; |
} |
} |
/branches/v1.8-narince/src/org/tela_botanica/client/util/Analytics.java |
---|
New file |
0,0 → 1,37 |
package org.tela_botanica.client.util; |
public class Analytics { |
/** |
* Envoie une notification à Google Analytics, comme quoi la page "url" a été visitée |
* |
* @param url adresse ou surnom de la page visitée |
*/ |
public static native void pageVisitee(String url) /*-{ |
if (url == "") { |
url = $wnd.location.href; |
} |
$wnd.ga('send', 'pageview', url); |
}-*/; |
/** |
* Envoie une notification à Google Analytics, comme quoi l'événement "action" a été déclenché |
* sur la ressource "categorie" |
* |
* @param categorie - la ressource sur laquelle l'utilisateur a agi |
* @param action - ce que l'utilisateur a fait avec cette ressource |
* @param label - un bout de JSON avec des détails |
* @param nombre - nombre d'actions à enregistrer |
*/ |
public static native void evenement(String categorie, String action, String label, int nombre) /*-{ |
$wnd.ga('send', 'event', categorie, action, label, nombre); |
}-*/; |
public static void evenement(String categorie, String action, String label) { |
Analytics.evenement(categorie, action, label, 1); |
} |
public static void evenement(String categorie, String action) { |
Analytics.evenement(categorie, action, "", 1); |
} |
} |
/branches/v1.8-narince/src/org/tela_botanica/client/util/. |
---|
New file |
Property changes: |
Added: svn:mergeinfo |
Merged /branches/v1.6-muscardin/src/org/tela_botanica/client/util:r1816-1817 |
Merged /trunk/src/org/tela_botanica/client/util:r11-147,1209-1382 |
Merged /branches/v1.1-aramon/src/org/tela_botanica/client/util:r1383-1511 |
Merged /branches/v1.0-syrah/src/org/tela_botanica/client/util:r1136-1328 |