001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portlet.mail.model;
022:
023: import com.liferay.portal.kernel.util.GetterUtil;
024: import com.liferay.portal.kernel.util.StringMaker;
025: import com.liferay.portal.kernel.util.StringPool;
026: import com.liferay.portal.kernel.util.StringUtil;
027: import com.liferay.portal.kernel.util.Validator;
028: import com.liferay.util.Html;
029:
030: import java.util.ArrayList;
031: import java.util.List;
032:
033: /**
034: * <a href="MailContent.java.html"><b><i>View Source</i></b></a>
035: *
036: * @author Alexander Chow
037: *
038: */
039: public class MailContent {
040:
041: public MailContent() {
042: }
043:
044: public MailContent(String body) {
045: setHtmlBody(body);
046: }
047:
048: public String getPlainBody() {
049: return GetterUtil.getString(_plainBody);
050: }
051:
052: public void setPlainBody(String plainBody) {
053: _plainBody = plainBody;
054: }
055:
056: public void appendPlainBody(String plainBody) {
057: if (Validator.isNull(_plainBody)) {
058: _plainBody = plainBody;
059: } else {
060: _plainBody += StringPool.NEW_LINE + StringPool.NEW_LINE
061: + plainBody;
062: }
063: }
064:
065: public String getHtmlBody() {
066: if (Validator.isNotNull(_htmlBody)) {
067: return _htmlBody;
068: } else {
069: String body = GetterUtil.getString(_plainBody);
070:
071: if (Validator.isNotNull(body)) {
072: body = Html.escape(body);
073: body = StringUtil.replace(body, "\t", " ");
074: body = StringUtil.replace(body, " ", " ");
075: body = StringUtil.replace(body, "\n", "<BR />");
076: body = "<div style=\"font-family: courier, monospace; "
077: + "font-size: 12\">" + body + "</div>";
078: }
079:
080: return body;
081: }
082: }
083:
084: public void setHtmlBody(String htmlBody) {
085: _htmlBody = htmlBody;
086: }
087:
088: public void appendHtmlBody(String htmlBody) {
089: if (Validator.isNull(_htmlBody)) {
090: _htmlBody = htmlBody;
091: } else {
092: _htmlBody += "<HR/>" + htmlBody;
093: }
094: }
095:
096: public List getSubContent() {
097: return _subContent;
098: }
099:
100: public void appendSubContent(MailContent mc) {
101: _subContent.add(mc);
102: }
103:
104: public String toString() {
105: StringMaker sm = new StringMaker();
106:
107: sm.append(getHtmlBody());
108:
109: for (int i = 0; i < _subContent.size(); i++) {
110: sm.append("<HR/>" + _subContent.get(i).toString());
111: }
112:
113: return sm.toString();
114: }
115:
116: private String _plainBody;
117: private String _htmlBody;
118: private List _subContent = new ArrayList();
119:
120: }
|