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 | */ |
---|
7 | package com.medias.megapoli.struts.actions; |
---|
8 | |
---|
9 | import java.util.ArrayList; |
---|
10 | import java.util.HashMap; |
---|
11 | import java.util.Map; |
---|
12 | |
---|
13 | import javax.servlet.ServletException; |
---|
14 | import javax.servlet.http.HttpServletRequest; |
---|
15 | import javax.servlet.http.HttpServletResponse; |
---|
16 | |
---|
17 | import org.apache.struts.action.Action; |
---|
18 | import org.apache.struts.action.ActionError; |
---|
19 | import org.apache.struts.action.ActionErrors; |
---|
20 | import org.apache.struts.action.ActionForm; |
---|
21 | import org.apache.struts.action.ActionForward; |
---|
22 | import org.apache.struts.action.ActionMapping; |
---|
23 | import org.apache.struts.action.ActionMessage; |
---|
24 | import org.apache.struts.action.ActionMessages; |
---|
25 | import com.medias.megapoli.struts.forms.MetadataForm; |
---|
26 | import com.medias.Context; |
---|
27 | import com.medias.mail.Mail; |
---|
28 | import 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 | */ |
---|
36 | public 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 | } |
---|