Subversion Repositories eFlore/Archives.cel-v2

Rev

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

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