001: /*
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: ApplyMimePartMailFactoryAction.java 9680 2006-10-06 12:08:33Z danesa $
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.webapp.jonasadmin.service.mail;
027:
028: import java.io.IOException;
029: import java.util.Properties;
030:
031: import javax.management.ObjectName;
032: import javax.servlet.ServletException;
033: import javax.servlet.http.HttpServletRequest;
034: import javax.servlet.http.HttpServletResponse;
035:
036: import org.apache.struts.action.ActionForm;
037: import org.apache.struts.action.ActionForward;
038: import org.apache.struts.action.ActionMapping;
039: import org.objectweb.jonas.jmx.J2eeObjectName;
040: import org.objectweb.jonas.jmx.JonasManagementRepr;
041: import org.objectweb.jonas.mail.MailServiceImpl;
042: import org.objectweb.jonas.webapp.jonasadmin.JonasBaseAction;
043:
044: /**
045: * @author Adriana Danes
046: */
047:
048: public class ApplyMimePartMailFactoryAction extends JonasBaseAction {
049:
050: // --------------------------------------------------------- Public Methods
051:
052: public ActionForward executeAction(ActionMapping p_Mapping,
053: ActionForm p_Form, HttpServletRequest p_Request,
054: HttpServletResponse p_Response) throws IOException,
055: ServletException {
056:
057: // Form used
058: MailFactoryForm oForm = (MailFactoryForm) p_Form;
059: try {
060: // process form ....
061: // Mail factory name
062: String mfName = oForm.getMailFactoryName();
063: // Object name used corresponding to the Mail factory MBean
064: String domainName = m_WhereAreYou.getCurrentDomainName();
065: String serverName = m_WhereAreYou
066: .getCurrentJonasServerName();
067: ObjectName oObjectName = J2eeObjectName.JavaMailResource(
068: domainName, mfName, serverName,
069: MailServiceImpl.MIMEPART_PROPERTY_TYPE);
070:
071: String jndiName = oForm.getJndiName();
072: String currentJndiName = getStringAttribute(oObjectName,
073: "Name");
074: if (!jndiName.equals(currentJndiName)) {
075: // Set new JNDI name
076: JonasManagementRepr.setAttribute(oObjectName, "Name",
077: jndiName, serverName);
078: }
079:
080: // apply session properties
081: String sSessionProps = oForm.getSessionProps();
082: Properties pSessionProps = getPropsFromString(sSessionProps);
083: String aName = null;
084: String aValue = null;
085: JonasManagementRepr.setAttribute(oObjectName,
086: "SessionProperties", pSessionProps, serverName);
087:
088: // apply authentication properties if changed
089: String username = oForm.getUsername();
090: String password = oForm.getPassword();
091: Properties authProps = new Properties();
092: authProps.setProperty("mail.authentication.username",
093: username);
094: authProps.setProperty("mail.authentication.password",
095: password);
096: JonasManagementRepr.setAttribute(oObjectName,
097: "AuthenticationProperties", authProps, serverName);
098:
099: // apply specific properties for mime part datasource
100: String to = oForm.getTo();
101: String subject = oForm.getSubject();
102: String cc = oForm.getCc();
103: String bcc = oForm.getBcc();
104: Properties mimeProps = new Properties();
105: mimeProps.setProperty("mail.to", to);
106: mimeProps.setProperty("mail.subject", subject);
107: mimeProps.setProperty("mail.cc", cc);
108: mimeProps.setProperty("mail.bcc", bcc);
109: JonasManagementRepr.setAttribute(oObjectName,
110: "MimeMessageProperties", mimeProps, serverName);
111:
112: if (oForm.getAction().equals("save")) {
113: JonasManagementRepr.invoke(oObjectName, "saveConfig",
114: null, null, serverName);
115: }
116: } catch (Throwable t) {
117: addGlobalError(t);
118: saveErrors(p_Request, m_Errors);
119: return (p_Mapping.findForward("Global Error"));
120: }
121: // Forward to the jsp and add the parameter 'name' with the good value.
122: return new ActionForward(p_Mapping.findForward(
123: "ActionEditMimePartMailFactory").getPath()
124: + "?name=" + oForm.getMailFactoryName());
125: }
126:
127: }
|