source: ether_megapoli/trunk/domain/interface/com/medias/xml/metadata/Plateforme.java @ 424

Last change on this file since 424 was 424, checked in by vmipsl, 12 years ago

!!! Recup Megapoli apres EFFACEMENT !!!

File size: 8.2 KB
Line 
1package com.medias.xml.metadata;
2
3import com.medias.Constantes;
4import com.medias.ConversionException;
5import com.medias.utils.Entity;
6import org.apache.struts.upload.FormFile;
7import org.jdom.Element;
8
9import java.util.ArrayList;
10import java.util.Comparator;
11import java.util.Iterator;
12import java.util.List;
13
14/**
15 * @author combaz
16 *
17 * Created on 10 févr. 2005
18 */
19public class Plateforme implements Entity
20{
21        /**
22     *
23     */
24    private static final long serialVersionUID = 1L;
25
26    private FormFile newFile;
27       
28        private String nom;
29        private String nomOth;
30        private String desc;
31        private ArrayList<String> liste_images;
32        // Pour la partie dépÃŽt de données
33        private String lat_min;
34        private String lon_min;
35        private String alt_min;
36        private String lat_max;
37        private String lon_max;
38        private String alt_max;
39        // Pour la partie accÚs aux données
40        private String typePlateforme;
41        private String idPlateforme;
42       
43        public Plateforme() {
44                super();
45                this.newFile = null;
46                this.nom = "";
47                this.nomOth = "";
48                this.desc = null;
49                this.liste_images = new ArrayList<String>();
50                this.lat_min = "0";
51                this.lon_min = "0";
52                this.alt_min = "0";
53                this.lat_max = "0";
54                this.lon_max = "0";
55                this.alt_max = "0";
56                this.typePlateforme = null;
57                this.idPlateforme = null;
58        }
59
60       
61    public String getIdPlateforme() {
62        return idPlateforme;
63    }
64   
65    public void setIdPlateforme(String idPlateforme) {
66        this.idPlateforme = idPlateforme;
67    }
68   
69        public String getTypePlateforme() {
70                return typePlateforme;
71        }
72       
73        public void setTypePlateforme(String typePlateforme) {
74                this.typePlateforme = typePlateforme;
75        }
76       
77        /**
78         * @return Returns the newFile.
79         */
80        public FormFile getNewFile() {
81                return newFile;
82        }
83        /**
84         * @param newFile The newFile to set.
85         */
86        public void setNewFile(FormFile newFile) {
87            if (newFile == null) {
88                this.newFile = null;
89            }
90            else if (!newFile.getFileName().equals("")){
91                this.newFile = newFile;
92//              this.liste_images.add(newFile.getFileName());
93                }
94        }
95
96        public String removeFile(Integer idx) {
97            String filename = liste_images.get(idx.intValue());
98                this.liste_images.remove(idx.intValue());
99                Iterator<String> it = liste_images.iterator();
100                String img;
101                while (it.hasNext()) {
102                    img = (String)it.next();
103                    if (img.equals("")) {
104                        it.remove();
105                    }
106                }
107                return filename;
108        }
109       
110        /**
111         * @return Returns the nom.
112         */
113        public String getNom() {
114                return nom;
115        }
116        /**
117         * @param nom The nom to set.
118         */
119        public void setNom(String nom) {
120                this.nom = nom;
121        }
122        /**
123         * @return Returns the desc.
124         */
125        public String getDesc() {
126                return desc;
127        }
128        /**
129         * @param desc The desc to set.
130         */
131        public void setDesc(String desc) {
132                this.desc = desc;
133        }
134        /**
135         * @return Returns the images.
136         */
137        public Object[] getListe_images() {
138//          if(this.liste_images.isEmpty()) {
139//                  liste_images.add("");
140//              }
141                return this.liste_images.toArray();
142        }
143       
144        public ArrayList<String> getListe_imagesList() {
145                return this.liste_images;
146        }
147        /**
148         * @param images The images to set.
149         */
150        public void setListe_images(String[] images) {
151                this.liste_images = new ArrayList<String>();
152                for(int i=0; i<images.length; i++){
153                    if (!images[i].equals("")) {
154                        this.liste_images.add(images[i]);
155                    }
156                }
157        }
158
159        /**
160         * @return Returns the alt_max.
161         */
162        public String getAlt_max() {
163                return alt_max;
164        }
165        /**
166         * @param alt_max The alt_max to set.
167         */
168        public void setAlt_max(String alt_max) {
169                this.alt_max = alt_max;
170        }
171        /**
172         * @return Returns the alt_min.
173         */
174        public String getAlt_min() {
175                return alt_min;
176        }
177        /**
178         * @param alt_min The alt_min to set.
179         */
180        public void setAlt_min(String alt_min) {
181                this.alt_min = alt_min;
182        }
183        /**
184         * @return Returns the lat_max.
185         */
186        public String getLat_max() {
187                return lat_max;
188        }
189        /**
190         * @param lat_max The lat_max to set.
191         */
192        public void setLat_max(String lat_max) {
193                this.lat_max = lat_max;
194        }
195        /**
196         * @return Returns the lat_min.
197         */
198        public String getLat_min() {
199                return lat_min;
200        }
201        /**
202         * @param lat_min The lat_min to set.
203         */
204        public void setLat_min(String lat_min) {
205                this.lat_min = lat_min;
206        }
207        /**
208         * @return Returns the lon_max.
209         */
210        public String getLon_max() {
211                return lon_max;
212        }
213        /**
214         * @param lon_max The lon_max to set.
215         */
216        public void setLon_max(String lon_max) {
217                this.lon_max = lon_max;
218        }
219        /**
220         * @return Returns the lon_min.
221         */
222        public String getLon_min() {
223                return lon_min;
224        }
225        /**
226         * @param lon_min The lon_min to set.
227         */
228        public void setLon_min(String lon_min) {
229                this.lon_min = lon_min;
230        }
231        public Element toXmlElement(String title) {
232                Element n = new Element("nom");
233                n.addContent(this.nom);
234                Element d = new Element("desc");
235                d.addContent(this.desc);
236                Element im = new Element("liste_images");
237                ArrayList<Element> il = new ArrayList<Element>();
238                for(int i = 0; i<this.liste_images.size(); i++) {
239                        String img = this.liste_images.get(i);
240                        if (!img.equals("")) {
241                                Element elem = new Element("image");
242                                elem.addContent(img);
243                                il.add(elem);
244                        }
245                }
246                im.addContent(il);             
247                Element lm = new Element("lat_min");
248                lm.addContent(""+this.lat_min);
249                Element Lm = new Element("lon_min");
250                Lm.addContent(""+this.lon_min);
251                Element am = new Element("alt_min");
252                am.addContent(""+ this.alt_min);
253                Element lM = new Element("lat_max");
254                lM.addContent(""+this.lat_max);
255                Element LM = new Element("lon_max");
256                LM.addContent(""+this.lon_max);
257                Element aM = new Element("alt_max");
258                aM.addContent(""+ this.alt_max);
259               
260                Element plat = new Element(title);
261                plat.addContent(n);
262                plat.addContent(d);
263                plat.addContent(im);
264                plat.addContent(lm);
265                plat.addContent(Lm);
266                plat.addContent(am);
267                plat.addContent(lM);
268                plat.addContent(LM);
269                plat.addContent(aM);
270                return plat;
271        }
272       
273        public void fromXmlElement(Element el) throws ConversionException {
274                Element n = el.getChild("nom");
275                Element d = el.getChild("desc");
276                Element im = el.getChild("liste_images");
277                Element lm = el.getChild("lat_min");
278                Element Lm = el.getChild("lon_min");
279                Element am = el.getChild("alt_min");
280                Element lM = el.getChild("lat_max");
281                Element LM = el.getChild("lon_max");
282                Element aM = el.getChild("alt_max");
283                if((lm==null)||(Lm==null)||(am==null)||(lM==null)||(LM==null)||(aM==null)) {
284                        Element l = el.getChild("lat");
285                        Element L = el.getChild("lon");
286                        Element a = el.getChild("alt");
287                        this.setNom(n.getText());
288                        this.setLat_min(l.getText());
289                        this.setLon_min(L.getText());
290                        this.setAlt_min(a.getText());
291                        this.setLat_max(l.getText());
292                        this.setLon_max(L.getText());
293                        this.setAlt_max(a.getText());
294                }
295               
296                else {
297                        boolean isNomDefault = false;
298                        for (String nomPlat: Constantes.listePlateformes) {
299                                if (n.getText().equals(nomPlat)) {
300                                        isNomDefault = true;
301                                        break;
302                                }
303                        }
304                        if (isNomDefault)
305                                this.setNom(n.getText());
306                        else {
307                                this.setNom("-");
308                                this.setNomOth(n.getText());
309                        }
310                        if(d!=null)
311                                this.setDesc(d.getText());
312                        if(im!=null) {
313                                List<?> il = im.getChildren("image");
314                                if(!il.isEmpty()) {
315                                        Iterator<?> ilit = il.iterator();
316                                        while(ilit.hasNext()) {
317                                                Element elem = (Element) ilit.next();
318                                                String img = elem.getText();
319                                                this.liste_images.add(img);
320                                        }
321                                }
322                        }
323                        this.setLat_min(lm.getText());
324                        this.setLon_min(Lm.getText());
325                        this.setAlt_min(am.getText());
326                        this.setLat_max(lM.getText());
327                        this.setLon_max(LM.getText());
328                        this.setAlt_max(aM.getText());
329                }
330        }
331
332        public void formToModel() {
333                alt_max = ( alt_max == null ? "" : alt_max.trim() );
334                alt_min = ( alt_min == null ? "" : alt_min.trim() );
335                lat_max = ( lat_max == null ? "" : lat_max.trim() );
336                lat_min = ( lat_min == null ? "" : lat_min.trim() );
337                lon_max = ( lon_max == null ? "" : lon_max.trim() );
338                lon_min = ( lon_min == null ? "" : lon_min.trim() );
339                desc = ( desc == null ? "" : desc.trim() );
340//              nom = ( (nom == null) ? "" : nom.trim() );
341                if (nom == null || nom.equals("-")) {
342                        if (nomOth == null) {
343                                nom = "";
344                        } else {
345                                nom = nomOth.trim();
346                        }
347                } else {
348                        nom = nom.trim();
349                }
350        }
351       
352    public class ComparatorNom implements Comparator<Plateforme>{
353        public int compare(Plateforme p1, Plateforme p2){
354                return p1.getNom().compareTo(p2.getNom());
355        }
356    }
357
358        public String getNomOth() {
359                return nomOth;
360        }
361
362
363        public void setNomOth(String nomOth) {
364                this.nomOth = nomOth;
365        }
366}
Note: See TracBrowser for help on using the repository browser.