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