00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 package org.objectweb.jonas.webapp.jonasadmin.resource;
00027
00028 import java.io.IOException;
00029 import java.util.Enumeration;
00030 import java.util.Properties;
00031
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.webapp.jonasadmin.deploy.BaseDeployAction;
00040
00045 public class EditMailFactoryPropertiesAction extends BaseDeployAction {
00046
00047 public ActionForward executeAction(ActionMapping p_Mapping, ActionForm p_Form
00048 , HttpServletRequest p_Request, HttpServletResponse p_Response)
00049 throws IOException, ServletException {
00050
00051 String sAction = p_Request.getParameter("action");
00052 MailFactoryPropertiesForm oForm = new MailFactoryPropertiesForm();
00053 oForm.reset(p_Mapping, p_Request);
00054 m_Session.setAttribute("mailFactoryPropertiesForm", oForm);
00055 String name = "";
00056 Properties props = new Properties();
00057 try {
00058 populate(name, props, oForm);
00059 } catch (Throwable t) {
00060 addGlobalError(t);
00061 saveErrors(p_Request, m_Errors);
00062 return (p_Mapping.findForward("Global Error"));
00063 }
00064
00065
00066 return (p_Mapping.findForward("MailFactory Properties"));
00067 }
00075 void populate(String mailFactoryName, Properties props, MailFactoryPropertiesForm pForm) throws Exception {
00076
00077
00078 pForm.setMailFactoryName(mailFactoryName);
00079
00080 pForm.setJndiName(getStringAttribute(props, "mail.factory.name", pForm.getJndiName()));
00081 props.remove("mail.factory.name");
00082
00083 pForm.setType(getStringAttribute(props, "mail.factory.type", pForm.getType()));
00084 props.remove("mail.factory.type");
00085
00086
00087 pForm.setUsername(getStringAttribute(props, "mail.authentication.username", pForm.getUsername()));
00088 props.remove("mail.authentication.username");
00089 pForm.setPassword(getStringAttribute(props, "mail.authentication.password", pForm.getPassword()));
00090 props.remove("mail.authentication.password");
00091
00092
00093 pForm.setTo(getStringAttribute(props, "mail.to", pForm.getTo()));
00094 pForm.setSubject(getStringAttribute(props, "mail.subject", pForm.getSubject()));
00095 pForm.setCc(getStringAttribute(props, "mail.cc", pForm.getCc()));
00096 pForm.setBcc(getStringAttribute(props, "mail.bcc", pForm.getBcc()));
00097 props.remove("mail.to");
00098 props.remove("mail.subject");
00099 props.remove("mail.cc");
00100 props.remove("mail.bcc");
00101
00102
00103 String aName = null;
00104 String aValue = null;
00105 StringBuffer bufSessionProps = new StringBuffer();
00106 for(Enumeration pNames = props.propertyNames(); pNames.hasMoreElements() ; ) {
00107 aName = (String)pNames.nextElement();
00108 aValue = (String)props.getProperty(aName);
00109 bufSessionProps.append(aName);
00110 bufSessionProps.append("=");
00111 bufSessionProps.append(aValue);
00112 bufSessionProps.append(",");
00113 bufSessionProps.append("\n");
00114 }
00115 if (!props.isEmpty()) {
00116
00117 bufSessionProps.delete(bufSessionProps.length() - 2, bufSessionProps.length() - 1);
00118 } else {
00119
00120
00121 bufSessionProps.append("mail.host=");
00122 }
00123 String sSessionProps = new String(bufSessionProps);
00124 pForm.setSessionProps(sSessionProps);
00125 }
00126
00131 Properties getPropsFromForm(MailFactoryPropertiesForm p_Form, boolean mimepart) throws Exception {
00132 Properties oProps = new Properties();
00133 Properties sProps = getPropsFromString(p_Form.getSessionProps());
00134 oProps.putAll(sProps);
00135 setStringAttribute(oProps, "mail.factory.name", p_Form.getJndiName());
00136 setStringAttribute(oProps, "mail.factory.type", p_Form.getType());
00137 setStringAttribute(oProps, "mail.authentication.username", p_Form.getUsername());
00138 setStringAttribute(oProps, "mail.authentication.password", p_Form.getPassword());
00139 String aName = null;
00140 String aValue = null;
00141 for(Enumeration pNames = oProps.propertyNames(); pNames.hasMoreElements() ; ) {
00142 aName = (String) pNames.nextElement();
00143 aValue = (String) oProps.getProperty(aName);
00144 }
00145 if (mimepart == true) {
00146 setStringAttribute(oProps, "mail.to", p_Form.getTo());
00147 setStringAttribute(oProps, "mail.subject", p_Form.getSubject());
00148 setStringAttribute(oProps, "mail.cc", p_Form.getCc());
00149 setStringAttribute(oProps, "mail.bcc", p_Form.getBcc());
00150 }
00151 return oProps;
00152 }
00153 }