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