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