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