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