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