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.messageboards.model.impl;
022:
023: import com.liferay.portal.PortalException;
024: import com.liferay.portal.SystemException;
025: import com.liferay.portal.model.impl.CompanyImpl;
026: import com.liferay.portal.util.PortalUtil;
027: import com.liferay.portlet.messageboards.model.MBCategory;
028: import com.liferay.portlet.messageboards.model.MBMessage;
029: import com.liferay.portlet.messageboards.service.MBCategoryLocalServiceUtil;
030: import com.liferay.portlet.messageboards.service.MBThreadLocalServiceUtil;
031: import com.liferay.portlet.messageboards.util.BBCodeUtil;
032: import com.liferay.portlet.tags.service.TagsEntryLocalServiceUtil;
033:
034: import org.apache.commons.logging.Log;
035: import org.apache.commons.logging.LogFactory;
036:
037: /**
038: * <a href="MBMessageImpl.java.html"><b><i>View Source</i></b></a>
039: *
040: * @author Brian Wing Shun Chan
041: *
042: */
043: public class MBMessageImpl extends MBMessageModelImpl implements
044: MBMessage {
045:
046: public static final long DEFAULT_PARENT_MESSAGE_ID = 0;
047:
048: public MBMessageImpl() {
049: }
050:
051: public String getUserUuid() throws SystemException {
052: return PortalUtil.getUserValue(getUserId(), "uuid", _userUuid);
053: }
054:
055: public void setUserUuid(String userUuid) {
056: _userUuid = userUuid;
057: }
058:
059: public MBCategory getCategory() {
060: MBCategory category = null;
061:
062: try {
063: if (getCategoryId() == CompanyImpl.SYSTEM) {
064: category = MBCategoryLocalServiceUtil
065: .getSystemCategory();
066: } else {
067: category = MBCategoryLocalServiceUtil
068: .getCategory(getCategoryId());
069: }
070: } catch (Exception e) {
071: category = new MBCategoryImpl();
072:
073: _log.error(e);
074: }
075:
076: return category;
077: }
078:
079: public boolean isRoot() {
080: if (getParentMessageId() == DEFAULT_PARENT_MESSAGE_ID) {
081: return true;
082: } else {
083: return false;
084: }
085: }
086:
087: public boolean isReply() {
088: return !isRoot();
089: }
090:
091: public boolean isDiscussion() {
092: if (getCategoryId() == CompanyImpl.SYSTEM) {
093: return true;
094: } else {
095: return false;
096: }
097: }
098:
099: public double getPriority() throws PortalException, SystemException {
100: if (_priority == -1) {
101: _priority = MBThreadLocalServiceUtil.getThread(
102: getThreadId()).getPriority();
103: }
104: return _priority;
105: }
106:
107: public void setPriority(double priority) {
108: _priority = priority;
109: }
110:
111: public String getThreadAttachmentsDir() {
112: return "messageboards/" + getThreadId();
113: }
114:
115: public String getAttachmentsDir() {
116: if (_attachmentDirs == null) {
117: _attachmentDirs = getThreadAttachmentsDir() + "/"
118: + getMessageId();
119: }
120: return _attachmentDirs;
121: }
122:
123: public void setAttachmentsDir(String attachmentsDir) {
124: _attachmentDirs = attachmentsDir;
125: }
126:
127: public String getBody(boolean translated) {
128: if (translated) {
129: return BBCodeUtil.getHTML(getBody());
130: } else {
131: return getBody();
132: }
133: }
134:
135: public String[] getTagsEntries() throws PortalException,
136: SystemException {
137: return TagsEntryLocalServiceUtil.getEntryNames(MBMessage.class
138: .getName(), getMessageId());
139: }
140:
141: private static Log _log = LogFactory.getLog(MBMessageImpl.class);
142:
143: private String _userUuid;
144: private double _priority = -1;
145: private String _attachmentDirs;
146:
147: }
|