1
22
23 package com.liferay.portlet.mail.model;
24
25 import com.liferay.portal.kernel.util.GetterUtil;
26 import com.liferay.portal.kernel.util.StringMaker;
27 import com.liferay.portal.kernel.util.StringPool;
28 import com.liferay.portal.kernel.util.StringUtil;
29 import com.liferay.portal.kernel.util.Validator;
30 import com.liferay.util.Html;
31
32 import java.util.ArrayList;
33 import java.util.List;
34
35
41 public class MailContent {
42
43 public MailContent() {
44 }
45
46 public MailContent(String body) {
47 setHtmlBody(body);
48 }
49
50 public String getPlainBody() {
51 return GetterUtil.getString(_plainBody);
52 }
53
54 public void setPlainBody(String plainBody) {
55 _plainBody = plainBody;
56 }
57
58 public void appendPlainBody(String plainBody) {
59 if (Validator.isNull(_plainBody)) {
60 _plainBody = plainBody;
61 }
62 else {
63 _plainBody += StringPool.NEW_LINE + StringPool.NEW_LINE + plainBody;
64 }
65 }
66
67 public String getHtmlBody() {
68 if (Validator.isNotNull(_htmlBody)) {
69 return _htmlBody;
70 }
71 else {
72 String body = GetterUtil.getString(_plainBody);
73
74 if (Validator.isNotNull(body)) {
75 body = Html.escape(body);
76 body = StringUtil.replace(body, "\t", " ");
77 body = StringUtil.replace(body, " ", " ");
78 body = StringUtil.replace(body, "\n", "<BR />");
79 body =
80 "<div style=\"font-family: courier, monospace; " +
81 "font-size: 12\">" + body + "</div>";
82 }
83
84 return body;
85 }
86 }
87
88 public void setHtmlBody(String htmlBody) {
89 _htmlBody = htmlBody;
90 }
91
92 public void appendHtmlBody(String htmlBody) {
93 if (Validator.isNull(_htmlBody)) {
94 _htmlBody = htmlBody;
95 }
96 else {
97 _htmlBody += "<HR/>" + htmlBody;
98 }
99 }
100
101 public List getSubContent() {
102 return _subContent;
103 }
104
105 public void appendSubContent(MailContent mc) {
106 _subContent.add(mc);
107 }
108
109 public String toString() {
110 StringMaker sm = new StringMaker();
111
112 sm.append(getHtmlBody());
113
114 for (int i = 0; i < _subContent.size(); i++) {
115 sm.append("<HR/>" + _subContent.get(i).toString());
116 }
117
118 return sm.toString();
119 }
120
121 private String _plainBody;
122 private String _htmlBody;
123 private List _subContent = new ArrayList();
124
125 }