001
014
015 package com.liferay.portlet.messageboards.util;
016
017 import com.liferay.portal.kernel.util.GetterUtil;
018 import com.liferay.portal.kernel.util.HtmlUtil;
019 import com.liferay.portal.kernel.util.ObjectValuePair;
020 import com.liferay.portal.kernel.util.Validator;
021
022 import java.io.ByteArrayInputStream;
023 import java.io.InputStream;
024
025 import java.util.ArrayList;
026 import java.util.List;
027
028
031 public class MBMailMessage {
032
033 public void addBytes(String fileName, byte[] bytes) {
034 _bytesOVPs.add(new ObjectValuePair<String, byte[]>(fileName, bytes));
035 }
036
037 public String getBody() {
038 if (Validator.isNotNull(_plainBody)) {
039 return GetterUtil.getString(_plainBody);
040 }
041 else if (Validator.isNotNull(_htmlBody)) {
042 return HtmlUtil.extractText(_htmlBody);
043 }
044 else {
045 return "-";
046 }
047 }
048
049 public String getHtmlBody() {
050 return _htmlBody;
051 }
052
053 public List<ObjectValuePair<String, InputStream>> getInputStreamOVPs() {
054 List<ObjectValuePair<String, InputStream>> inputStreamOVPs =
055 new ArrayList<ObjectValuePair<String, InputStream>>(
056 _bytesOVPs.size());
057
058 for (ObjectValuePair<String, byte[]> bytesOVP : _bytesOVPs) {
059 String key = bytesOVP.getKey();
060 byte[] bytes = bytesOVP.getValue();
061
062 ByteArrayInputStream byteArrayInputStream =
063 new ByteArrayInputStream(bytes);
064
065 ObjectValuePair<String, InputStream> inputStreamOVP =
066 new ObjectValuePair<String, InputStream>(
067 key, byteArrayInputStream);
068
069 inputStreamOVPs.add(inputStreamOVP);
070 }
071
072 return inputStreamOVPs;
073 }
074
075 public String getPlainBody() {
076 return _plainBody;
077 }
078
079 public void setHtmlBody(String htmlBody) {
080 _htmlBody = htmlBody;
081 }
082
083 public void setPlainBody(String plainBody) {
084 _plainBody = plainBody;
085 }
086
087 private List<ObjectValuePair<String, byte[]>> _bytesOVPs =
088 new ArrayList<ObjectValuePair<String, byte[]>>();
089 private String _htmlBody;
090 private String _plainBody;
091
092 }