1
22
23 package com.liferay.portlet.messageboards.model.impl;
24
25 import com.liferay.documentlibrary.NoSuchDirectoryException;
26 import com.liferay.documentlibrary.service.DLServiceUtil;
27 import com.liferay.portal.PortalException;
28 import com.liferay.portal.SystemException;
29 import com.liferay.portal.kernel.log.Log;
30 import com.liferay.portal.kernel.log.LogFactoryUtil;
31 import com.liferay.portal.model.CompanyConstants;
32 import com.liferay.portal.util.PortalUtil;
33 import com.liferay.portlet.messageboards.model.MBCategory;
34 import com.liferay.portlet.messageboards.model.MBMessage;
35 import com.liferay.portlet.messageboards.model.MBThread;
36 import com.liferay.portlet.messageboards.service.MBCategoryLocalServiceUtil;
37 import com.liferay.portlet.messageboards.service.MBThreadLocalServiceUtil;
38 import com.liferay.portlet.messageboards.util.BBCodeUtil;
39 import com.liferay.portlet.tags.service.TagsEntryLocalServiceUtil;
40
41
47 public class MBMessageImpl extends MBMessageModelImpl implements MBMessage {
48
49 public static final long DEFAULT_PARENT_MESSAGE_ID = 0;
50
51 public MBMessageImpl() {
52 }
53
54 public String getUserUuid() throws SystemException {
55 return PortalUtil.getUserValue(getUserId(), "uuid", _userUuid);
56 }
57
58 public void setUserUuid(String userUuid) {
59 _userUuid = userUuid;
60 }
61
62 public MBCategory getCategory() {
63 MBCategory category = null;
64
65 try {
66 if (getCategoryId() == CompanyConstants.SYSTEM) {
67 category = MBCategoryLocalServiceUtil.getSystemCategory();
68 }
69 else {
70 category = MBCategoryLocalServiceUtil.getCategory(
71 getCategoryId());
72 }
73 }
74 catch (Exception e) {
75 category = new MBCategoryImpl();
76
77 _log.error(e);
78 }
79
80 return category;
81 }
82
83 public MBThread getThread() throws PortalException, SystemException {
84 return MBThreadLocalServiceUtil.getThread(getThreadId());
85 }
86
87 public boolean isRoot() {
88 if (getParentMessageId() == DEFAULT_PARENT_MESSAGE_ID) {
89 return true;
90 }
91 else {
92 return false;
93 }
94 }
95
96 public boolean isReply() {
97 return !isRoot();
98 }
99
100 public boolean isDiscussion() {
101 if (getCategoryId() == CompanyConstants.SYSTEM) {
102 return true;
103 }
104 else {
105 return false;
106 }
107 }
108
109 public String getBody(boolean translate) {
110 String body = null;
111
112 if (translate) {
113 body = BBCodeUtil.getHTML(this);
114 }
115 else {
116 body = getBody();
117 }
118
119 return body;
120 }
121
122 public String getThreadAttachmentsDir() {
123 return "messageboards/" + getThreadId();
124 }
125
126 public String getAttachmentsDir() {
127 if (_attachmentDirs == null) {
128 _attachmentDirs = getThreadAttachmentsDir() + "/" + getMessageId();
129 }
130
131 return _attachmentDirs;
132 }
133
134 public void setAttachmentsDir(String attachmentsDir) {
135 _attachmentDirs = attachmentsDir;
136 }
137
138 public String[] getAttachmentsFiles()
139 throws PortalException, SystemException {
140
141 String[] fileNames = new String[0];
142
143 try {
144 fileNames = DLServiceUtil.getFileNames(
145 getCompanyId(), CompanyConstants.SYSTEM, getAttachmentsDir());
146 }
147 catch (NoSuchDirectoryException nsde) {
148 }
149
150 return fileNames;
151 }
152
153 public String[] getTagsEntries() throws SystemException {
154 return TagsEntryLocalServiceUtil.getEntryNames(
155 MBMessage.class.getName(), getMessageId());
156 }
157
158 private static Log _log = LogFactoryUtil.getLog(MBMessageImpl.class);
159
160 private String _userUuid;
161 private String _attachmentDirs;
162
163 }