[jboss-cvs] jboss-seam/src/mail/org/jboss/seam/mail/ui ...
Peter Muir
peter at bleepbleep.org.uk
Fri Feb 2 16:20:41 EST 2007
User: pmuir
Date: 07/02/02 16:20:41
Modified: src/mail/org/jboss/seam/mail/ui UIMessage.java
UIBody.java MailComponent.java
Added: src/mail/org/jboss/seam/mail/ui UIAttachment.java
Log:
JBSEAM-693 Initial support for attachments to emails
Revision Changes Path
1.6 +5 -1 jboss-seam/src/mail/org/jboss/seam/mail/ui/UIMessage.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: UIMessage.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/mail/org/jboss/seam/mail/ui/UIMessage.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- UIMessage.java 28 Jan 2007 21:58:54 -0000 1.5
+++ UIMessage.java 2 Feb 2007 21:20:41 -0000 1.6
@@ -5,9 +5,11 @@
import javax.faces.FacesException;
import javax.faces.context.FacesContext;
import javax.mail.MessagingException;
+import javax.mail.Multipart;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.MimeMessage;
+import javax.mail.internet.MimeMultipart;
import org.jboss.seam.mail.MailSession;
@@ -55,9 +57,11 @@
this.session = session;
}
- public MimeMessage getMimeMessage() {
+ public MimeMessage getMimeMessage() throws MessagingException {
if (mimeMessage == null) {
mimeMessage = new MimeMessage(getMailSession());
+ Multipart root = new MimeMultipart();
+ mimeMessage.setContent(root);
}
return mimeMessage;
}
1.4 +6 -4 jboss-seam/src/mail/org/jboss/seam/mail/ui/UIBody.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: UIBody.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/mail/org/jboss/seam/mail/ui/UIBody.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- UIBody.java 25 Jan 2007 10:58:24 -0000 1.3
+++ UIBody.java 2 Feb 2007 21:20:41 -0000 1.4
@@ -32,10 +32,11 @@
try
{
String body = encode(facesContext);
- MimeMessage mimeMessage = findMimeMessage();
+
+ BodyPart bodyPart = new MimeBodyPart();
if (PLAIN.equalsIgnoreCase(type))
{
- mimeMessage.setText(body);
+ bodyPart.setText(body);
}
else if (HTML.equals(type))
{
@@ -49,13 +50,14 @@
Multipart multipart = new MimeMultipart("alternative");
multipart.addBodyPart(html);
multipart.addBodyPart(text);
- mimeMessage.setContent(multipart);
+ bodyPart.setContent(multipart);
}
else
{
- mimeMessage.setContent(body, "text/html");
+ bodyPart.setContent(body, "text/html");
}
}
+ getRootMultipart().addBodyPart(bodyPart);
}
catch (MessagingException e)
{
1.5 +2 -1 jboss-seam/src/mail/org/jboss/seam/mail/ui/MailComponent.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: MailComponent.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/mail/org/jboss/seam/mail/ui/MailComponent.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- MailComponent.java 26 Jan 2007 11:42:20 -0000 1.4
+++ MailComponent.java 2 Feb 2007 21:20:41 -0000 1.5
@@ -55,8 +55,9 @@
/**
* look up the tree for mail message
+ * @throws MessagingException
*/
- public MimeMessage findMimeMessage() {
+ public MimeMessage findMimeMessage() throws MessagingException {
UIMessage parent = (UIMessage) findParent(this, UIMessage.class);
if (parent != null)
{
1.1 date: 2007/02/02 21:20:41; author: pmuir; state: Exp;jboss-seam/src/mail/org/jboss/seam/mail/ui/UIAttachment.java
Index: UIAttachment.java
===================================================================
package org.jboss.seam.mail.ui;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.activation.FileDataSource;
import javax.activation.URLDataSource;
import javax.faces.FacesException;
import javax.faces.context.FacesContext;
import javax.mail.BodyPart;
import javax.mail.MessagingException;
import javax.mail.internet.MimeBodyPart;
import org.jboss.seam.util.Resources;
public class UIAttachment extends MailComponent
{
private Object value;
private String contentType;
public Object getValue()
{
if (value != null)
{
return value;
}
else
{
return getValue("value");
}
}
public void setValue(Object value)
{
this.value = value;
}
@Override
public void encodeBegin(FacesContext context) throws IOException
{
DataSource ds = null;
// TODO Support seam-pdf
// TODO Support byte array, input stream
// TODO Override content type, file name
try
{
if (getValue() instanceof URL)
{
URL url = (URL) getValue();
ds = new URLDataSource(url);
}
else if (getValue() instanceof File)
{
File file = (File) getValue();
ds = new FileDataSource(file);
}
else if (getValue() instanceof String)
{
String string = (String) getValue();
ds = new URLDataSource(Resources.getResource(string));
}
if (ds != null)
{
BodyPart attachment = new MimeBodyPart();
attachment.setDataHandler(new DataHandler(ds));
// TODO Make this default to just the filename
attachment.setFileName(ds.getName());
super.getRootMultipart().addBodyPart(attachment);
}
}
catch (MessagingException e)
{
throw new FacesException(e.getMessage(), e);
}
}
@Override
public void encodeChildren(FacesContext context) throws IOException
{
// No children
}
public String getContentType()
{
if (contentType == null)
{
return getString("contentType");
}
else
{
return contentType;
}
}
public void setContentType(String contentType)
{
this.contentType = contentType;
}
}
More information about the jboss-cvs-commits
mailing list