1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portlet.messageboards.service.impl;
21  
22  import com.liferay.portal.PortalException;
23  import com.liferay.portal.SystemException;
24  import com.liferay.portal.kernel.log.Log;
25  import com.liferay.portal.kernel.log.LogFactoryUtil;
26  import com.liferay.portal.kernel.util.GetterUtil;
27  import com.liferay.portal.kernel.util.HtmlUtil;
28  import com.liferay.portal.kernel.util.ObjectValuePair;
29  import com.liferay.portal.kernel.util.StringPool;
30  import com.liferay.portal.kernel.util.StringUtil;
31  import com.liferay.portal.model.Company;
32  import com.liferay.portal.model.User;
33  import com.liferay.portal.security.auth.PrincipalException;
34  import com.liferay.portal.security.permission.ActionKeys;
35  import com.liferay.portal.theme.ThemeDisplay;
36  import com.liferay.portal.util.PortalUtil;
37  import com.liferay.portal.util.PropsKeys;
38  import com.liferay.portal.util.PropsUtil;
39  import com.liferay.portlet.messageboards.model.MBCategory;
40  import com.liferay.portlet.messageboards.model.MBMessage;
41  import com.liferay.portlet.messageboards.model.MBMessageDisplay;
42  import com.liferay.portlet.messageboards.model.MBThread;
43  import com.liferay.portlet.messageboards.model.impl.MBThreadImpl;
44  import com.liferay.portlet.messageboards.service.base.MBMessageServiceBaseImpl;
45  import com.liferay.portlet.messageboards.service.permission.MBCategoryPermission;
46  import com.liferay.portlet.messageboards.service.permission.MBDiscussionPermission;
47  import com.liferay.portlet.messageboards.service.permission.MBMessagePermission;
48  import com.liferay.portlet.messageboards.util.BBCodeUtil;
49  import com.liferay.portlet.messageboards.util.comparator.MessageCreateDateComparator;
50  import com.liferay.util.RSSUtil;
51  
52  import com.sun.syndication.feed.synd.SyndContent;
53  import com.sun.syndication.feed.synd.SyndContentImpl;
54  import com.sun.syndication.feed.synd.SyndEntry;
55  import com.sun.syndication.feed.synd.SyndEntryImpl;
56  import com.sun.syndication.feed.synd.SyndFeed;
57  import com.sun.syndication.feed.synd.SyndFeedImpl;
58  import com.sun.syndication.io.FeedException;
59  
60  import java.util.ArrayList;
61  import java.util.Iterator;
62  import java.util.List;
63  
64  import javax.portlet.PortletPreferences;
65  
66  /**
67   * <a href="MBMessageServiceImpl.java.html"><b><i>View Source</i></b></a>
68   *
69   * @author Brian Wing Shun Chan
70   *
71   */
72  public class MBMessageServiceImpl extends MBMessageServiceBaseImpl {
73  
74      public MBMessage addDiscussionMessage(
75              long groupId, String className, long classPK, long threadId,
76              long parentMessageId, String subject, String body,
77              ThemeDisplay themeDisplay)
78          throws PortalException, SystemException {
79  
80          User user = getUser();
81  
82          MBDiscussionPermission.check(
83              getPermissionChecker(), user.getCompanyId(), groupId, className,
84              classPK, user.getUserId(), ActionKeys.ADD_DISCUSSION);
85  
86          return mbMessageLocalService.addDiscussionMessage(
87              getUserId(), null, groupId, className, classPK, threadId,
88              parentMessageId, subject, body, themeDisplay);
89      }
90  
91      public MBMessage addMessage(
92              long categoryId, String subject, String body,
93              List<ObjectValuePair<String, byte[]>> files, boolean anonymous,
94              double priority, String[] tagsEntries,
95              boolean addCommunityPermissions, boolean addGuestPermissions)
96          throws PortalException, SystemException {
97  
98          MBCategoryPermission.check(
99              getPermissionChecker(), categoryId, ActionKeys.ADD_MESSAGE);
100 
101         if (!MBCategoryPermission.contains(
102                 getPermissionChecker(), categoryId, ActionKeys.ADD_FILE)) {
103 
104             files.clear();
105         }
106 
107         if (!MBCategoryPermission.contains(
108                 getPermissionChecker(), categoryId,
109                 ActionKeys.UPDATE_THREAD_PRIORITY)) {
110 
111             priority = MBThreadImpl.PRIORITY_NOT_GIVEN;
112         }
113 
114         return mbMessageLocalService.addMessage(
115             getGuestOrUserId(), null, categoryId, subject, body, files,
116             anonymous, priority, tagsEntries, null, addCommunityPermissions,
117             addGuestPermissions, null);
118     }
119 
120     public MBMessage addMessage(
121             long categoryId, String subject, String body,
122             List<ObjectValuePair<String, byte[]>> files, boolean anonymous,
123             double priority, String[] tagsEntries,
124             String[] communityPermissions, String[] guestPermissions)
125         throws PortalException, SystemException {
126 
127         MBCategoryPermission.check(
128             getPermissionChecker(), categoryId, ActionKeys.ADD_MESSAGE);
129 
130         if (!MBCategoryPermission.contains(
131                 getPermissionChecker(), categoryId, ActionKeys.ADD_FILE)) {
132 
133             files.clear();
134         }
135 
136         if (!MBCategoryPermission.contains(
137                 getPermissionChecker(), categoryId,
138                 ActionKeys.UPDATE_THREAD_PRIORITY)) {
139 
140             priority = MBThreadImpl.PRIORITY_NOT_GIVEN;
141         }
142 
143         return mbMessageLocalService.addMessage(
144             getGuestOrUserId(), null, categoryId, subject, body, files,
145             anonymous, priority, tagsEntries, null, communityPermissions,
146             guestPermissions, null);
147     }
148 
149     public MBMessage addMessage(
150             long categoryId, String subject, String body,
151             List<ObjectValuePair<String, byte[]>> files, boolean anonymous,
152             double priority, String[] tagsEntries, PortletPreferences prefs,
153             boolean addCommunityPermissions, boolean addGuestPermissions,
154             ThemeDisplay themeDisplay)
155         throws PortalException, SystemException {
156 
157         MBCategoryPermission.check(
158             getPermissionChecker(), categoryId, ActionKeys.ADD_MESSAGE);
159 
160         if (!MBCategoryPermission.contains(
161                 getPermissionChecker(), categoryId, ActionKeys.ADD_FILE)) {
162 
163             files.clear();
164         }
165 
166         if (!MBCategoryPermission.contains(
167                 getPermissionChecker(), categoryId,
168                 ActionKeys.UPDATE_THREAD_PRIORITY)) {
169 
170             priority = MBThreadImpl.PRIORITY_NOT_GIVEN;
171         }
172 
173         return mbMessageLocalService.addMessage(
174             getGuestOrUserId(), null, categoryId, subject, body, files,
175             anonymous, priority, tagsEntries, prefs, addCommunityPermissions,
176             addGuestPermissions, themeDisplay);
177     }
178 
179     public MBMessage addMessage(
180             long categoryId, String subject, String body,
181             List<ObjectValuePair<String, byte[]>> files, boolean anonymous,
182             double priority, String[] tagsEntries, PortletPreferences prefs,
183             String[] communityPermissions, String[] guestPermissions,
184             ThemeDisplay themeDisplay)
185         throws PortalException, SystemException {
186 
187         MBCategoryPermission.check(
188             getPermissionChecker(), categoryId, ActionKeys.ADD_MESSAGE);
189 
190         if (!MBCategoryPermission.contains(
191                 getPermissionChecker(), categoryId, ActionKeys.ADD_FILE)) {
192 
193             files.clear();
194         }
195 
196         if (!MBCategoryPermission.contains(
197                 getPermissionChecker(), categoryId,
198                 ActionKeys.UPDATE_THREAD_PRIORITY)) {
199 
200             priority = MBThreadImpl.PRIORITY_NOT_GIVEN;
201         }
202 
203         return mbMessageLocalService.addMessage(
204             getGuestOrUserId(), null, categoryId, subject, body, files,
205             anonymous, priority, tagsEntries, prefs, communityPermissions,
206             guestPermissions, themeDisplay);
207     }
208 
209     public MBMessage addMessage(
210             long categoryId, long threadId, long parentMessageId,
211             String subject, String body,
212             List<ObjectValuePair<String, byte[]>> files, boolean anonymous,
213             double priority, String[] tagsEntries,
214             boolean addCommunityPermissions, boolean addGuestPermissions)
215         throws PortalException, SystemException {
216 
217         checkReplyToPermission(categoryId, parentMessageId);
218 
219         if (!MBCategoryPermission.contains(
220                 getPermissionChecker(), categoryId, ActionKeys.ADD_FILE)) {
221 
222             files.clear();
223         }
224 
225         if (!MBCategoryPermission.contains(
226                 getPermissionChecker(), categoryId,
227                 ActionKeys.UPDATE_THREAD_PRIORITY)) {
228 
229             priority = MBThreadImpl.PRIORITY_NOT_GIVEN;
230         }
231 
232         return mbMessageLocalService.addMessage(
233             getGuestOrUserId(), null, categoryId, threadId, parentMessageId,
234             subject, body, files, anonymous, priority, tagsEntries, null,
235             addCommunityPermissions, addGuestPermissions, null);
236     }
237 
238     public MBMessage addMessage(
239             long categoryId, long threadId, long parentMessageId,
240             String subject, String body,
241             List<ObjectValuePair<String, byte[]>> files, boolean anonymous,
242             double priority, String[] tagsEntries,
243             String[] communityPermissions, String[] guestPermissions)
244         throws PortalException, SystemException {
245 
246         checkReplyToPermission(categoryId, parentMessageId);
247 
248         if (!MBCategoryPermission.contains(
249                 getPermissionChecker(), categoryId, ActionKeys.ADD_FILE)) {
250 
251             files.clear();
252         }
253 
254         if (!MBCategoryPermission.contains(
255                 getPermissionChecker(), categoryId,
256                 ActionKeys.UPDATE_THREAD_PRIORITY)) {
257 
258             priority = MBThreadImpl.PRIORITY_NOT_GIVEN;
259         }
260 
261         return mbMessageLocalService.addMessage(
262             getGuestOrUserId(), null, categoryId, threadId, parentMessageId,
263             subject, body, files, anonymous, priority, tagsEntries, null,
264             communityPermissions, guestPermissions, null);
265     }
266 
267     public MBMessage addMessage(
268             long categoryId, long threadId, long parentMessageId,
269             String subject, String body,
270             List<ObjectValuePair<String, byte[]>> files, boolean anonymous,
271             double priority, String[] tagsEntries, PortletPreferences prefs,
272             boolean addCommunityPermissions, boolean addGuestPermissions,
273             ThemeDisplay themeDisplay)
274         throws PortalException, SystemException {
275 
276         checkReplyToPermission(categoryId, parentMessageId);
277 
278         if (!MBCategoryPermission.contains(
279                 getPermissionChecker(), categoryId, ActionKeys.ADD_FILE)) {
280 
281             files.clear();
282         }
283 
284         if (!MBCategoryPermission.contains(
285                 getPermissionChecker(), categoryId,
286                 ActionKeys.UPDATE_THREAD_PRIORITY)) {
287 
288             priority = MBThreadImpl.PRIORITY_NOT_GIVEN;
289         }
290 
291         return mbMessageLocalService.addMessage(
292             getGuestOrUserId(), null, categoryId, threadId, parentMessageId,
293             subject, body, files, anonymous, priority, tagsEntries, prefs,
294             addCommunityPermissions, addGuestPermissions, themeDisplay);
295     }
296 
297     public MBMessage addMessage(
298             long categoryId, long threadId, long parentMessageId,
299             String subject, String body,
300             List<ObjectValuePair<String, byte[]>> files, boolean anonymous,
301             double priority, String[] tagsEntries, PortletPreferences prefs,
302             String[] communityPermissions, String[] guestPermissions,
303             ThemeDisplay themeDisplay)
304         throws PortalException, SystemException {
305 
306         checkReplyToPermission(categoryId, parentMessageId);
307 
308         if (!MBCategoryPermission.contains(
309                 getPermissionChecker(), categoryId, ActionKeys.ADD_FILE)) {
310 
311             files.clear();
312         }
313 
314         if (!MBCategoryPermission.contains(
315                 getPermissionChecker(), categoryId,
316                 ActionKeys.UPDATE_THREAD_PRIORITY)) {
317 
318             priority = MBThreadImpl.PRIORITY_NOT_GIVEN;
319         }
320 
321         return mbMessageLocalService.addMessage(
322             getGuestOrUserId(), null, categoryId, threadId, parentMessageId,
323             subject, body, files, anonymous, priority, tagsEntries, prefs,
324             communityPermissions, guestPermissions, themeDisplay);
325     }
326 
327     public void deleteDiscussionMessage(
328             long groupId, String className, long classPK, long messageId)
329         throws PortalException, SystemException {
330 
331         User user = getUser();
332 
333         MBDiscussionPermission.check(
334             getPermissionChecker(), user.getCompanyId(), groupId, className,
335             classPK, messageId, user.getUserId(), ActionKeys.DELETE_DISCUSSION);
336 
337         mbMessageLocalService.deleteDiscussionMessage(messageId);
338     }
339 
340     public void deleteMessage(long messageId)
341         throws PortalException, SystemException {
342 
343         MBMessagePermission.check(
344             getPermissionChecker(), messageId, ActionKeys.DELETE);
345 
346         mbMessageLocalService.deleteMessage(messageId);
347     }
348 
349     public List<MBMessage> getCategoryMessages(
350             long categoryId, int start, int end)
351         throws PortalException, SystemException {
352 
353         List<MBMessage> messages = new ArrayList<MBMessage>();
354 
355         Iterator<MBMessage> itr = mbMessageLocalService.getCategoryMessages(
356             categoryId, start, end).iterator();
357 
358         while (itr.hasNext()) {
359             MBMessage message = itr.next();
360 
361             if (MBMessagePermission.contains(
362                     getPermissionChecker(), message, ActionKeys.VIEW)) {
363 
364                 messages.add(message);
365             }
366         }
367 
368         return messages;
369     }
370 
371     public int getCategoryMessagesCount(long categoryId)
372         throws SystemException {
373 
374         return mbMessageLocalService.getCategoryMessagesCount(categoryId);
375     }
376 
377     public String getCategoryMessagesRSS(
378             long categoryId, int max, String type, double version,
379             String displayStyle, String feedURL, String entryURL,
380             ThemeDisplay themeDisplay)
381         throws PortalException, SystemException {
382 
383         MBCategory category = mbCategoryLocalService.getCategory(
384             categoryId);
385 
386         String name = category.getName();
387         String description = category.getDescription();
388 
389         List<MBMessage> messages = new ArrayList<MBMessage>();
390 
391         int lastIntervalStart = 0;
392         boolean listNotExhausted = true;
393         MessageCreateDateComparator comparator =
394             new MessageCreateDateComparator(false, false);
395 
396         while ((messages.size() < max) && listNotExhausted) {
397             List<MBMessage> messageList =
398                 mbMessageLocalService.getCategoryMessages(
399                     categoryId, lastIntervalStart, lastIntervalStart + max,
400                     comparator);
401 
402             Iterator<MBMessage> itr = messageList.iterator();
403 
404             lastIntervalStart += max;
405             listNotExhausted = (messageList.size() == max);
406 
407             while (itr.hasNext() && (messages.size() < max)) {
408                 MBMessage message = itr.next();
409 
410                 if (MBMessagePermission.contains(
411                         getPermissionChecker(), message, ActionKeys.VIEW)) {
412 
413                     messages.add(message);
414                 }
415             }
416         }
417 
418         return exportToRSS(
419             name, description, type, version, displayStyle, feedURL, entryURL,
420             messages, themeDisplay);
421     }
422 
423     public String getCompanyMessagesRSS(
424             long companyId, int max, String type, double version,
425             String displayStyle, String feedURL, String entryURL,
426             ThemeDisplay themeDisplay)
427         throws PortalException, SystemException {
428 
429         Company company = companyPersistence.findByPrimaryKey(companyId);
430 
431         String name = company.getName();
432         String description = company.getName();
433 
434         List<MBMessage> messages = new ArrayList<MBMessage>();
435 
436         int lastIntervalStart = 0;
437         boolean listNotExhausted = true;
438         MessageCreateDateComparator comparator =
439             new MessageCreateDateComparator(false, false);
440 
441         while ((messages.size() < max) && listNotExhausted) {
442             List<MBMessage> messageList =
443                 mbMessageLocalService.getCompanyMessages(
444                     companyId, lastIntervalStart, lastIntervalStart + max,
445                     comparator);
446 
447             Iterator<MBMessage> itr = messageList.iterator();
448 
449             lastIntervalStart += max;
450             listNotExhausted = (messageList.size() == max);
451 
452             while (itr.hasNext() && (messages.size() < max)) {
453                 MBMessage message = itr.next();
454 
455                 if (MBMessagePermission.contains(
456                         getPermissionChecker(), message, ActionKeys.VIEW)) {
457 
458                     messages.add(message);
459                 }
460             }
461         }
462 
463         return exportToRSS(
464             name, description, type, version, displayStyle, feedURL, entryURL,
465             messages, themeDisplay);
466     }
467 
468     public String getGroupMessagesRSS(
469             long groupId, int max, String type, double version,
470             String displayStyle, String feedURL, String entryURL,
471             ThemeDisplay themeDisplay)
472         throws PortalException, SystemException {
473 
474         String name = StringPool.BLANK;
475         String description = StringPool.BLANK;
476 
477         List<MBMessage> messages = new ArrayList<MBMessage>();
478 
479         int lastIntervalStart = 0;
480         boolean listNotExhausted = true;
481         MessageCreateDateComparator comparator =
482             new MessageCreateDateComparator(false, true);
483 
484         while ((messages.size() < max) && listNotExhausted) {
485             List<MBMessage> messageList =
486                 mbMessageLocalService.getGroupMessages(
487                     groupId, lastIntervalStart, lastIntervalStart + max,
488                     comparator);
489 
490             Iterator<MBMessage> itr = messageList.iterator();
491 
492             lastIntervalStart += max;
493             listNotExhausted = (messageList.size() == max);
494 
495             while (itr.hasNext() && (messages.size() < max)) {
496                 MBMessage message = itr.next();
497 
498                 if (MBMessagePermission.contains(
499                         getPermissionChecker(), message, ActionKeys.VIEW)) {
500 
501                     messages.add(message);
502                 }
503             }
504         }
505 
506         if (messages.size() > 0) {
507             MBMessage message = messages.get(messages.size() - 1);
508 
509             name = message.getSubject();
510             description = message.getSubject();
511         }
512 
513         return exportToRSS(
514             name, description, type, version, displayStyle, feedURL, entryURL,
515             messages, themeDisplay);
516     }
517 
518     public String getGroupMessagesRSS(
519             long groupId, long userId, int max, String type, double version,
520             String displayStyle, String feedURL, String entryURL,
521             ThemeDisplay themeDisplay)
522         throws PortalException, SystemException {
523 
524         String name = StringPool.BLANK;
525         String description = StringPool.BLANK;
526 
527         List<MBMessage> messages = new ArrayList<MBMessage>();
528 
529         int lastIntervalStart = 0;
530         boolean listNotExhausted = true;
531         MessageCreateDateComparator comparator =
532             new MessageCreateDateComparator(false, true);
533 
534         while ((messages.size() < max) && listNotExhausted) {
535             List<MBMessage> messageList =
536                 mbMessageLocalService.getGroupMessages(
537                     groupId, userId, lastIntervalStart, lastIntervalStart + max,
538                     comparator);
539 
540             Iterator<MBMessage> itr = messageList.iterator();
541 
542             lastIntervalStart += max;
543             listNotExhausted = (messageList.size() == max);
544 
545             while (itr.hasNext() && (messages.size() < max)) {
546                 MBMessage message = itr.next();
547 
548                 if (MBMessagePermission.contains(
549                         getPermissionChecker(), message, ActionKeys.VIEW)) {
550 
551                     messages.add(message);
552                 }
553             }
554         }
555 
556         if (messages.size() > 0) {
557             MBMessage message = messages.get(messages.size() - 1);
558 
559             name = message.getSubject();
560             description = message.getSubject();
561         }
562 
563         return exportToRSS(
564             name, description, type, version, displayStyle, feedURL, entryURL,
565             messages, themeDisplay);
566     }
567 
568     public MBMessage getMessage(long messageId)
569         throws PortalException, SystemException {
570 
571         MBMessagePermission.check(
572             getPermissionChecker(), messageId, ActionKeys.VIEW);
573 
574         return mbMessageLocalService.getMessage(messageId);
575     }
576 
577     public MBMessageDisplay getMessageDisplay(long messageId)
578         throws PortalException, SystemException {
579 
580         MBMessagePermission.check(
581             getPermissionChecker(), messageId, ActionKeys.VIEW);
582 
583         return mbMessageLocalService.getMessageDisplay(messageId);
584     }
585 
586     public String getThreadMessagesRSS(
587             long threadId, int max, String type, double version,
588             String displayStyle, String feedURL, String entryURL,
589             ThemeDisplay themeDisplay)
590         throws PortalException, SystemException {
591 
592         String name = StringPool.BLANK;
593         String description = StringPool.BLANK;
594 
595         List<MBMessage> messages = new ArrayList<MBMessage>();
596 
597         MessageCreateDateComparator comparator =
598             new MessageCreateDateComparator(false, true);
599 
600         Iterator<MBMessage> itr = mbMessageLocalService.getThreadMessages(
601             threadId, comparator).iterator();
602 
603         while (itr.hasNext() && (messages.size() < max)) {
604             MBMessage message = itr.next();
605 
606             if (MBMessagePermission.contains(
607                     getPermissionChecker(), message, ActionKeys.VIEW)) {
608 
609                 messages.add(message);
610             }
611         }
612 
613         if (messages.size() > 0) {
614             MBMessage message = messages.get(messages.size() - 1);
615 
616             name = message.getSubject();
617             description = message.getSubject();
618         }
619 
620         return exportToRSS(
621             name, description, type, version, displayStyle, feedURL, entryURL,
622             messages, themeDisplay);
623     }
624 
625     public void subscribeMessage(long messageId)
626         throws PortalException, SystemException {
627 
628         MBMessagePermission.check(
629             getPermissionChecker(), messageId, ActionKeys.SUBSCRIBE);
630 
631         mbMessageLocalService.subscribeMessage(getUserId(), messageId);
632     }
633 
634     public void unsubscribeMessage(long messageId)
635         throws PortalException, SystemException {
636 
637         MBMessagePermission.check(
638             getPermissionChecker(), messageId, ActionKeys.SUBSCRIBE);
639 
640         mbMessageLocalService.unsubscribeMessage(getUserId(), messageId);
641     }
642 
643     public MBMessage updateDiscussionMessage(
644             long groupId, String className, long classPK, long messageId,
645             String subject, String body)
646         throws PortalException, SystemException {
647 
648         User user = getUser();
649 
650         MBDiscussionPermission.check(
651             getPermissionChecker(), user.getCompanyId(), groupId, className,
652             classPK, messageId, user.getUserId(), ActionKeys.UPDATE_DISCUSSION);
653 
654         return mbMessageLocalService.updateDiscussionMessage(
655             getUserId(), messageId, subject, body);
656     }
657 
658     public MBMessage updateMessage(
659             long messageId, String subject, String body,
660             List<ObjectValuePair<String, byte[]>> files,
661             List<String> existingFiles, double priority, String[] tagsEntries)
662         throws PortalException, SystemException {
663 
664         MBMessage message = mbMessageLocalService.getMessage(messageId);
665 
666         MBMessagePermission.check(
667             getPermissionChecker(), messageId, ActionKeys.UPDATE);
668 
669         if (!MBCategoryPermission.contains(
670                 getPermissionChecker(), message.getCategoryId(),
671                 ActionKeys.ADD_FILE)) {
672 
673             files.clear();
674         }
675 
676         if (!MBCategoryPermission.contains(
677                 getPermissionChecker(), message.getCategoryId(),
678                 ActionKeys.UPDATE_THREAD_PRIORITY)) {
679 
680             MBThread thread = mbThreadLocalService.getThread(
681                 message.getThreadId());
682 
683             priority = thread.getPriority();
684         }
685 
686         return mbMessageLocalService.updateMessage(
687             getUserId(), messageId, subject, body, files, existingFiles,
688             priority, tagsEntries, null, null);
689     }
690 
691     public MBMessage updateMessage(
692             long messageId, String subject, String body,
693             List<ObjectValuePair<String, byte[]>> files,
694             List<String> existingFiles, double priority, String[] tagsEntries,
695             PortletPreferences prefs, ThemeDisplay themeDisplay)
696         throws PortalException, SystemException {
697 
698         MBMessage message = mbMessageLocalService.getMessage(messageId);
699 
700         MBMessagePermission.check(
701             getPermissionChecker(), messageId, ActionKeys.UPDATE);
702 
703         if (!MBCategoryPermission.contains(
704                 getPermissionChecker(), message.getCategoryId(),
705                 ActionKeys.ADD_FILE)) {
706 
707             files.clear();
708         }
709 
710         if (!MBCategoryPermission.contains(
711                 getPermissionChecker(), message.getCategoryId(),
712                 ActionKeys.UPDATE_THREAD_PRIORITY)) {
713 
714             MBThread thread = mbThreadLocalService.getThread(
715                 message.getThreadId());
716 
717             priority = thread.getPriority();
718         }
719 
720         return mbMessageLocalService.updateMessage(
721             getUserId(), messageId, subject, body, files, existingFiles,
722             priority, tagsEntries, prefs, themeDisplay);
723     }
724 
725     protected void checkReplyToPermission(long categoryId, long parentMessageId)
726         throws PortalException, SystemException {
727 
728         if (parentMessageId > 0) {
729             if (MBCategoryPermission.contains(
730                     getPermissionChecker(), categoryId,
731                     ActionKeys.ADD_MESSAGE)) {
732 
733                 return;
734             }
735 
736             MBMessage parentMessage = mbMessagePersistence.fetchByPrimaryKey(
737                 parentMessageId);
738 
739             if ((parentMessage == null) ||
740                 !MBCategoryPermission.contains(
741                     getPermissionChecker(), categoryId,
742                     ActionKeys.REPLY_TO_MESSAGE)) {
743 
744                 throw new PrincipalException();
745             }
746         }
747         else {
748             MBCategoryPermission.check(
749                 getPermissionChecker(), categoryId, ActionKeys.ADD_MESSAGE);
750         }
751     }
752 
753     protected String exportToRSS(
754             String name, String description, String type, double version,
755             String displayStyle, String feedURL, String entryURL,
756             List<MBMessage> messages, ThemeDisplay themeDisplay)
757         throws SystemException {
758 
759         SyndFeed syndFeed = new SyndFeedImpl();
760 
761         syndFeed.setFeedType(RSSUtil.getFeedType(type, version));
762         syndFeed.setTitle(name);
763         syndFeed.setLink(feedURL);
764         syndFeed.setDescription(description);
765 
766         List<SyndEntry> entries = new ArrayList<SyndEntry>();
767 
768         syndFeed.setEntries(entries);
769 
770         Iterator<MBMessage> itr = messages.iterator();
771 
772         while (itr.hasNext()) {
773             MBMessage message = itr.next();
774 
775             String author = PortalUtil.getUserName(
776                 message.getUserId(), message.getUserName());
777 
778             String value = null;
779 
780             if (displayStyle.equals(RSSUtil.DISPLAY_STYLE_ABSTRACT)) {
781                 value = StringUtil.shorten(
782                     HtmlUtil.extractText(message.getBody()),
783                     _RSS_ABSTRACT_LENGTH, StringPool.BLANK);
784             }
785             else if (displayStyle.equals(RSSUtil.DISPLAY_STYLE_TITLE)) {
786                 value = StringPool.BLANK;
787             }
788             else {
789                 value = BBCodeUtil.getHTML(message);
790 
791                 value = StringUtil.replace(
792                     value,
793                     new String[] {
794                         "@theme_images_path@",
795                         "href=\"/",
796                         "src=\"/"
797                     },
798                     new String[] {
799                         themeDisplay.getURLPortal() +
800                             themeDisplay.getPathThemeImages(),
801                         "href=\"" + themeDisplay.getURLPortal() + "/",
802                         "src=\"" + themeDisplay.getURLPortal() + "/"
803                     });
804             }
805 
806             SyndEntry syndEntry = new SyndEntryImpl();
807 
808             if (!message.isAnonymous()) {
809                 syndEntry.setAuthor(author);
810             }
811 
812             syndEntry.setTitle(message.getSubject());
813             syndEntry.setLink(
814                 entryURL + "&messageId=" + message.getMessageId());
815             syndEntry.setPublishedDate(message.getCreateDate());
816 
817             SyndContent syndContent = new SyndContentImpl();
818 
819             syndContent.setType(RSSUtil.DEFAULT_ENTRY_TYPE);
820             syndContent.setValue(value);
821 
822             syndEntry.setDescription(syndContent);
823 
824             entries.add(syndEntry);
825         }
826 
827         try {
828             return RSSUtil.export(syndFeed);
829         }
830         catch (FeedException fe) {
831             throw new SystemException(fe);
832         }
833     }
834 
835     private static final int _RSS_ABSTRACT_LENGTH = GetterUtil.getInteger(
836         PropsUtil.get(PropsKeys.MESSAGE_BOARDS_RSS_ABSTRACT_LENGTH));
837 
838     private static Log _log = LogFactoryUtil.getLog(MBMessageServiceImpl.class);
839 
840 }