cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeremy Quinn <jer...@media.demon.co.uk>
Subject Re: DB support in flowscript (was: XSP "official" position)
Date Thu, 20 Nov 2003 10:36:25 GMT

On 19 Nov 2003, at 19:03, Tony Collen wrote:

> Yep, this is the easy way.  I could see this being the answer to some 
> FAQ:
>
> Q: How can I easily send an email from the Flow layer?
>
> A: The simple way is to write an XSP, and call the XSP's pipeline from 
> within the Flowscript.  If you need something a little cleaner, you 
> can simply write a helper class in Java and access it from your Flow 
> as an object.
>

or:

The Flowscript:

importPackage (Packages.org.apache.cocoon.mail);

function sendMail (smtpHost, bodysrc, to, from, subject, bean) {
	var mailer = new MailMessageSender (smtpHost);
	mailer.setFrom (from);
	mailer.setTo (to);
	mailer.setSubject (subject);
	// use a JXTemplate to produce the body from the 'bean'
	var output = new Packages.java.io.ByteArrayOutputStream ();
	cocoon.processPipelineTo (bodysrc, { bean: bean }, output);
	mailer.setBody (output.toString ());
	mailer.send (null); // a null resolver, because we do not need one
}

NB. MailMessageSender can take a 'src' of a pipeline to call to get the 
email body, but it does not take a bean as a parameter. So I can do it 
like the above.

The  template:

<document xmlns:t="http://apache.org/cocoon/templates/jx/1.0">
To: #{bean/firstname} #{bean/lastname}.

You have been successfully registered with our site.

http://the.url.here

Your login is: #{bean/email}
We hope you remember your password!
</document>

The Pipeline:

<map:match pattern="mail/*">
	<map:generate type="jx" src="content/mail/{1}.xml"/>
	<map:serialize type="text"/>
</map:match>

HTH

regards Jeremy
Mime
View raw message