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