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.service.mail;
00027
00028 import java.util.ArrayList;
00029 import java.util.Collections;
00030 import java.util.Enumeration;
00031 import java.util.Properties;
00032
00033 import javax.management.ObjectName;
00034
00035 import org.objectweb.jonas.jmx.JonasManagementRepr;
00036 import org.objectweb.jonas.jmx.JonasObjectName;
00037 import org.objectweb.jonas.webapp.jonasadmin.JonasBaseAction;
00038 import org.objectweb.jonas.webapp.jonasadmin.service.ejb.EjbItem;
00039 import org.objectweb.jonas.webapp.jonasadmin.service.ejb.EjbItemByNameComparator;
00040
00045 public abstract class EditMailFactoryAction extends JonasBaseAction {
00046
00047
00048 void populate(ObjectName pObjectName, MailFactoryForm pForm) throws Exception {
00049
00050
00051 pForm.setJndiName(getStringAttribute(pObjectName, "Name"));
00052
00053 Properties authProps = (Properties)JonasManagementRepr.getAttribute(pObjectName, "AuthenticationProperties");
00054 String username = (String) authProps.getProperty("mail.authentication.username");
00055 pForm.setUsername(username);
00056 String password = (String) authProps.getProperty("mail.authentication.password");
00057 pForm.setPassword(password);
00058
00059
00060 Properties sessionProps = (Properties)JonasManagementRepr.getAttribute(pObjectName, "SessionProperties");
00061 StringBuffer bufSessionProps = new StringBuffer();
00062 String propName = null;
00063 String propValue;
00064 for (Enumeration propNames = sessionProps.propertyNames() ; propNames.hasMoreElements() ;) {
00065 propName = (String) propNames.nextElement();
00066 propValue = sessionProps.getProperty(propName);
00067 bufSessionProps.append(propName);
00068 bufSessionProps.append("=");
00069 bufSessionProps.append(propValue);
00070 bufSessionProps.append(",");
00071 bufSessionProps.append("\n");
00072 }
00073 if (!sessionProps.isEmpty()) {
00074
00075 bufSessionProps.delete(bufSessionProps.length() - 2, bufSessionProps.length() - 1);
00076 } else {
00077
00078 bufSessionProps.append("mail.host=");
00079 }
00080 String sSessionProps = new String(bufSessionProps);
00081 pForm.setSessionProps(sSessionProps);
00082
00083
00084 ArrayList al = new ArrayList();
00085 String[] asParam = new String[1];
00086 String[] asSignature = new String[1];
00087 asSignature[0] = "java.lang.String";
00088 asParam[0] = pForm.getJndiName();
00089 ObjectName oObjectName = JonasObjectName.ejbService();
00090 if (JonasManagementRepr.isRegistered(oObjectName) == true) {
00091 java.util.Iterator it = ((java.util.Set) JonasManagementRepr.invoke(
00092 oObjectName,
00093 "getMailFactoryDependence",
00094 asParam,
00095 asSignature)).iterator();
00096 while (it.hasNext()) {
00097 al.add(new EjbItem((ObjectName) it.next()));
00098 }
00099
00100 Collections.sort(al, new EjbItemByNameComparator());
00101 }
00102
00103
00104 pForm.setListUsedByEjb(al);
00105 }
00106
00107
00108 void setMimePartProps(ObjectName pObjectName, MailFactoryForm pForm) throws Exception {
00109 Properties mimepartProps = (Properties)JonasManagementRepr.getAttribute(pObjectName, "MimeMessageProperties");
00110
00111 String to = (String) mimepartProps.getProperty("mail.to");
00112 pForm.setTo(to);
00113
00114 String subject = (String) mimepartProps.getProperty("mail.subject");
00115 pForm.setSubject(subject);
00116
00117 String cc = (String) mimepartProps.getProperty("mail.cc");
00118 pForm.setCc(cc);
00119
00120 String bcc = (String) mimepartProps.getProperty("mail.bcc");
00121 pForm.setBcc(bcc);
00122 }
00123 }