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