source: ether_statistics/service/implementation/com/medias/megapoli/struts/actions/NewSetMailsAction.java @ 569

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

Nouveau projet

File size: 2.6 KB
Line 
1/*
2 * Created on 10 févr. 2005
3 *
4 * TODO To change the template for this generated file go to
5 * Window - Preferences - Java - Code Style - Code Templates
6 */
7package com.medias.megapoli.struts.actions;
8
9import java.util.ArrayList;
10import java.util.HashMap;
11import java.util.Map;
12
13import javax.servlet.ServletException;
14import javax.servlet.http.HttpServletRequest;
15import javax.servlet.http.HttpServletResponse;
16
17import org.apache.struts.action.Action;
18import org.apache.struts.action.ActionError;
19import org.apache.struts.action.ActionErrors;
20import org.apache.struts.action.ActionForm;
21import org.apache.struts.action.ActionForward;
22import org.apache.struts.action.ActionMapping;
23import org.apache.struts.action.ActionMessage;
24import org.apache.struts.action.ActionMessages;
25import com.medias.megapoli.struts.forms.MetadataForm;
26import com.medias.Context;
27import com.medias.mail.Mail;
28import com.medias.mail.MailFactory;
29
30/**
31 * @author combaz
32 *
33 * TODO To change the template for this generated type comment go to
34 * Window - Preferences - Java - Code Style - Code Templates
35 */
36public class NewSetMailsAction extends Action {
37       
38        public ActionForward execute(ActionMapping mapping,ActionForm form,
39                        HttpServletRequest request, HttpServletResponse response)
40                throws ServletException {
41                String target = "failure";
42                ActionErrors errors = new ActionErrors();
43                ActionMessages mess = new ActionMessages();
44               
45                if(this.isCancelled(request))
46                        target = "cancel";
47               
48                else if(form!=null) {
49                        MetadataForm mform = (MetadataForm)form;
50                        //On envoie les mails...
51                        MailFactory mf = (MailFactory) this.servlet.getServletContext().getAttribute("APP_MAILFACTORY");
52                        ArrayList<Mail> mails = mform.getMailsList();
53                        try {
54                                mf.sendMails(mails);
55                                target="success";
56                                mess.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("data.upload.newSet.sendMail.succeded"));
57                        }
58                        catch(Exception e) {
59                                System.out.println ("exception_newSetMail");
60                                e.printStackTrace();
61                                errors.add(ActionErrors.GLOBAL_MESSAGE, new ActionError("errors.upload.newSet.sendMails.failed",Context.getWebmaster(request)));
62                        }
63                }
64                       
65
66                if(!errors.isEmpty()){
67                        saveErrors(request, errors);
68                        target = "failure";
69                }
70
71                if(!mess.isEmpty()){
72                        saveMessages(request, mess);
73                }                       
74                       
75                return mapping.findForward(target);
76        }
77       
78       
79        protected Map<String, String> getKeyMethodMap() {
80              Map<String, String> map = new HashMap<String, String>();
81              map.put("Ajouter un contact", "addContact");
82              map.put("Add a new contact", "addContact");
83              map.put("deletePers", "removeContact");
84              return map;
85          }
86}
Note: See TracBrowser for help on using the repository browser.