Subversion Repositories eFlore/Archives.cel-v2

Rev

Rev 46 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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