Subversion Repositories eFlore/Applications.cel

Compare Revisions

Ignore whitespace Rev 1571 → Rev 1572

/trunk/src/org/tela_botanica/client/util/Util.java
4,9 → 4,11
import java.util.Iterator;
import java.util.Map;
 
import org.tela_botanica.client.modeles.objets.ChampEtendu;
import org.tela_botanica.client.modeles.objets.Observation;
 
import com.google.gwt.http.client.URL;
import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONString;
 
19,28 → 21,45
return jsonNonNull(jo, index) ? ((JSONString)jo.get(index)).stringValue() : "";
}
public static Map<String, String> getMapValeursOuVide(JSONObject jo, String index) {
Map<String, String> mapValeurs = new HashMap<String, String>();
if(jo.get(index) != null && jo.get(index).isObject() != null) {
JSONObject mapJo = jo.get(index).isObject();
for (Iterator<String> it = mapJo.keySet().iterator(); it.hasNext();) {
String cle = it.next();
mapValeurs.put(cle, mapJo.get(cle).isString().stringValue());
public static Map<String, ChampEtendu> getMapValeursOuVide(JSONObject jo, String index) {
Map<String, ChampEtendu> mapValeurs = new HashMap<String, ChampEtendu>();
if(jo.get(index) != null && jo.get(index).isArray() != null) {
JSONArray tabJo = jo.get(index).isArray();
for (int i = 0; i < tabJo.size(); i++) {
JSONObject champJson = tabJo.get(i).isObject();
String cle = champJson.get("cle").isString().stringValue();
String label = champJson.get("label").isString().stringValue();
String valeur = champJson.get("valeur").isString().stringValue();
ChampEtendu champ = new ChampEtendu(cle, label, valeur);
mapValeurs.put(cle, champ);
}
 
}
return mapValeurs;
}
public static String convertirMapEnChaineRequete(Map<String, String> map, String cleUrl) {
String chaineChamps = "";
for (Iterator<String> it = map.keySet().iterator(); it.hasNext();) {
String cle = it.next();
String valeur = map.get(cle);
chaineChamps += URL.encode(cleUrl+"["+cle+"]")+"="+URL.encode(valeur)+"&";
}
return chaineChamps;
public static String convertirChampsEtendusEnChaineRequete(Map<String, ChampEtendu> map) {
String json = "";
if (map != null && !map.isEmpty()) {
JSONArray jsonArr = new JSONArray();
int i = 0;
for (Map.Entry<String, ChampEtendu> entry: map.entrySet()) {
jsonArr.set(i, convertirChampEtenduEnJson(entry.getValue()));
i++;
}
json = jsonArr.toString();
}
return json;
}
public static JSONObject convertirChampEtenduEnJson(ChampEtendu champEtendu) {
JSONObject jsonObj = new JSONObject();
jsonObj.put("cle", new JSONString(champEtendu.getCle()));
jsonObj.put("label", new JSONString(champEtendu.getLabel()));
jsonObj.put("valeur", new JSONString(champEtendu.getValeur()));
return jsonObj;
}
public static boolean jsonNonNull(JSONObject jo, String index) {
return (jo != null &&
jo.get(index) != null &&
264,4 → 283,20
return dateRemplacee;
}
public static boolean estZero(String s) {
boolean estZero = false;
try {
Double dou = Double.parseDouble(s);
estZero = (dou == 0);
} catch(NumberFormatException e) {
 
}
return estZero;
}
public static String formaterNombre(String s) {
s = s.indexOf(".") < 0 ? s : s.replaceAll("0*$", "").replaceAll("\\.$", "");
return s;
}
}