source: ether_megapoli/trunk/service/implementation/com/medias/megapoli/struts/forms/MetadataForm.java @ 151

Last change on this file since 151 was 151, checked in by vmipsl, 13 years ago

Import medias files and cleanup

File size: 5.0 KB
Line 
1package com.medias.megapoli.struts.forms;
2
3import java.util.ArrayList;
4import java.util.Iterator;
5import java.util.Properties;
6
7import org.apache.struts.upload.FormFile;
8import org.apache.struts.validator.ValidatorForm;
9import com.medias.xml.metadata.Contact;
10import com.medias.xml.metadata.Metadata;
11import com.medias.xml.metadata.Plateforme;
12import com.medias.megapoli.utils.NewSetMail;
13import com.medias.mail.Mail;
14
15/**
16 * @author combaz
17 * Created on 10 févr. 2005
18 *
19 * TODO To change the template for this generated type comment go to
20 * Window - Preferences - Java - Code Style - Code Templates
21 */
22public class MetadataForm extends ValidatorForm {
23       
24        /**
25     *
26     */
27    private static final long serialVersionUID = 1L;
28    private Metadata metadata;
29        private ArrayList<String> mess;
30        private ArrayList<Mail> mails;
31
32        public ArrayList<Mail> getMailsList(){
33                return this.mails;
34        }
35       
36        /**
37         * @return Returns the mails.
38         */
39        public Object[] getMails() {
40                return this.mails.toArray();
41        }
42       
43        /**
44         * @param capteurs The capteurs to set.
45         */
46        public void setMails(Mail[] mails) {
47                this.mails = new ArrayList<Mail>();
48                for(int i=0; i<mails.length; i++)
49                        this.mails.add(mails[i]);
50        }
51
52        /**
53         * @return Returns the mess.
54         */
55        public Object[] getMess() {
56                if(this.mess == null)
57                        this.mess = new ArrayList<String>();
58                return this.mess.toArray();
59        }
60       
61       
62        public ArrayList<String> getMessList() {
63                if(this.mess == null)
64                        this.mess = new ArrayList<String>();
65                return this.mess;
66        } 
67       
68        public void setMess(int idx, String txt) {
69                this.mess = new ArrayList<String>();
70                for (int i=0;i<idx;i++)
71                        this.mess.add(i,"");
72                this.mess.add(idx,txt);
73        }
74       
75/*      public void setMess(String[] mess) {
76System.out.println("setMess(txt[])");
77                this.mess = new ArrayList();
78                for(int i=0; i<mess.length; i++) {
79                        if(mess[i]!=null)
80                                this.mess.add(new String(mess[i]));
81                        else
82                                this.mess.add("");
83                }
84        }*/
85       
86        public String getMessText() {
87                String txt = "";
88                Iterator<String> it = this.getMessList().iterator();
89                while(it.hasNext() && txt.length()==0) {
90                        txt = (String) it.next();
91                        if(txt == null)
92                                txt="";
93                }                       
94               
95                if(txt.length()!=0)
96                        return txt;
97               
98                else
99                        return null;
100        }
101       
102        public Integer getMessIdx() {
103                int i = 0;
104                String txt = "";
105                Iterator<String> it = this.mess.iterator();
106                while(it.hasNext() && txt.length()==0) {
107                        txt = (String) it.next();
108                        i++;
109                }
110               
111                if(txt.length()!=0)
112                        return new Integer(i-1);
113               
114                else
115                        return null;
116        }
117
118        /**
119         * @return Returns the metadata.
120         */
121        public Metadata getMetadata() {
122                return metadata;
123        }
124        /**
125         * @param metadata The metadata to set.
126         */
127        public void setMetadata(Metadata metadata) {
128                this.metadata = metadata;
129        }       
130       
131        public FormFile getNewFile() {
132                FormFile file = null;
133                ArrayList<Plateforme> plats = this.metadata.getContenuPrevu().getPlateformes();
134                Iterator<Plateforme> it = plats.iterator();
135                Plateforme plat;
136                while(it.hasNext() && file==null) {
137                    plat = (Plateforme) it.next();
138                        file = plat.getNewFile();
139                }
140                return file;
141        }
142
143        public void setNewFile(FormFile newFile) {
144                FormFile file = null;
145                ArrayList<Plateforme> plats = this.metadata.getContenuPrevu().getPlateformes();
146                Iterator<Plateforme> it = plats.iterator();
147                Plateforme plat;
148                while(it.hasNext() && file==null) {
149                    plat = (Plateforme) it.next();
150                        file = plat.getNewFile();
151                        plat.setNewFile(newFile);
152                }
153        }
154       
155        public String getSetPath() {
156                return this.metadata.getRelativePath();
157        }
158       
159        public void initMess() {
160                this.mess = new ArrayList<String>();           
161        }
162       
163        public void init() {
164                this.initMess();
165                this.metadata = new Metadata();
166                this.mails = new ArrayList<Mail>();
167        }
168       
169        public void init(String categorie) {
170                this.init();
171                this.metadata.getPres().setCat(categorie);
172        }
173       
174        public void initNewSetMails(Properties prop, String from, String nom) {
175                this.mails = new ArrayList<Mail>();
176                Iterator<Contact> it = this.metadata.getPres().getContactsList().iterator();
177                while(it.hasNext()) {
178                        Contact pers = (Contact)it.next();
179                        if(!pers.isNull()) {
180                                /* Doit retourner le mail en copie à l'expéditeur par bcc */
181                                NewSetMail pers_mail = new NewSetMail(from, pers.getMail(), from);
182                                pers_mail.createContent(prop, pers.getPrenom(),pers.getMail(),pers.getMdp(),pers.getRole(),this.metadata.getPres().getNom(),nom);
183                                Iterator<Contact> it2 = this.metadata.getPres().getContactsList().iterator();
184                                while(it2.hasNext()) {
185                                        Contact pers2 = (Contact) it2.next();
186                                        if(!pers2.equals(pers)) {
187                                                String identPers;
188                                                if (pers2.getPrenom() == null || pers2.getPrenom().trim().equals("")) {
189                                                        if (pers2.getNom() == null || pers2.getNom().trim().equals("")) {
190                                                                identPers = pers2.getMail();
191                                                        } else {
192                                                                identPers = pers2.getNom()+" ("+pers2.getMail()+")";
193                                                        }
194                                                } else {
195                                                        if (pers2.getNom() == null || pers2.getNom().trim().equals("")) {
196                                                                identPers = pers2.getMail();
197                                                        } else {
198                                                                identPers = pers2.getPrenom()+" "+pers2.getNom()+" ("+pers2.getMail()+")";
199                                                        }
200                                                }
201                                                pers_mail.addReference(identPers,pers2.getRole());
202                                        }
203                                }
204                                this.mails.add(pers_mail);
205                        }
206                }
207        }
208}
Note: See TracBrowser for help on using the repository browser.