You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by sy...@apache.org on 2004/09/23 14:40:49 UTC
svn commit: rev 47100 - in cocoon/branches/BRANCH_2_1_X: . src/blocks/mail/java/org/apache/cocoon/mail
Author: sylvain
Date: Thu Sep 23 05:40:49 2004
New Revision: 47100
Modified:
cocoon/branches/BRANCH_2_1_X/src/blocks/mail/java/org/apache/cocoon/mail/MailMessageSender.java
cocoon/branches/BRANCH_2_1_X/src/blocks/mail/java/org/apache/cocoon/mail/MailSender.java
cocoon/branches/BRANCH_2_1_X/status.xml
Log:
MailSender now gets the SourceResolver from the ServiceManager, thus easing its use in flowscript
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/mail/java/org/apache/cocoon/mail/MailMessageSender.java
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/mail/java/org/apache/cocoon/mail/MailMessageSender.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/mail/java/org/apache/cocoon/mail/MailMessageSender.java Thu Sep 23 05:40:49 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 <a href="mailto:frank.ridderbusch@gmx.de">Frank Ridderbusch</a>
* @author <a href="mailto:haul@apache.org">Christian Haul</a>
* @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/branches/BRANCH_2_1_X/src/blocks/mail/java/org/apache/cocoon/mail/MailSender.java
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/mail/java/org/apache/cocoon/mail/MailSender.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/mail/java/org/apache/cocoon/mail/MailSender.java Thu Sep 23 05:40:49 2004
@@ -23,7 +23,7 @@
* and the <CODE>sendmail.xsl</CODE> logicsheet for sending an email message.
*
* @author <a href="mailto:haul@apache.org">Christian Haul</a>
- * @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
+}
Modified: cocoon/branches/BRANCH_2_1_X/status.xml
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/status.xml (original)
+++ cocoon/branches/BRANCH_2_1_X/status.xml Thu Sep 23 05:40:49 2004
@@ -204,6 +204,10 @@
<changes>
<release version="@version@" date="@date@">
+ <action dev="SW" type="update">
+ Mail block: the MailSender now gets its source resolver from the service manager.
+ This allows its use from flowscript where the old SourceResolver is not available.
+ </action>
<action dev="VG" type="fix">
AbstractSAXTransformer namespaceURI and defaultNamespaceURI must never
be null. When extending AbstractSAXTransformer make sure to set