Subversion Repositories eFlore/Archives.cel-v2

Rev

Rev 30 | Rev 43 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 30 Rev 36
1
package org.tela_botanica.client.modeles;
1
package org.tela_botanica.client.modeles;
2
 
2
 
3
import java.util.HashMap;
3
import java.util.HashMap;
4
import java.util.Iterator;
4
import java.util.Iterator;
5
import java.util.Set;
5
import java.util.Set;
6
 
6
 
7
import com.google.gwt.json.client.JSONObject;
7
import com.google.gwt.json.client.JSONObject;
8
 
8
 
9
/**
9
/**
10
 * 
10
 * 
11
 * Classe representant une image du carnet,
11
 * Classe representant une image du carnet,
12
 * elle ne contient pas d'image à proprement parler mais
12
 * elle ne contient pas d'image à proprement parler mais
13
 * plutôt les informations associées ainsi que l'url distante 
13
 * plutôt les informations associées ainsi que l'url distante.
-
 
14
 * C'est une table de hachage qui contient des paires propriété/valeur 
14
 * 
15
 * 
15
 */
16
 */
16
public class ImageCarnet extends HashMap {
17
public class ImageCarnet extends HashMap {
17
	
18
	
-
 
19
 
-
 
20
	/**
-
 
21
	 * Constructeur avec un objet JSON
-
 
22
	 * @param image
18
 
23
	 */
19
	public ImageCarnet(JSONObject image)
24
	public ImageCarnet(JSONObject image)
-
 
25
	{	
20
	{	
26
		// l'objet JSON est une table de hachage
-
 
27
		Set im = image.keySet() ;
21
		Set im = image.keySet() ;
28
		
-
 
29
		// on la parcourt pour chaque clé
22
		
30
		for (Iterator iterator = im.iterator(); iterator.hasNext();) {
23
		for (Iterator iterator = im.iterator(); iterator.hasNext();) {
31
			
24
			
32
			// si elle est associée à une valeur, on l'ajoute
25
			String key = (String) iterator.next();
33
			String key = (String) iterator.next();
26
			if(image.get(key).isString() != null)
34
			if(image.get(key).isString() != null)
27
			{
35
			{
28
				String valeur = image.get(key).isString().stringValue() ;
36
				String valeur = image.get(key).isString().stringValue() ;
29
				this.put(key, valeur) ;
37
				this.put(key, valeur) ;
30
			}
38
			}
31
			else
39
			else
32
			{
40
			{
-
 
41
				// sinon on ajoute la clé avec une valeur vide
33
				String valeur = " " ;
42
				String valeur = " " ;
34
				this.put(key, valeur) ;
43
				this.put(key, valeur) ;
35
			}
44
			}
36
			
45
			
37
		}
46
		}
38
 
47
 
39
	}
48
	}
-
 
49
	
-
 
50
	/**
-
 
51
	 * Surcharge de toString qui affiche toutes les propriétés de l'image
40
	
52
	 */
41
	public String toString()
53
	public String toString()
42
	{
54
	{
43
		String valeur = " ";
55
		String valeur = " ";
44
		
56
		
45
		for (Iterator iterator = this.keySet().iterator(); iterator.hasNext();) {
57
		for (Iterator iterator = this.keySet().iterator(); iterator.hasNext();) {
46
			
58
			
47
			
59
			
48
			String key = (String) iterator.next();
60
			String key = (String) iterator.next();
49
			if(this.get(key) != null)
61
			if(this.get(key) != null)
50
			{
62
			{
51
				valeur += "cle : "+key+" valeur :"+(String)this.get(key)+"\n" ;
63
				valeur += "cle : "+key+" valeur :"+(String)this.get(key)+"\n" ;
52
			}
64
			}
53
			
65
			
54
		}
66
		}
55
		
67
		
56
		return valeur ;
68
		return valeur ;
57
	}
69
	}
-
 
70
	
-
 
71
	/**
-
 
72
	 * Pour éviter que l'on traite des valeurs nulles à l'affichage
-
 
73
	 * on passe par cette fonction qui retire les charactères nuls qui font planter
-
 
74
	 * l'affichage, il ne faut pas utiliser get directement 
-
 
75
	 * @param cle
-
 
76
	 * @return la valeur associée à la clé
58
	
77
	 */
59
	public String renvoyerValeurCorrecte(String cle)
78
	public String renvoyerValeurCorrecte(String cle)
60
	{
79
	{
61
		if(this.containsKey((cle)))
80
		if(this.containsKey((cle)))
62
		{
81
		{
63
			String valeur = (String)this.get(cle) ;
82
			String valeur = (String)this.get(cle) ;
64
			if(valeur.equals("null") || valeur == null)
83
			if(valeur.equals("null") || valeur == null)
65
			{
84
			{
66
				return "null" ;
85
				return " " ;
67
			}			
86
			}			
68
			else
87
			else
69
			{
88
			{
70
				char nullChar = '\u0000' ;
89
				char nullChar = '\u0000' ;
71
				String sNull = ""+nullChar ; 
90
				String sNull = ""+nullChar ; 
72
				valeur = valeur.replaceAll(sNull, "") ;
91
				valeur = valeur.replaceAll(sNull, "") ;
73
				return valeur ;
92
				return valeur ;
74
			}
93
			}
75
		}
94
		}
76
		else
95
		else
77
		{
96
		{
78
			return "null" ;
97
			return " " ;
79
		}
98
		}
80
	}
99
	}
-
 
100
 
-
 
101
	/**
-
 
102
	 * Acesseur pour l'id de l'image
-
 
103
	 * @return l'id de l'image
81
 
104
	 */
82
	public String getId() {
105
	public String getId() {
83
		
106
		
84
		return renvoyerValeurCorrecte("ci_id_image") ;
107
		return renvoyerValeurCorrecte("ci_id_image") ;
85
	}
108
	}
-
 
109
	
-
 
110
	/**
-
 
111
	 * Acesseur pour le numero d'ordre de l'image
-
 
112
	 * @return l'ordre de l'image
86
	
113
	 */
87
	public String getOrdre() {
114
	public String getOrdre() {
88
		
115
		
89
		return renvoyerValeurCorrecte("ci_ordre") ;
116
		return renvoyerValeurCorrecte("ci_ordre") ;
90
	}
117
	}
-
 
118
	
-
 
119
	/**
-
 
120
	 * Base de l'url serveur pour les images
-
 
121
	 * @return url racine pour les images
91
	
122
	 */
92
	public String getBaseUrl()
123
	public String getBaseUrl()
93
	{
124
	{
94
		return "http://162.38.234.9/Documents/images_serveur/" ;
125
		return "http://162.38.234.9/Documents/images_serveur/" ;
95
	}
126
	}
-
 
127
 
-
 
128
	/**
-
 
129
	 * Renvoie le chemin et nom du fichier grand format
-
 
130
	 * @return le chemin du fichier grand format
96
 
131
	 */
97
	public String getUrl() {
132
	public String getUrl() {
98
		
133
		
99
		return getBaseUrl()+(String)this.get("ci_id_image")+".jpg" ;
134
		return getBaseUrl()+(String)this.get("ci_id_image")+".jpg" ;
100
	}
135
	}
-
 
136
	
-
 
137
	/**
-
 
138
	 * Renvoie le chemin et nom du fichier petit format
-
 
139
	 * @return le chemin du fichier petit format
101
	
140
	 */
102
	public String getSUrl() {
141
	public String getSUrl() {
103
		
142
		
104
		return getBaseUrl()+(String)this.get("ci_id_image")+"_S.jpg" ;
143
		return getBaseUrl()+(String)this.get("ci_id_image")+"_S.jpg" ;
105
	}
144
	}
-
 
145
	
-
 
146
	/**
-
 
147
	 * Renvoie le chemin et nom du fichier moyen format
-
 
148
	 * @return le chemin du fichier moyen format
106
	
149
	 */
107
	public String getMUrl() {
150
	public String getMUrl() {
108
		
151
		
109
		return getBaseUrl()+(String)this.get("ci_id_image")+"_M.jpg" ;
152
		return getBaseUrl()+(String)this.get("ci_id_image")+"_M.jpg" ;
110
	}
153
	}
-
 
154
	
-
 
155
	/**
-
 
156
	 * Renvoie la taille de l'image
-
 
157
	 * @return un tableau de deux string contenant la hauteur puis la largeur 
-
 
158
	 */
111
	
159
	public String[] getTailleImage()
-
 
160
	{
-
 
161
		String[] XY = { renvoyerValeurCorrecte("ci_meta_height") , renvoyerValeurCorrecte("ci_meta_width") } ;
-
 
162
		return XY ;
112
 
163
	}
-
 
164
	
-
 
165
	/**		
-
 
166
	 * Renvoie la date exif associée à l'image
-
 
167
	 * @return la date associée à l'image
113
 
168
	 */
114
	public String getDate() {
169
	public String getDate() {
115
		
170
		
116
		return renvoyerValeurCorrecte("ci_meta_date_time") ;
171
		return renvoyerValeurCorrecte("ci_meta_date_time") ;
117
	}
172
	}
-
 
173
 
-
 
174
	/**
-
 
175
	 * Renvoie la ville associée à l'image
118
 
176
	 * @return la ville iptc
119
 
177
	 */
120
	public Object getIptcCity() {
178
	public Object getIptcCity() {
121
		
179
		
122
		return renvoyerValeurCorrecte("ci_meta_iptc_city") ;
180
		return renvoyerValeurCorrecte("ci_meta_iptc_city") ;
123
	}
181
	}
-
 
182
 
-
 
183
	/**
-
 
184
	 * Renvoie le fabricant de l'appareil
124
 
185
	 * @return le fabricant
125
 
186
	 */
126
	public String getMake() {
187
	public String getMake() {
127
		
188
		
128
		return renvoyerValeurCorrecte("ci_meta_make") ;
189
		return renvoyerValeurCorrecte("ci_meta_make") ;
129
	}
190
	}
-
 
191
 
-
 
192
	/**
-
 
193
	 * Renvoie le modele de l'appareil
130
 
194
	 * @return le modele
131
 
195
	 */
132
	public String getModel() {
196
	public String getModel() {
133
		
197
		
134
		return renvoyerValeurCorrecte("ci_meta_model") ;
198
		return renvoyerValeurCorrecte("ci_meta_model") ;
135
	}
199
	}
-
 
200
	
-
 
201
	/**
-
 
202
	 * Renvoie un tableau nom / valeur de toutes les metadonnées Iptc
-
 
203
	 * @return les métadonnées iptc
136
	
204
	 */
137
	public String[][] getMetadonnesIptc() {
205
	public String[][] getMetadonnesIptc() {
138
		
206
		
139
		String[][] metaIptc = new String[12][2] ;
207
		String[][] metaIptc = new String[12][2] ;
140
		int elem = 0 ;
208
		int elem = 0 ;
141
		
209
		
142
		for (Iterator it = this.keySet().iterator(); it.hasNext();) 
210
		for (Iterator it = this.keySet().iterator(); it.hasNext();) 
143
		{
211
		{
144
						
212
						
145
			String key = (String)it.next();
213
			String key = (String)it.next();
146
			
214
			
147
				// on filtre le "ci"
215
				// on filtre le "ci"
148
				String type[] = key.split("_",3) ;
216
				String type[] = key.split("_",3) ;
149
				
217
				
150
				
218
				
151
				// si c'est une metadonnee exif ou iptc
219
				// si c'est une metadonnee exif ou iptc
152
				if(type[1].equals("meta"))
220
				if(type[1].equals("meta"))
153
				{
221
				{
154
					String[] genre =  type[2].split("_",2) ;
222
					String[] genre =  type[2].split("_",2) ;
155
					if(genre[0].equals("iptc"))
223
					if(genre[0].equals("iptc"))
156
					{
224
					{
157
						String nom = genre[1] ;
225
						String nom = genre[1] ;
158
						metaIptc[elem][0] = nom ;
226
						metaIptc[elem][0] = nom ;
159
						metaIptc[elem][1] = renvoyerValeurCorrecte(key) ;
227
						metaIptc[elem][1] = renvoyerValeurCorrecte(key) ;
160
						elem++ ;	
228
						elem++ ;	
161
					}
229
					}
162
					
230
					
163
				}	
231
				}	
164
							    	
232
							    	
165
		}
233
		}
166
		
234
		
167
		return metaIptc ;
235
		return metaIptc ;
168
	}
236
	}
-
 
237
	
-
 
238
	/**
-
 
239
	 * Renvoie un tableau nom / valeur de toutes les metadonnées Exif
-
 
240
	 * @return les métadonnées Exif
169
	
241
	 */
170
	public Object[][] getMetadonnesExif() {
242
	public String[][] getMetadonnesExif() {
171
		
243
		
172
		String[][] metaExif = new String[31][2] ;
244
		String[][] metaExif = new String[31][2] ;
173
		int elem = 0 ;
245
		int elem = 0 ;
174
		
246
		
175
		for (Iterator it = this.keySet().iterator(); it.hasNext();) 
247
		for (Iterator it = this.keySet().iterator(); it.hasNext();) 
176
		{
248
		{
177
						
249
						
178
			String key = (String)it.next();
250
			String key = (String)it.next();
179
			
251
			
180
				// on filtre le "ci"
252
				// on filtre le "ci"
181
				String type[] = key.split("_",3) ;
253
				String type[] = key.split("_",3) ;
182
				
254
				
183
				
255
				
184
				// si c'est une metadonnee exif ou iptc
256
				// si c'est une metadonnee exif ou iptc
185
				if(type[1].equals("meta"))
257
				if(type[1].equals("meta"))
186
				{
258
				{
187
					String[] genre =  type[2].split("_",2) ;
259
					String[] genre =  type[2].split("_",2) ;
188
					if(genre[0].equals("exif"))
260
					if(genre[0].equals("exif"))
189
					{
261
					{
190
						String nom = genre[1] ;
262
						String nom = genre[1] ;
191
						metaExif[elem][0] = nom ;
263
						metaExif[elem][0] = nom ;
192
						metaExif[elem][1] = renvoyerValeurCorrecte(key) ;
264
						metaExif[elem][1] = renvoyerValeurCorrecte(key) ;
193
						elem++ ;	
265
						elem++ ;	
194
					}
266
					}
195
					
267
					
196
				}	
268
				}	
197
							    	
269
							    	
198
		}
270
		}
199
		
271
		
200
		return metaExif ;
272
		return metaExif ;
201
	
273
	
202
	}
274
	}
-
 
275
	
-
 
276
	/**
-
 
277
	 * Renvoie un tableau nom / valeur contenant les infos générales
-
 
278
	 * @return les infos générales
203
	
279
	 */
204
	public Object[][] getInfoGenerales() {
280
	public String[][] getInfoGenerales() {
205
		
281
		
206
		String[][] metaGen = new String[2][2] ;
282
		String[][] metaGen = new String[2][2] ;
207
		
283
		
208
		metaGen[0][0] = "ci_meta_comment" ;
284
		metaGen[0][0] = "ci_meta_comment" ;
209
		metaGen[0][1] = (String)this.get("ci_meta_comment") ;
285
		metaGen[0][1] = (String)this.get("ci_meta_comment") ;
210
		
286
		
211
		metaGen[1][0] = "ci_meta_date" ;
287
		metaGen[1][0] = "ci_meta_date" ;
212
		metaGen[1][1] = (String)this.get("ci_meta_date") ;
288
		metaGen[1][1] = (String)this.get("ci_meta_date") ;
213
		
289
		
214
		return metaGen ;
290
		return metaGen ;
215
	}
291
	}
-
 
292
	
-
 
293
	/**
-
 
294
	 * Renvoie une string contenant les mots clés séparés par des ','
-
 
295
	 * @return les mots clés
216
	
296
	 */
217
	public String getMotsCles() {
297
	public String getMotsCles() {
218
		
298
		
219
		return renvoyerValeurCorrecte("ci_meta_mots_cles") ;
299
		return renvoyerValeurCorrecte("ci_meta_mots_cles") ;
220
	}
300
	}
-
 
301
	
-
 
302
	/**
-
 
303
	 * Met à jour le commenentaire et la date
-
 
304
	 * @param commentaires le nouveau commentaire
-
 
305
	 * @param date la nouvelle date
221
	
306
	 */
222
	public void miseAJourInfoGenerales(String commentaires, String date)
307
	public void miseAJourInfoGenerales(String commentaires, String date)
223
	{
308
	{
224
			put("ci_meta_comment",commentaires) ;
309
			put("ci_meta_comment",commentaires) ;
225
		
310
		
226
			put("ci_meta_date",date) ;
311
			put("ci_meta_date",date) ;
227
	}
312
	}
228
 
313
	
-
 
314
	/**
-
 
315
	 * Met à jour les mots clés
-
 
316
	 * @param motsClesEnCours la liste de mots clés séparés par des ','
-
 
317
	 */
229
	public void mettreAjourMotsCles(String motsClesEnCours) {
318
	public void mettreAjourMotsCles(String motsClesEnCours) {
230
		
319
		
231
		put("ci_meta_mots_cles",motsClesEnCours) ;
320
		put("ci_meta_mots_cles",motsClesEnCours) ;
232
		
321
		
233
	}
322
	}
234
}
323
}