ApplyMimePartMailFactoryAction.java

00001 /*
00002  * JOnAS: Java(TM) Open Application Server
00003  * Copyright (C) 1999 Bull S.A.
00004  * Contact: jonas-team@objectweb.org
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00019  * USA
00020  *
00021  * --------------------------------------------------------------------------
00022  * $Id: ApplyMimePartMailFactoryAction.java,v 1.6 2004/03/19 14:31:49 sauthieg Exp $
00023  * --------------------------------------------------------------------------
00024  */
00025 
00026 package org.objectweb.jonas.webapp.jonasadmin.service.mail;
00027 
00028 import java.io.IOException;
00029 import java.util.Properties;
00030 
00031 import javax.management.ObjectName;
00032 import javax.servlet.ServletException;
00033 import javax.servlet.http.HttpServletRequest;
00034 import javax.servlet.http.HttpServletResponse;
00035 
00036 import org.apache.struts.action.ActionForm;
00037 import org.apache.struts.action.ActionForward;
00038 import org.apache.struts.action.ActionMapping;
00039 import org.objectweb.jonas.jmx.J2eeObjectName;
00040 import org.objectweb.jonas.jmx.JonasManagementRepr;
00041 import org.objectweb.jonas.mail.MailServiceImpl;
00042 import org.objectweb.jonas.webapp.jonasadmin.JonasBaseAction;
00043 
00048 public class ApplyMimePartMailFactoryAction extends JonasBaseAction {
00049 
00050 // --------------------------------------------------------- Public Methods
00051 
00052     public ActionForward executeAction(ActionMapping p_Mapping, ActionForm p_Form
00053         , HttpServletRequest p_Request, HttpServletResponse p_Response)
00054         throws IOException, ServletException {
00055 
00056         // Form used
00057         MailFactoryForm oForm = (MailFactoryForm) p_Form;
00058         try {
00059             // process form ....
00060             // Mail factory name
00061             String mfName = oForm.getMailFactoryName();
00062             // Object name used corresponding to the Mail factory MBean       
00063             String domainName = m_WhereAreYou.getCurrentDomainName();
00064             String serverName = m_WhereAreYou.getCurrentJonasServerName();
00065             ObjectName oObjectName = J2eeObjectName.JavaMailResource(domainName, mfName, serverName, 
00066                                                                      MailServiceImpl.MIMEPART_PROPERTY_TYPE);
00067 
00068             String jndiName = oForm.getJndiName();
00069             String currentJndiName = getStringAttribute(oObjectName, "Name");
00070             if (!jndiName.equals(currentJndiName)) {
00071                 // Set new JNDI name
00072                 JonasManagementRepr.setAttribute(oObjectName, "Name", jndiName);
00073             }
00074 
00075             // apply session properties
00076             String sSessionProps = oForm.getSessionProps();
00077             Properties pSessionProps = getPropsFromString(sSessionProps);
00078             String aName = null;
00079             String aValue = null;
00080             JonasManagementRepr.setAttribute(oObjectName, "SessionProperties", pSessionProps);
00081 
00082             // apply authentication properties if changed
00083             String username = oForm.getUsername();
00084             String password = oForm.getPassword();
00085             Properties authProps = new Properties();
00086             authProps.setProperty("mail.authentication.username", username);
00087             authProps.setProperty("mail.authentication.password", password);
00088             JonasManagementRepr.setAttribute(oObjectName, "AuthenticationProperties", authProps);
00089 
00090             // apply specific properties for mime part datasource
00091             String to = oForm.getTo();
00092             String subject = oForm.getSubject();
00093             String cc = oForm.getCc();
00094             String bcc = oForm.getBcc();
00095             Properties mimeProps = new Properties();
00096             mimeProps.setProperty("mail.to", to);
00097             mimeProps.setProperty("mail.subject", subject);
00098             mimeProps.setProperty("mail.cc", cc);
00099             mimeProps.setProperty("mail.bcc", bcc);
00100             JonasManagementRepr.setAttribute(oObjectName, "MimeMessageProperties", mimeProps);
00101 
00102             if (oForm.getAction().equals("save") == true) {
00103                 JonasManagementRepr.invoke(oObjectName, "saveConfig", null, null);
00104             }
00105         }
00106         catch (Throwable t) {
00107             addGlobalError(t);
00108             saveErrors(p_Request, m_Errors);
00109             return (p_Mapping.findForward("Global Error"));
00110         }
00111         // Forward to the jsp and add the parameter 'name' with the good value.
00112         return new ActionForward(p_Mapping.findForward("ActionEditMimePartMailFactory").getPath()
00113             + "?name=" + oForm.getMailFactoryName());
00114     }
00115 
00116 }

Generated on Tue Feb 15 15:05:33 2005 for JOnAS by  doxygen 1.3.9.1