001
014
015 package com.liferay.portlet.messageboards.model.impl;
016
017 import com.liferay.portal.kernel.exception.PortalException;
018 import com.liferay.portal.kernel.exception.SystemException;
019 import com.liferay.portal.kernel.log.Log;
020 import com.liferay.portal.kernel.log.LogFactoryUtil;
021 import com.liferay.portal.kernel.parsers.bbcode.BBCodeTranslatorUtil;
022 import com.liferay.portal.model.CompanyConstants;
023 import com.liferay.portlet.asset.service.AssetTagLocalServiceUtil;
024 import com.liferay.portlet.documentlibrary.NoSuchDirectoryException;
025 import com.liferay.portlet.documentlibrary.store.DLStoreUtil;
026 import com.liferay.portlet.messageboards.model.MBCategory;
027 import com.liferay.portlet.messageboards.model.MBCategoryConstants;
028 import com.liferay.portlet.messageboards.model.MBDiscussion;
029 import com.liferay.portlet.messageboards.model.MBMessage;
030 import com.liferay.portlet.messageboards.model.MBMessageConstants;
031 import com.liferay.portlet.messageboards.model.MBThread;
032 import com.liferay.portlet.messageboards.service.MBCategoryLocalServiceUtil;
033 import com.liferay.portlet.messageboards.service.MBThreadLocalServiceUtil;
034
035
038 public class MBMessageImpl extends MBMessageBaseImpl {
039
040 public MBMessageImpl() {
041 }
042
043 public String[] getAssetTagNames() throws SystemException {
044 return AssetTagLocalServiceUtil.getTagNames(
045 MBMessage.class.getName(), getMessageId());
046 }
047
048 public String getAttachmentsDir() {
049 if (_attachmentDirs == null) {
050 _attachmentDirs = getThreadAttachmentsDir() + "/" + getMessageId();
051 }
052
053 return _attachmentDirs;
054 }
055
056 public String[] getAttachmentsFiles()
057 throws PortalException, SystemException {
058
059 String[] fileNames = new String[0];
060
061 try {
062 fileNames = DLStoreUtil.getFileNames(
063 getCompanyId(), CompanyConstants.SYSTEM, getAttachmentsDir());
064 }
065 catch (NoSuchDirectoryException nsde) {
066 }
067
068 return fileNames;
069 }
070
071 public String getBody(boolean translate) {
072 String body = null;
073
074 if (translate) {
075 body = BBCodeTranslatorUtil.getHTML(getBody());
076 }
077 else {
078 body = getBody();
079 }
080
081 return body;
082 }
083
084 public MBCategory getCategory() {
085 MBCategory category = null;
086
087 long categoryId = getCategoryId();
088
089 try {
090 category = MBCategoryLocalServiceUtil.getCategory(categoryId);
091 }
092 catch (Exception e) {
093 category = new MBCategoryImpl();
094
095 category.setCategoryId(getCategoryId());
096
097 _log.error(e);
098 }
099
100 return category;
101 }
102
103 public MBThread getThread() throws PortalException, SystemException {
104 return MBThreadLocalServiceUtil.getThread(getThreadId());
105 }
106
107 public String getThreadAttachmentsDir() {
108 return "messageboards/" + getThreadId();
109 }
110
111 public String getWorkflowClassName() {
112 if (isDiscussion()) {
113 return MBDiscussion.class.getName();
114 }
115 else {
116 return MBMessage.class.getName();
117 }
118 }
119
120 public boolean isDiscussion() {
121 if (getCategoryId() == MBCategoryConstants.DISCUSSION_CATEGORY_ID) {
122 return true;
123 }
124 else {
125 return false;
126 }
127 }
128
129 public boolean isFormatBBCode() {
130 String format = getFormat();
131
132 if (format.equals("bbcode")) {
133 return true;
134 }
135 else {
136 return false;
137 }
138 }
139
140 public boolean isReply() {
141 return !isRoot();
142 }
143
144 public boolean isRoot() {
145 if (getParentMessageId() ==
146 MBMessageConstants.DEFAULT_PARENT_MESSAGE_ID) {
147
148 return true;
149 }
150 else {
151 return false;
152 }
153 }
154
155 public void setAttachmentsDir(String attachmentsDir) {
156 _attachmentDirs = attachmentsDir;
157 }
158
159 private static Log _log = LogFactoryUtil.getLog(MBMessageImpl.class);
160
161 private String _attachmentDirs;
162
163 }