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