KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > webapp > jonasadmin > service > mail > ApplyMimePartMailFactoryAction


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: ApplyMimePartMailFactoryAction.java,v 1.6 2004/03/19 14:31:49 sauthieg Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.webapp.jonasadmin.service.mail;
27
28 import java.io.IOException JavaDoc;
29 import java.util.Properties JavaDoc;
30
31 import javax.management.ObjectName JavaDoc;
32 import javax.servlet.ServletException JavaDoc;
33 import javax.servlet.http.HttpServletRequest JavaDoc;
34 import javax.servlet.http.HttpServletResponse JavaDoc;
35
36 import org.apache.struts.action.ActionForm;
37 import org.apache.struts.action.ActionForward;
38 import org.apache.struts.action.ActionMapping;
39 import org.objectweb.jonas.jmx.J2eeObjectName;
40 import org.objectweb.jonas.jmx.JonasManagementRepr;
41 import org.objectweb.jonas.mail.MailServiceImpl;
42 import org.objectweb.jonas.webapp.jonasadmin.JonasBaseAction;
43
44 /**
45  * @author Adriana Danes
46  */

47
48 public class ApplyMimePartMailFactoryAction extends JonasBaseAction {
49
50 // --------------------------------------------------------- Public Methods
51

52     public ActionForward executeAction(ActionMapping p_Mapping, ActionForm p_Form
53         , HttpServletRequest JavaDoc p_Request, HttpServletResponse JavaDoc p_Response)
54         throws IOException JavaDoc, ServletException JavaDoc {
55
56         // Form used
57
MailFactoryForm oForm = (MailFactoryForm) p_Form;
58         try {
59             // process form ....
60
// Mail factory name
61
String JavaDoc mfName = oForm.getMailFactoryName();
62             // Object name used corresponding to the Mail factory MBean
63
String JavaDoc domainName = m_WhereAreYou.getCurrentDomainName();
64             String JavaDoc serverName = m_WhereAreYou.getCurrentJonasServerName();
65             ObjectName JavaDoc oObjectName = J2eeObjectName.JavaMailResource(domainName, mfName, serverName,
66                                                                      MailServiceImpl.MIMEPART_PROPERTY_TYPE);
67
68             String JavaDoc jndiName = oForm.getJndiName();
69             String JavaDoc currentJndiName = getStringAttribute(oObjectName, "Name");
70             if (!jndiName.equals(currentJndiName)) {
71                 // Set new JNDI name
72
JonasManagementRepr.setAttribute(oObjectName, "Name", jndiName);
73             }
74
75             // apply session properties
76
String JavaDoc sSessionProps = oForm.getSessionProps();
77             Properties JavaDoc pSessionProps = getPropsFromString(sSessionProps);
78             String JavaDoc aName = null;
79             String JavaDoc aValue = null;
80             JonasManagementRepr.setAttribute(oObjectName, "SessionProperties", pSessionProps);
81
82             // apply authentication properties if changed
83
String JavaDoc username = oForm.getUsername();
84             String JavaDoc password = oForm.getPassword();
85             Properties JavaDoc authProps = new Properties JavaDoc();
86             authProps.setProperty("mail.authentication.username", username);
87             authProps.setProperty("mail.authentication.password", password);
88             JonasManagementRepr.setAttribute(oObjectName, "AuthenticationProperties", authProps);
89
90             // apply specific properties for mime part datasource
91
String JavaDoc to = oForm.getTo();
92             String JavaDoc subject = oForm.getSubject();
93             String JavaDoc cc = oForm.getCc();
94             String JavaDoc bcc = oForm.getBcc();
95             Properties JavaDoc mimeProps = new Properties JavaDoc();
96             mimeProps.setProperty("mail.to", to);
97             mimeProps.setProperty("mail.subject", subject);
98             mimeProps.setProperty("mail.cc", cc);
99             mimeProps.setProperty("mail.bcc", bcc);
100             JonasManagementRepr.setAttribute(oObjectName, "MimeMessageProperties", mimeProps);
101
102             if (oForm.getAction().equals("save") == true) {
103                 JonasManagementRepr.invoke(oObjectName, "saveConfig", null, null);
104             }
105         }
106         catch (Throwable JavaDoc t) {
107             addGlobalError(t);
108             saveErrors(p_Request, m_Errors);
109             return (p_Mapping.findForward("Global Error"));
110         }
111         // Forward to the jsp and add the parameter 'name' with the good value.
112
return new ActionForward(p_Mapping.findForward("ActionEditMimePartMailFactory").getPath()
113             + "?name=" + oForm.getMailFactoryName());
114     }
115
116 }
117
Popular Tags