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 import java.rmi.RemoteException;
33
34
39 public class MBMessageImpl extends MBMessageModelImpl implements MBMessage {
40
41 public static final long DEFAULT_PARENT_MESSAGE_ID = 0;
42
43 public MBMessageImpl() {
44 }
45
46 public String getAttachmentsDir() {
47 if (_attachmentDirs == null) {
48 _attachmentDirs = getThreadAttachmentsDir() + "/" + getMessageId();
49 }
50
51 return _attachmentDirs;
52 }
53
54 public String[] getAttachmentsFiles()
55 throws PortalException, SystemException {
56
57 String[] fileNames = new String[0];
58
59 try {
60 fileNames = DLServiceUtil.getFileNames(
61 getCompanyId(), CompanyConstants.SYSTEM, getAttachmentsDir());
62 }
63 catch (NoSuchDirectoryException nsde) {
64 }
65 catch (RemoteException re) {
66 _log.error(re);
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 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 return category;
104 }
105
106 public String[] getTagsEntries() throws SystemException {
107 return TagsEntryLocalServiceUtil.getEntryNames(
108 MBMessage.class.getName(), getMessageId());
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() == CompanyConstants.SYSTEM) {
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() == DEFAULT_PARENT_MESSAGE_ID) {
134 return true;
135 }
136 else {
137 return false;
138 }
139 }
140
141 public void setAttachmentsDir(String attachmentsDir) {
142 _attachmentDirs = attachmentsDir;
143 }
144
145 private static Log _log = LogFactoryUtil.getLog(MBMessageImpl.class);
146
147 private String _attachmentDirs;
148
149 }