1 25 26 package org.objectweb.jonas.webapp.jonasadmin.resource; 27 28 import java.io.IOException ; 29 import java.util.Enumeration ; 30 import java.util.Properties ; 31 32 import javax.servlet.ServletException ; 33 import javax.servlet.http.HttpServletRequest ; 34 import javax.servlet.http.HttpServletResponse ; 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.webapp.jonasadmin.deploy.BaseDeployAction; 40 41 45 public class EditMailFactoryPropertiesAction extends BaseDeployAction { 46 47 public ActionForward executeAction(ActionMapping p_Mapping, ActionForm p_Form 48 , HttpServletRequest p_Request, HttpServletResponse p_Response) 49 throws IOException , ServletException { 50 51 String sAction = p_Request.getParameter("action"); 52 MailFactoryPropertiesForm oForm = new MailFactoryPropertiesForm(); 53 oForm.reset(p_Mapping, p_Request); 54 m_Session.setAttribute("mailFactoryPropertiesForm", oForm); 55 String name = ""; 56 Properties props = new Properties (); 57 try { 58 populate(name, props, oForm); 59 } catch (Throwable t) { 60 addGlobalError(t); 61 saveErrors(p_Request, m_Errors); 62 return (p_Mapping.findForward("Global Error")); 63 } 64 65 return (p_Mapping.findForward("MailFactory Properties")); 67 } 68 75 void populate(String mailFactoryName, Properties props, MailFactoryPropertiesForm pForm) throws Exception { 76 pForm.setMailFactoryName(mailFactoryName); 79 pForm.setJndiName(getStringAttribute(props, "mail.factory.name", pForm.getJndiName())); 81 props.remove("mail.factory.name"); 82 pForm.setType(getStringAttribute(props, "mail.factory.type", pForm.getType())); 84 props.remove("mail.factory.type"); 85 86 pForm.setUsername(getStringAttribute(props, "mail.authentication.username", pForm.getUsername())); 88 props.remove("mail.authentication.username"); 89 pForm.setPassword(getStringAttribute(props, "mail.authentication.password", pForm.getPassword())); 90 props.remove("mail.authentication.password"); 91 92 pForm.setTo(getStringAttribute(props, "mail.to", pForm.getTo())); 94 pForm.setSubject(getStringAttribute(props, "mail.subject", pForm.getSubject())); 95 pForm.setCc(getStringAttribute(props, "mail.cc", pForm.getCc())); 96 pForm.setBcc(getStringAttribute(props, "mail.bcc", pForm.getBcc())); 97 props.remove("mail.to"); 98 props.remove("mail.subject"); 99 props.remove("mail.cc"); 100 props.remove("mail.bcc"); 101 102 String aName = null; 104 String aValue = null; 105 StringBuffer bufSessionProps = new StringBuffer (); 106 for(Enumeration pNames = props.propertyNames(); pNames.hasMoreElements() ; ) { 107 aName = (String )pNames.nextElement(); 108 aValue = (String )props.getProperty(aName); 109 bufSessionProps.append(aName); 110 bufSessionProps.append("="); 111 bufSessionProps.append(aValue); 112 bufSessionProps.append(","); 113 bufSessionProps.append("\n"); 114 } 115 if (!props.isEmpty()) { 116 bufSessionProps.delete(bufSessionProps.length() - 2, bufSessionProps.length() - 1); 118 } else { 119 bufSessionProps.append("mail.host="); 122 } 123 String sSessionProps = new String (bufSessionProps); 124 pForm.setSessionProps(sSessionProps); 125 } 126 127 131 Properties getPropsFromForm(MailFactoryPropertiesForm p_Form, boolean mimepart) throws Exception { 132 Properties oProps = new Properties (); 133 Properties sProps = getPropsFromString(p_Form.getSessionProps()); 134 oProps.putAll(sProps); 135 setStringAttribute(oProps, "mail.factory.name", p_Form.getJndiName()); 136 setStringAttribute(oProps, "mail.factory.type", p_Form.getType()); 137 setStringAttribute(oProps, "mail.authentication.username", p_Form.getUsername()); 138 setStringAttribute(oProps, "mail.authentication.password", p_Form.getPassword()); 139 String aName = null; 140 String aValue = null; 141 for(Enumeration pNames = oProps.propertyNames(); pNames.hasMoreElements() ; ) { 142 aName = (String ) pNames.nextElement(); 143 aValue = (String ) oProps.getProperty(aName); 144 } 145 if (mimepart == true) { 146 setStringAttribute(oProps, "mail.to", p_Form.getTo()); 147 setStringAttribute(oProps, "mail.subject", p_Form.getSubject()); 148 setStringAttribute(oProps, "mail.cc", p_Form.getCc()); 149 setStringAttribute(oProps, "mail.bcc", p_Form.getBcc()); 150 } 151 return oProps; 152 } 153 } 154 | Popular Tags |