Return-Path: Delivered-To: apmail-cocoon-cvs-archive@www.apache.org Received: (qmail 79532 invoked from network); 23 Sep 2004 13:40:42 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 23 Sep 2004 13:40:42 -0000 Received: (qmail 31040 invoked by uid 500); 23 Sep 2004 13:40:41 -0000 Delivered-To: apmail-cocoon-cvs-archive@cocoon.apache.org Received: (qmail 30973 invoked by uid 500); 23 Sep 2004 13:40:41 -0000 Mailing-List: contact cvs-help@cocoon.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@cocoon.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list cvs@cocoon.apache.org Received: (qmail 30962 invoked by uid 99); 23 Sep 2004 13:40:41 -0000 X-ASF-Spam-Status: No, hits=-10.0 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Thu, 23 Sep 2004 06:40:40 -0700 Received: (qmail 79452 invoked by uid 65534); 23 Sep 2004 13:40:39 -0000 Date: 23 Sep 2004 13:40:39 -0000 Message-ID: <20040923134039.79441.qmail@minotaur.apache.org> From: sylvain@apache.org To: cvs@cocoon.apache.org Subject: svn commit: rev 47102 - cocoon/trunk/src/blocks/mail/java/org/apache/cocoon/mail X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Author: sylvain Date: Thu Sep 23 06:40:38 2004 New Revision: 47102 Modified: cocoon/trunk/src/blocks/mail/java/org/apache/cocoon/mail/MailMessageSender.java cocoon/trunk/src/blocks/mail/java/org/apache/cocoon/mail/MailSender.java Log: MailSender now gets the SourceResolver from the ServiceManager, thus easing its use in flowscript Modified: cocoon/trunk/src/blocks/mail/java/org/apache/cocoon/mail/MailMessageSender.java ============================================================================== --- cocoon/trunk/src/blocks/mail/java/org/apache/cocoon/mail/MailMessageSender.java (original) +++ cocoon/trunk/src/blocks/mail/java/org/apache/cocoon/mail/MailMessageSender.java Thu Sep 23 06:40:38 2004 @@ -15,19 +15,23 @@ */ package org.apache.cocoon.mail; -import org.apache.cocoon.environment.SourceResolver; import org.apache.cocoon.mail.datasource.FilePartDataSource; import org.apache.cocoon.mail.datasource.SourceDataSource; import org.apache.cocoon.servlet.multipart.Part; +import org.apache.avalon.framework.CascadingRuntimeException; import org.apache.avalon.framework.activity.Initializable; import org.apache.avalon.framework.component.Component; import org.apache.avalon.framework.logger.AbstractLogEnabled; import org.apache.avalon.framework.parameters.ParameterException; import org.apache.avalon.framework.parameters.Parameterizable; import org.apache.avalon.framework.parameters.Parameters; +import org.apache.avalon.framework.service.ServiceException; +import org.apache.avalon.framework.service.ServiceManager; +import org.apache.avalon.framework.service.Serviceable; import org.apache.excalibur.source.Source; +import org.apache.excalibur.source.SourceResolver; import java.io.IOException; import java.net.MalformedURLException; @@ -63,10 +67,12 @@ * @author Frank Ridderbusch * @author Christian Haul * @since 2.1 - * @version CVS $Id: MailMessageSender.java,v 1.12 2004/05/09 20:05:59 haul Exp $ + * @version CVS $Id$ */ public class MailMessageSender extends AbstractLogEnabled - implements MailSender, Parameterizable, Initializable, Component { + implements MailSender, Parameterizable, Serviceable, Initializable, Component { + + private ServiceManager manager; private MimeMessage message; private String from; @@ -197,12 +203,39 @@ this.message = new MimeMessage(session); this.attachmentList = new ArrayList(); } + + public void service(ServiceManager manager) { + this.manager = manager; + } + + /** Assemble the message from the defined fields and send it. + * @throws AddressException when problems with email addresses are found + * @throws MessagingException when message could not be send. + */ + public void send() throws AddressException, MessagingException { + SourceResolver resolver = null; + try { + resolver = (SourceResolver)this.manager.lookup(SourceResolver.ROLE); + doSend(resolver); + } catch(ServiceException se) { + throw new CascadingRuntimeException("Cannot get Source Resolver to send mail", se); + } finally { + this.manager.release(resolver); + } + } /** Assemble the message from the defined fields and send it. * @throws AddressException when problems with email addresses are found * @throws MessagingException when message could not be send. */ - public void send(SourceResolver resolver) + public void send(org.apache.cocoon.environment.SourceResolver resolver) + throws AddressException, MessagingException { + + // resolver is automatically down-casted + doSend(resolver); + } + + public void doSend(SourceResolver resolver) throws AddressException, MessagingException { List sourcesList = new ArrayList(); @@ -375,11 +408,28 @@ } /** + * Invokes the {@link #send()} method but catches any exception thrown. This + * method is intended to be used from the sendmail logicsheet. + * @return true when successful + */ + public boolean sendIt() { + boolean success = false; + try { + this.exception = null; + this.send(); + success = true; + } catch (Exception e) { + this.exception = e; + } + return success; + } + + /** * Invokes the {@link #send(SourceResolver)} method but catches any exception thrown. This * method is intended to be used from the sendmail logicsheet. * @return true when successful */ - public boolean sendIt(SourceResolver resolver) { + public boolean sendIt(org.apache.cocoon.environment.SourceResolver resolver) { boolean success = false; try { this.exception = null; Modified: cocoon/trunk/src/blocks/mail/java/org/apache/cocoon/mail/MailSender.java ============================================================================== --- cocoon/trunk/src/blocks/mail/java/org/apache/cocoon/mail/MailSender.java (original) +++ cocoon/trunk/src/blocks/mail/java/org/apache/cocoon/mail/MailSender.java Thu Sep 23 06:40:38 2004 @@ -23,7 +23,7 @@ * and the sendmail.xsl logicsheet for sending an email message. * * @author Christian Haul - * @version CVS $Id: MailSender.java,v 1.1 2004/05/09 20:05:59 haul Exp $ + * @version CVS $Id$ */ public interface MailSender { @@ -32,6 +32,7 @@ /** Assemble the message from the defined fields and send it. * @throws AddressException when problems with email addresses are found * @throws MessagingException when message could not be send. + * @deprecated Use {@link #send()} which doesn't require passing the source resolver */ void send(SourceResolver resolver) throws AddressException, MessagingException; @@ -40,9 +41,25 @@ * Invokes the {@link #send(SourceResolver)} method but catches any exception thrown. This * method is intended to be used from the sendmail logicsheet. * @return true when successful + * @deprecated Use {@link #sendIt()} which doesn't require passing the source resolver */ boolean sendIt(SourceResolver resolver); + /** Assemble the message from the defined fields and send it. The source resolver + * is obtained from the hosting component container. + * @throws AddressException when problems with email addresses are found + * @throws MessagingException when message could not be send. + */ + void send() throws AddressException, MessagingException; + + /** + * Invokes the {@link #send()} method but catches any exception thrown. This + * method is intended to be used from the sendmail logicsheet. The source + * resolver is obtained from the hosting component container. + * @return true when successful + */ + boolean sendIt(); + /** * Accesses any Exception caught by {@link #sendIt(SourceResolver)}. * @return AddressException or MessagingException @@ -159,4 +176,4 @@ * @see org.apache.excalibur.source.Source */ void addAttachmentURL(String url, String type, String name); -} \ No newline at end of file +}