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