001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
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.util.ArrayList;
023    import java.util.List;
024    
025    /**
026     * @author Jorge Ferrer
027     */
028    public class MBMailMessage {
029    
030            public void addFile(String fileName, byte[] bytes) {
031                    _files.add(new ObjectValuePair<String, byte[]>(fileName, bytes));
032            }
033    
034            public List<ObjectValuePair<String, byte[]>> getFiles() {
035                    return _files;
036            }
037    
038            public String getHtmlBody() {
039                    return _htmlBody;
040            }
041    
042            public void setHtmlBody(String htmlBody) {
043                    _htmlBody = htmlBody;
044            }
045    
046            public String getPlainBody() {
047                    return _plainBody;
048            }
049    
050            public void setPlainBody(String plainBody) {
051                    _plainBody = plainBody;
052            }
053    
054            public String getBody() {
055                    if (Validator.isNotNull(_plainBody)) {
056                            return GetterUtil.getString(_plainBody);
057                    }
058                    else if (Validator.isNotNull(_htmlBody)) {
059                            return HtmlUtil.extractText(_htmlBody);
060                    }
061                    else {
062                            return "-";
063                    }
064            }
065    
066            private String _htmlBody;
067            private String _plainBody;
068            private List<ObjectValuePair<String, byte[]>> _files =
069                    new ArrayList<ObjectValuePair<String, byte[]>>();
070    
071    }