Subversion Repositories eFlore/Applications.cel

Rev

Rev 2 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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