[jboss-cvs] jboss-seam/src/mail/org/jboss/seam/mail/ui ...
Peter Muir
peter at bleepbleep.org.uk
Fri Feb 9 15:15:13 EST 2007
User: pmuir
Date: 07/02/09 15:15:13
Modified: src/mail/org/jboss/seam/mail/ui UIBody.java
Log:
JBSEAM-805
Revision Changes Path
1.7 +60 -45 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.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- UIBody.java 8 Feb 2007 23:27:19 -0000 1.6
+++ UIBody.java 9 Feb 2007 20:15:13 -0000 1.7
@@ -12,15 +12,15 @@
import javax.mail.internet.MimeMultipart;
/**
- * JSF component for rendering the body
- * Supports plain text, html bodies and setting an alternative
- * (text) part using an alternative facet
+ * JSF component for rendering the body Supports plain text, html bodies and
+ * setting an alternative (text) part using an alternative facet
*
*/
public class UIBody extends MailComponent
{
- public static final String HTML="html";
+ public static final String HTML = "html";
+
public static final String PLAIN = "plain";
private String type = HTML;
@@ -31,34 +31,29 @@
try
{
String body = encode(facesContext);
- BodyPart bodyPart = new MimeBodyPart();
+ BodyPart bodyPart = null;
if (PLAIN.equalsIgnoreCase(type))
{
- bodyPart.setText(body);
- bodyPart.setDisposition("inline");
+ bodyPart = getTextBody(facesContext, body);
}
else if (HTML.equals(type))
{
UIComponent alternative = getFacet("alternative");
if (alternative != null)
{
- BodyPart text = new MimeBodyPart();
- text.setText(encode(facesContext,alternative));
- text.setDisposition("inline");
-
- BodyPart html = new MimeBodyPart();
- html.setContent(body, "text/html");
- html.setDisposition("inline");
Multipart multipart = new MimeMultipart("alternative");
- multipart.addBodyPart(text);
- multipart.addBodyPart(html);
+
+ multipart.addBodyPart(getTextBody(facesContext, encode(facesContext,
+ alternative)));
+ multipart.addBodyPart(getHtmlBody(facesContext, body));
+
+ bodyPart = new MimeBodyPart();
bodyPart.setContent(multipart);
}
else
{
- bodyPart.setContent(body, "text/html");
- bodyPart.setDisposition("inline");
+ bodyPart = getHtmlBody(facesContext, body);
}
}
getRootMultipart().addBodyPart(bodyPart);
@@ -86,4 +81,24 @@
return type;
}
+ private BodyPart getTextBody(FacesContext facesContext, Object body)
+ throws MessagingException
+ {
+ BodyPart bodyPart = new MimeBodyPart();
+ bodyPart.setDisposition("inline");
+ bodyPart.setContent(body, "text/plain; charset="
+ + facesContext.getResponseWriter().getCharacterEncoding() + "; format=flowed");
+ return bodyPart;
+ }
+
+ private BodyPart getHtmlBody(FacesContext facesContext, Object body)
+ throws MessagingException
+ {
+ BodyPart bodyPart = new MimeBodyPart();
+ bodyPart.setDisposition("inline");
+ bodyPart.setContent(body, "text/html; charset="
+ + facesContext.getResponseWriter().getCharacterEncoding());
+ return bodyPart;
+ }
+
}
More information about the jboss-cvs-commits
mailing list