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: EditMailFactoryAction.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.util.ArrayList;
029: import java.util.Collections;
030: import java.util.Enumeration;
031: import java.util.Properties;
032:
033: import javax.management.ObjectName;
034:
035: import org.objectweb.jonas.jmx.JonasManagementRepr;
036: import org.objectweb.jonas.jmx.JonasObjectName;
037: import org.objectweb.jonas.webapp.jonasadmin.JonasBaseAction;
038: import org.objectweb.jonas.webapp.jonasadmin.service.ejb.EjbItem;
039: import org.objectweb.jonas.webapp.jonasadmin.service.ejb.EjbItemByNameComparator;
040:
041: /**
042: * Helper for actions for management of Mail Factories
043: * @author Adriana Danes
044: */
045: public abstract class EditMailFactoryAction extends JonasBaseAction {
046:
047: // Populate the MailFactory form
048: void populate(ObjectName pObjectName, MailFactoryForm pForm,
049: String serverName) throws Exception {
050: // Set configuration attributes
051: // - get the jndi name
052: pForm.setJndiName(getStringAttribute(pObjectName, "Name"));
053: // - get authentication properties
054: Properties authProps = (Properties) JonasManagementRepr
055: .getAttribute(pObjectName, "AuthenticationProperties",
056: serverName);
057: String username = (String) authProps
058: .getProperty("mail.authentication.username");
059: pForm.setUsername(username);
060: String password = (String) authProps
061: .getProperty("mail.authentication.password");
062: pForm.setPassword(password);
063:
064: // - get the mail session properties
065: Properties sessionProps = (Properties) JonasManagementRepr
066: .getAttribute(pObjectName, "SessionProperties",
067: serverName);
068: StringBuffer bufSessionProps = new StringBuffer();
069: String propName = null;
070: String propValue;
071: for (Enumeration propNames = sessionProps.propertyNames(); propNames
072: .hasMoreElements();) {
073: propName = (String) propNames.nextElement();
074: propValue = sessionProps.getProperty(propName);
075: bufSessionProps.append(propName);
076: bufSessionProps.append("=");
077: bufSessionProps.append(propValue);
078: bufSessionProps.append(",");
079: bufSessionProps.append("\n");
080: }
081: if (!sessionProps.isEmpty()) {
082: // delete the last 2 chars (, and \n)
083: bufSessionProps.delete(bufSessionProps.length() - 2,
084: bufSessionProps.length() - 1);
085: } else {
086: // Actually no chars in sessionPropsBuf
087: bufSessionProps.append("mail.host=");
088: }
089: String sSessionProps = new String(bufSessionProps);
090: pForm.setSessionProps(sSessionProps);
091:
092: // Set list of EJBs which use this mail factory
093: ArrayList al = new ArrayList();
094: String[] asParam = new String[1];
095: String[] asSignature = new String[1];
096: asSignature[0] = "java.lang.String";
097: asParam[0] = pForm.getJndiName();
098: ObjectName oObjectName = JonasObjectName.ejbService();
099: if (JonasManagementRepr.isRegistered(oObjectName, serverName) == true) {
100: java.util.Iterator it = ((java.util.Set) JonasManagementRepr
101: .invoke(oObjectName, "getMailFactoryDependence",
102: asParam, asSignature, serverName))
103: .iterator();
104: while (it.hasNext()) {
105: al.add(new EjbItem((ObjectName) it.next(), serverName));
106: }
107: // Sort by name
108: Collections.sort(al, new EjbItemByNameComparator());
109: }
110:
111: // Set list in form
112: pForm.setListUsedByEjb(al);
113: }
114:
115: // Set the specific properties of a MimePartDataSource
116: void setMimePartProps(ObjectName pObjectName,
117: MailFactoryForm pForm, String serverName) throws Exception {
118: Properties mimepartProps = (Properties) JonasManagementRepr
119: .getAttribute(pObjectName, "MimeMessageProperties",
120: serverName);
121:
122: String to = (String) mimepartProps.getProperty("mail.to");
123: pForm.setTo(to);
124:
125: String subject = (String) mimepartProps
126: .getProperty("mail.subject");
127: pForm.setSubject(subject);
128:
129: String cc = (String) mimepartProps.getProperty("mail.cc");
130: pForm.setCc(cc);
131:
132: String bcc = (String) mimepartProps.getProperty("mail.bcc");
133: pForm.setBcc(bcc);
134: }
135: }
|